Skip to content

Commit 33dda94

Browse files
authored
chore(deps): align rusqlite 0.40 + git2 0.21 with OpenHuman host (#59)
rusqlite and git2 are native `links = "…"` crates (libsqlite3-sys -> links=sqlite3, libgit2-sys -> links=git2). OpenHuman pins rusqlite =0.40.0 (bundled) and git2 0.21 (vendored-libgit2); the crate pinned rusqlite 0.32 / git2 0.19. Two versions of a links crate in one binary is a hard Cargo error, so the host could not activate its `tinycortex` dependency. Bump both to the host versions and adapt the API deltas: - rusqlite >= 0.33 dropped FromSql for usize: VectorStore::count reads COUNT(*) as i64 and converts via usize::try_from (matches the host's own fix). - git2 0.21: Tag::message() -> Result<Option<&str>>; StringArray::Iter::Item -> Result<Option<&str>>; Buf::as_str() -> Result<&str, Utf8Error>. Adapt the checkpoint tag reader, the two tag-name loops, and patch_text. cargo check --all-targets clean; diff/ledger + checkpoint tests (38) pass.
1 parent d1a8c7b commit 33dda94

3 files changed

Lines changed: 22 additions & 9 deletions

File tree

Cargo.toml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,15 @@ exclude = [
2121
anyhow = "1"
2222
async-trait = "0.1"
2323
chrono = { version = "0.4", features = ["serde"] }
24-
git2 = "0.19"
24+
# Native-linking deps pinned to OpenHuman's versions so the host and the crate
25+
# link ONE bundled SQLite and ONE libgit2 (both are `links = "…"` crates; two
26+
# versions in one binary is a hard Cargo error). Keep in lockstep with the host
27+
# root Cargo.toml when either side bumps.
28+
git2 = { version = "0.21", default-features = false, features = ["vendored-libgit2"] }
2529
parking_lot = "0.12"
2630
rand = "0.8"
2731
regex = "1"
28-
rusqlite = { version = "0.32", features = ["bundled"] }
32+
rusqlite = { version = "0.40", features = ["bundled"] }
2933
serde = { version = "1", features = ["derive"] }
3034
serde_json = "1"
3135
sha2 = "0.10"

src/memory/diff/ledger.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,9 @@ impl Ledger {
366366
};
367367
Ok(Some(checkpoint_from_message(
368368
checkpoint_id,
369-
tag.message().unwrap_or(""),
369+
// git2 0.21: Tag::message() is Result<Option<&str>, _>; a non-UTF8
370+
// or missing message degrades to an empty checkpoint body.
371+
tag.message().ok().flatten().unwrap_or(""),
370372
)))
371373
}
372374

@@ -375,8 +377,9 @@ impl Ledger {
375377
let pattern = format!("{CHECKPOINT_PREFIX}*");
376378
let names = self.repo.tag_names(Some(&pattern))?;
377379
let mut out = Vec::new();
378-
// StringArray::iter() yields Option<&str>; drop non-utf8 names.
379-
for name in names.iter().flatten() {
380+
// git2 0.21: StringArray::iter() yields Result<Option<&str>, _>; keep
381+
// only successfully-decoded utf8 names.
382+
for name in names.iter().filter_map(|r| r.ok().flatten()) {
380383
if let Some(ckpt) = self.get_checkpoint(name)? {
381384
out.push(ckpt);
382385
}
@@ -394,7 +397,8 @@ impl Ledger {
394397
let pattern = format!("{CHECKPOINT_PREFIX}*");
395398
let names = self.repo.tag_names(Some(&pattern))?;
396399
let mut deleted = 0u64;
397-
for name in names.iter().flatten() {
400+
// git2 0.21: StringArray::iter() yields Result<Option<&str>, _>.
401+
for name in names.iter().filter_map(|r| r.ok().flatten()) {
398402
if let Some(ckpt) = self.get_checkpoint(name)? {
399403
if ckpt.created_at_ms < older_than_ms {
400404
self.repo.tag_delete(name)?;
@@ -545,7 +549,8 @@ fn oid_hash(oid: Oid) -> Option<String> {
545549
fn patch_text(diff: &git2::Diff, delta_idx: usize) -> Option<String> {
546550
let mut patch = git2::Patch::from_diff(diff, delta_idx).ok().flatten()?;
547551
let buf = patch.to_buf().ok()?;
548-
let text = buf.as_str()?;
552+
// git2 0.21: Buf::as_str() returns Result<&str, Utf8Error>.
553+
let text = buf.as_str().ok()?;
549554
if text.trim().is_empty() {
550555
None
551556
} else {

src/memory/store/vectors/store.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use std::path::Path;
2323
use std::sync::Arc;
2424

25+
use anyhow::Context;
2526
use parking_lot::Mutex;
2627
use rusqlite::Connection;
2728

@@ -369,15 +370,18 @@ impl VectorStore {
369370
/// Returns the number of entries in a namespace (or all if `None`).
370371
pub fn count(&self, namespace: Option<&str>) -> anyhow::Result<usize> {
371372
let conn = self.conn.lock();
372-
let count: usize = match namespace {
373+
// SQLite COUNT(*) is an i64; rusqlite (>= 0.33) no longer implements
374+
// FromSql for usize, so read as i64 and convert. Overflow is impossible
375+
// in practice but handled rather than silently truncated.
376+
let count: i64 = match namespace {
373377
Some(ns) => conn.query_row(
374378
"SELECT COUNT(*) FROM vectors WHERE namespace = ?1",
375379
rusqlite::params![ns],
376380
|row| row.get(0),
377381
)?,
378382
None => conn.query_row("SELECT COUNT(*) FROM vectors", [], |row| row.get(0))?,
379383
};
380-
Ok(count)
384+
usize::try_from(count).context("vector count did not fit in usize")
381385
}
382386

383387
/// Lists all distinct namespaces.

0 commit comments

Comments
 (0)