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(autoindex): an aborted run never prints the "searchable" success footer (#1183)

xerj-org3171cf921de7
diff --git a/engine/crates/xerj-autoindex/src/xc.rs b/engine/crates/xerj-autoindex/src/xc.rs
index 403bf3adb..9dc8200cd 100644
--- a/engine/crates/xerj-autoindex/src/xc.rs
+++ b/engine/crates/xerj-autoindex/src/xc.rs
@@ -1262,14 +1262,53 @@ fn delete_indices(node: &dyn CorpusNode, names: &[String]) -> usize {
failed
}
-fn report(name: &str, rc: i32, docs: &str) {
+/// The terminal verdict lines, as a pure function so the footer can be
+/// asserted on (the live failures on this path were all about what the LAST
+/// line claims). `rc` is the autoindex exit the flow carried in:
+///
+/// - 0 / 3 are the clean outcomes (3 = some files skipped as junk, normal for
+/// real repos) — the store verified, so "searchable: N records" is earned.
+/// - any other `rc` only reaches here through a #367 salvage: autoindex
+/// aborted in finalisation but the written store passed the verification
+/// search, so it is kept and queryable. It is NOT a clean build. An aborted
+/// run that prints the plain `searchable: N records` success footer is the
+/// last live half of #1183's dishonest-resume item: the 2026-10-08 standing
+/// rebuild ended `xerj-done ok=false exit=1 reason=aborted` and still
+/// printed `corpus 'xerj-search' searchable: 1011181 records`, overstating
+/// the kept set by the 348 docs the re-walk had just dropped. A salvaged
+/// build says so, and never the word "searchable".
+fn report_footer(name: &str, rc: i32, docs: &str) -> Vec<String> {
match rc {
- 0 => println!("indexed cleanly"),
- 3 => println!("indexed (exit 3: some files skipped as junk — normal for real repos)"),
- _ => {}
+ 0 | 3 => {
+ let head = if rc == 0 {
+ "indexed cleanly".to_string()
+ } else {
+ "indexed (exit 3: some files skipped as junk — normal for real repos)".to_string()
+ };
+ vec![
+ head,
+ format!("corpus '{name}' searchable: {docs} records"),
+ format!("next: xerj code {name} \"<what you need>\""),
+ ]
+ }
+ _ => vec![
+ format!(
+ "corpus '{name}' indexed with errors (autoindex exit {rc}): {docs} records \
+ are present and queryable, but coverage is NOT guaranteed — read the error \
+ above before relying on this corpus."
+ ),
+ format!(
+ "next: xerj code {name} \"<what you need>\" (verify coverage first; a clean \
+ rebuild is `xerj corpus index {name} --fresh`)"
+ ),
+ ],
+ }
+}
+
+fn report(name: &str, rc: i32, docs: &str) {
+ for line in report_footer(name, rc, docs) {
+ println!("{line}");
}
- println!("corpus '{name}' searchable: {docs} records");
- println!("next: xerj code {name} \"<what you need>\"");
}
fn run_corpus_index(args: &[String]) -> i32 {
@@ -2746,6 +2785,49 @@ mod tests {
assert!(node.ops.borrow().iter().any(|o| *o == "search:xc-kv-*"));
}
+ /// #1183, the last live half of the dishonest-resume item: a run that
+ /// aborted (autoindex exit ∉ {0,3}) and was only KEPT by the #367 salvage
+ /// must not print the clean `searchable: N records` success footer. The
+ /// 2026-10-08 standing rebuild ended `xerj-done ok=false exit=1
+ /// reason=aborted` and still printed `corpus 'xerj-search' searchable:
+ /// 1011181 records`, overstating the kept set by the 348 docs the re-walk
+ /// had just dropped.
+ #[test]
+ fn the_searchable_footer_is_never_printed_after_an_aborted_run() {
+ // clean exits keep the earned "searchable" footer and the next-hint
+ for rc in [0, 3] {
+ let lines = report_footer("kv", rc, "500");
+ assert!(
+ lines
+ .iter()
+ .any(|l| l == "corpus 'kv' searchable: 500 records"),
+ "rc {rc} is clean and earns the searchable footer: {lines:?}"
+ );
+ assert!(lines.iter().any(|l| l.starts_with("next: xerj code kv")));
+ }
+ // a salvaged/aborted run (any other exit) says so and NEVER prints the
+ // word "searchable" — the whole defect in one assertion
+ for rc in [1, 2, 134] {
+ let lines = report_footer("kv", rc, "500");
+ assert!(
+ lines.iter().all(|l| !l.contains("searchable")),
+ "an aborted run (exit {rc}) must not print the searchable footer: {lines:?}"
+ );
+ // it still tells the operator the kept store exists, names the
+ // exit, and points at the clean rebuild — honest, not silent
+ assert!(
+ lines.iter().any(|l| l.contains("indexed with errors")
+ && l.contains(&format!("autoindex exit {rc}"))
+ && l.contains("coverage is NOT guaranteed")),
+ "the aborted footer must name the fault: {lines:?}"
+ );
+ assert!(
+ lines.iter().any(|l| l.contains("--fresh")),
+ "the aborted footer points at the clean rebuild: {lines:?}"
+ );
+ }
+ }
+
/// #1173: the three honest claims a failed legacy run can make. The one
/// this exists to pin is the middle: a count the node never answered is
/// UNKNOWN, and "wrote no new records" asserted from it is a fabricated