Skip to content

armgit / xerj

Public Imported from GitHub
0

AI search engine and MCP server for bots and agents. One Rust binary indexes code, docs, logs, JSONL/CSV and PDFs for BM25 full-text, vector and hybrid search, code search without grep, agent memory and RAG. Elasticsearch-compatible API; Corpus Hub serves hundreds of reference memory corpora.

fix(sessions): count a symlinked claude-mem store's WAL toward the input cap

Jacob Elbirtce22e1881c6f
diff --git a/engine/crates/xerj-autoindex/src/sessions/claude_mem.rs b/engine/crates/xerj-autoindex/src/sessions/claude_mem.rs
index c57beec73..5d00b0bd5 100644
--- a/engine/crates/xerj-autoindex/src/sessions/claude_mem.rs
+++ b/engine/crates/xerj-autoindex/src/sessions/claude_mem.rs
@@ -306,7 +306,10 @@ pub(super) fn import(input: &Path, output: &Path) -> Result<ImportSummary> {
let meta = fs::metadata(input).context("cannot open claude-mem database")?;
ensure!(meta.is_file(), "claude-mem input must be a regular file");
// Rows not yet checkpointed live in the WAL, so it counts toward the input cap.
- let mut wal = input.as_os_str().to_owned();
+ // SQLite names the WAL after the symlink target, so resolve the input first.
+ let mut wal = fs::canonicalize(input)
+ .context("cannot open claude-mem database")?
+ .into_os_string();
wal.push("-wal");
let wal_len = fs::metadata(&wal).map(|m| m.len()).unwrap_or(0);
ensure!(
@@ -553,7 +556,10 @@ mod tests {
.execute_batch("UPDATE observations SET facts = 'not json'")
.unwrap();
for (input, reason) in [
- (&not_sqlite, "cannot read the input as a SQLite database"),
+ (
+ &not_sqlite,
+ "cannot read the input as a SQLite database; pass ~/.claude-mem/claude-mem.db: file is not a database",
+ ),
(&pre_rename, "predates claude-mem's session ID rename"),
(&other, "no observations table"),
(
@@ -579,6 +585,26 @@ mod tests {
);
}
+ #[cfg(unix)]
+ #[test]
+ fn claude_mem_input_cap_counts_the_wal_even_through_a_symlink() {
+ let dir = tempfile::tempdir().unwrap();
+ let input = store(dir.path());
+ // Sparse, so the test writes no real data.
+ fs::File::create(dir.path().join("claude-mem.db-wal"))
+ .unwrap()
+ .set_len(MAX_INPUT_BYTES)
+ .unwrap();
+ let link = dir.path().join("link.db");
+ std::os::unix::fs::symlink(&input, &link).unwrap();
+ let output = dir.path().join("safe.jsonl");
+ for path in [&input, &link] {
+ let error = format!("{:#}", import_claude_mem(path, &output).unwrap_err());
+ assert!(error.contains("exceeds 512 MiB"), "{error}");
+ assert!(!output.exists());
+ }
+ }
+
#[test]
fn claude_mem_is_a_cli_format() {
let dir = tempfile::tempdir().unwrap();