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): lead the summary with an ok: line that spells out exit 3 (#1843) (#1913)

xerj-orgcf346ba116d8
diff --git a/engine/crates/xerj-autoindex/src/cli.rs b/engine/crates/xerj-autoindex/src/cli.rs
index bf64af1ad..81612cded 100644
--- a/engine/crates/xerj-autoindex/src/cli.rs
+++ b/engine/crates/xerj-autoindex/src/cli.rs
@@ -645,7 +645,10 @@ pub fn help_text_with(feedback: bool) -> String {
\x20\x20\x20\x20AWS_SECRET_ACCESS_KEY, optionally AWS_SESSION_TOKEN. Never from a flag.\n\
\n\
EXIT CODES: 0 complete (also: gate answered with --approve cancel);\n\
- \x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x203 completed-with-junk (junk recorded, never fatal) — this\n\
+ \x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x203 completed-with-junk (junk recorded, never fatal) — SUCCESS:\n\
+ \x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20the index is searchable, and the summary on stdout opens\n\
+ \x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20with a line starting `ok:` that says so (xerj-done carries\n\
+ \x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20ok=true). Treat 0 and 3 alike as a finished run. This\n\
\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20includes a dataset whose mapping the server REFUSED: its\n\
\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20files are recorded as junk with the server's reason, the\n\
\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20xerj-done line carries datasets_refused / files_refused,\n\
diff --git a/engine/crates/xerj-autoindex/src/lib.rs b/engine/crates/xerj-autoindex/src/lib.rs
index cb7c5af27..49141d73f 100644
--- a/engine/crates/xerj-autoindex/src/lib.rs
+++ b/engine/crates/xerj-autoindex/src/lib.rs
@@ -1400,6 +1400,50 @@ fn generated_exit_code(summary: &Value) -> i32 {
}
}
+/// The FIRST line of a finished run's human summary on stdout (#1843).
+///
+/// Exit 3 is success, but an agent that sees a non-zero exit reads failure
+/// unless something it reads first says otherwise. The `xerj-done` line on
+/// stderr already carries `ok=true`, yet it is the LAST line of a long progress
+/// stream and the summary on stdout opened with a timing line that never
+/// mentioned the exit code at all. So every finished run now leads with one
+/// line that starts `ok:` and names the exit code in words; exit 3 also says
+/// what was recorded and where to look, so junk stays visible.
+pub(crate) fn outcome_headline(
+ code: i32,
+ junk_files: u64,
+ junk_records: u64,
+ alias_sweep_failed: bool,
+) -> String {
+ if code != 3 {
+ return format!("ok: indexed and searchable (exit {code}, completed)");
+ }
+ if alias_sweep_failed {
+ return format!(
+ "ok: indexed and searchable — exit 3 ({ALIAS_SWEEP_FAILED_REASON}) is SUCCESS, not \
+ an error: the corpus is indexed and the journal committed; only the catalog's \
+ duplicate-alias cleanup could not run, so rerun the same command once the server \
+ condition clears"
+ );
+ }
+ let mut recorded = Vec::new();
+ if junk_files > 0 {
+ recorded.push(estimate::count_phrase(junk_files, "file", "files"));
+ }
+ if junk_records > 0 {
+ recorded.push(estimate::count_phrase(junk_records, "record", "records"));
+ }
+ let recorded = if recorded.is_empty() {
+ "some input".to_string()
+ } else {
+ recorded.join(" and ")
+ };
+ format!(
+ "ok: indexed and searchable — exit 3 (completed-with-junk) is SUCCESS, not an error: \
+ {recorded} recorded as junk (skipped, never fatal; `xerj autoindex map` lists them)"
+ )
+}
+
/// Terminal progress line for a run that ends on the generated `--no-graph`
/// path.
///
@@ -5051,6 +5095,16 @@ fn finish_generated_run(es: &Es, journal: &mut state::Journal, cfg: &IndexCfg) -
if cfg.json {
println!("{summary}");
} else if !cfg.quiet {
+ let count = |field: &str| summary.get(field).and_then(Value::as_u64).unwrap_or(0);
+ println!(
+ "{}",
+ outcome_headline(
+ generated_exit_code(&summary),
+ count("files_junk"),
+ count("junk_records_total"),
+ false,
+ )
+ );
println!(
"generation {} committed — {}, {} live",
generation,
@@ -9431,11 +9485,36 @@ fn run_index_report_inner(
// ── summary ──────────────────────────────────────────────────────────
let junk_total_records = junk_records.load(Ordering::Relaxed);
+ // Exit 3 means "completed, some input was unusable". Backend rejections
+ // are not consulted and must not be: a rejected item aborts the run with
+ // an error long before this line, so `rejected_records` is provably 0
+ // here. Splitting them out of `junk_total_records` therefore changes no
+ // exit code.
+ //
+ // A failed alias sweep lands here too, and on 3 rather than on a code of
+ // its own: 3 already means "completed, and something about this run is
+ // recorded rather than fatal" (`cli.rs` EXIT CODES), and inventing a fourth
+ // success code would break every caller that already branches on 0/3. The
+ // `reason` is what tells the two apart.
+ let code = if junk_total_records > 0 || junk_file_count > 0 || alias_sweep_error.is_some() {
+ 3
+ } else {
+ 0
+ };
if cfg.json {
println!("{run_doc}");
} else if !cfg.quiet {
println!(
- "\n{}",
+ "{}",
+ outcome_headline(
+ code,
+ junk_file_count as u64,
+ junk_total_records,
+ alias_sweep_error.is_some(),
+ )
+ );
+ println!(
+ "{}",
estimate::done_summary_line(
wall,
plan.datasets.len() as u64,
@@ -9528,22 +9607,6 @@ fn run_index_report_inner(
println!("{}", mixed_corpus_hint(&fams));
}
}
- // Exit 3 means "completed, some input was unusable". Backend rejections
- // are not consulted and must not be: a rejected item aborts the run with
- // an error long before this line, so `rejected_records` is provably 0
- // here. Splitting them out of `junk_total_records` therefore changes no
- // exit code.
- //
- // A failed alias sweep lands here too, and on 3 rather than on a code of
- // its own: 3 already means "completed, and something about this run is
- // recorded rather than fatal" (`cli.rs` EXIT CODES), and inventing a fourth
- // success code would break every caller that already branches on 0/3. The
- // `reason` is what tells the two apart.
- let code = if junk_total_records > 0 || junk_file_count > 0 || alias_sweep_error.is_some() {
- 3
- } else {
- 0
- };
// Terminal line, in every progress mode but `none` (which `--quiet`
// selects, and which prints nothing by definition). Exit 3 means
// "completed, some files were unparseable" — success — and an agent reading
@@ -11484,6 +11547,35 @@ mod generation_contract_identity_tests {
);
}
+ /// #1843: exit 3 read as failure because nothing an agent reads FIRST
+ /// said otherwise. Every finished run's stdout summary now opens with an
+ /// `ok:` line that names the exit code in words, and an exit-3 line says
+ /// what was recorded instead of hiding it.
+ #[test]
+ fn a_finished_run_leads_with_an_ok_line_that_spells_out_exit_3() {
+ let clean = outcome_headline(0, 0, 0, false);
+ assert!(clean.starts_with("ok: indexed and searchable"), "{clean}");
+ assert!(clean.contains("exit 0"), "{clean}");
+
+ let junk = outcome_headline(3, 1, 0, false);
+ assert!(junk.starts_with("ok: indexed and searchable"), "{junk}");
+ assert!(
+ junk.contains("exit 3 (completed-with-junk) is SUCCESS, not an error"),
+ "{junk}"
+ );
+ assert!(junk.contains("1 file recorded as junk"), "{junk}");
+ assert!(junk.contains("xerj autoindex"), "{junk}");
+ assert!(!junk.contains('\n'), "one line: {junk}");
+
+ let both = outcome_headline(3, 2, 5, false);
+ assert!(both.contains("2 files and 5 records"), "{both}");
+
+ let sweep = outcome_headline(3, 4, 0, true);
+ assert!(sweep.starts_with("ok: indexed and searchable"), "{sweep}");
+ assert!(sweep.contains(ALIAS_SWEEP_FAILED_REASON), "{sweep}");
+ assert!(sweep.contains("rerun the same command"), "{sweep}");
+ }
+
/// Resume of an already-indexed tokio tree printed
/// `submitted 0 source records from 0 files` beside 11246 live documents
/// and `(66096.3 docs/sec)`. The live count is the catalog; the rate is