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.

Verify missing datasets without rejecting intentional exclusions

xerj-orgb97039ac16b9
diff --cc CHANGELOG.md
index 8bd7b125f,88dd16ef1..07d25019f
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@@ -21,15 -21,12 +21,23 @@@ and this project adheres to [Semantic V
### Fixed
+- GitHub field-report submission uses the supported explicit-repository
+ `gh repo fork --clone=false` invocation and adds the fork remote itself
+ (#2596). The rollback test now verifies that the report was committed
+ before a failed push, rather than passing after an earlier fork failure.
+- Local admin-key discovery reports the source of the selected key and warns
+ when its directory is outside the working tree (#2578). Packaged installs
+ have their own provenance, and MCP guidance names `XERJ_AUTH`. Discovery
+ priority and explicit credential overrides are unchanged.
+
+ - `xerj autoindex` fails a run when one dataset index holds no documents
+ although the journal says records were written to it, even when the other
+ datasets are live (#2407, defect 2). The check summed live documents over
+ every dataset, so a populated `-json` index let a re-run print `ok: indexed
+ and searchable` over an empty `-docs` index. The error names each empty
- index and the records and files the journal sent it.
++ index and its contributing files; record totals are reported only when
++ those files target that dataset alone. Unknown sibling counts do not hide
++ independently confirmed missing data.
- SQL source extraction no longer slices statement heads inside a UTF-8
character, so unrecognized CJK statement/comment heads do not panic (#2547).
- Short Markdown files with YAML frontmatter retain their prose body even
diff --cc content/answers/autoindex-exit-codes.md
index fd63f9f54,b635a7053..02893cd3e
--- a/content/answers/autoindex-exit-codes.md
+++ b/content/answers/autoindex-exit-codes.md
@@@ -1,7 -1,7 +1,7 @@@
---
title: "What do the xerj autoindex exit codes mean?"
h1: "The indexer exited 3 (or 4). Did it fail?"
--description: "xerj autoindex exits 0 complete, 3 completed-with-junk, 4 needs-a-decision, 2 usage and 1 on an endpoint or journal failure. Only 4 is asking you a question."
++description: "xerj autoindex exits 0 complete, 3 completed-with-junk, 4 needs-a-decision, 2 usage and 1 on a runtime failure. Only 4 is asking you a question."
slug: "autoindex-exit-codes"
cluster: "Operations: exit codes"
question: "What does indexer exit code 3 mean?"
@@@ -60,18 -60,18 +60,18 @@@ faq
- q: "Why did folder indexing stop and ask me to approve?"
a: "The measured phase-A estimate for the indexing phase was longer than `--max-minutes` (default 10). With no `--approve` or `--yes`, nothing is indexed, a JSON decision request goes to stdout and the process exits 4."
- q: "How do I tell a failed index from a completed one with junk files?"
- a: "Read the exit code and terminal reason. A stale-resume-plan outcome is incomplete and needs --fresh; otherwise 0 and 3 are finished runs; 3 additionally refused at least one file, or a whole dataset whose mapping the server answered HTTP 400 to, in which case the `xerj-done` line carries `datasets_refused` and `files_refused`. 1 is an endpoint or journal failure and nothing about it is a junk report."
- a: "Read the exit code, not the log volume. 0 and 3 are both finished runs; 3 additionally refused at least one file, or a whole dataset whose mapping the server answered HTTP 400 to, in which case the `xerj-done` line carries `datasets_refused` and `files_refused`. 1 is an endpoint or journal failure and nothing about it is a junk report."
++ a: "Read the exit code and terminal reason. A stale-resume-plan outcome is incomplete and needs --fresh; otherwise 0 and 3 are finished runs; 3 additionally refused at least one file, or a whole dataset whose mapping the server answered HTTP 400 to, in which case the `xerj-done` line carries `datasets_refused` and `files_refused`. 1 is a runtime failure and nothing about it is a junk report."
- q: "Is exit 1 the code for any error?"
-- a: "No, and that shorthand is wrong. `--help` scopes 1 to an endpoint or journal failure, a refused corpus removal, or a refused unsafe state transition. A bad command line is 2. On the `--no-graph` path, an exit 1 whose terminal line reads `reason=server-backpressure` means the node rejected every write for the whole 600 s a bulk waits; the line carries `ops_applied` and `ops_remaining`."
++ a: "Exit 1 covers runtime errors, including verification failures, node or journal problems, and refused unsafe operations. A bad command line is 2. On the `--no-graph` path, an exit 1 whose terminal line reads `reason=server-backpressure` means the node rejected every write for the whole 600 s a bulk waits; the line carries `ops_applied` and `ops_remaining`."
- q: "Does exit 0 always mean the folder was indexed?"
a: "No. Answering the decision gate with `--approve cancel` also exits 0, and that run indexes nothing on purpose. Read the terminal line or the journal before you report a corpus as searchable."
- q: "Why did my run print no terminal line at all?"
a: "Either `--quiet` or `--progress none` was in force, which prints no terminal line, or the process was killed by a signal. A missing terminal line after the process is gone means it died, not that it finished."
- q: "Which codes should an agent retry?"
- a: "Retry nothing on 0 or 3. Re-run with `--approve` on 4. Fix the command line on 2. Investigate the endpoint and the journal on 1, because a blind retry repeats the same refusal. The one exit 1 to rerun unchanged is `reason=server-backpressure`, once the node accepts writes again: it resumes with the operations that remain."
+ a: "Do not blindly retry 0 or 3. Exit 3 with stale-resume-plan requires a --fresh rebuild to include the new files. Re-run with `--approve` on 4. Fix the command line on 2. Investigate the endpoint and the journal on 1, because a blind retry repeats the same refusal. The one exit 1 to rerun unchanged is `reason=server-backpressure`, once the node accepts writes again: it resumes with the operations that remain."
---
- **TL;DR** — Read the terminal reason as well as the exit code. Exit 3 with `completed-with-junk` is success; `stale-resume-plan` has `ok=false` because new files were not indexed and needs a `--fresh` rebuild. `xerj autoindex` exits 0 when the run completed, and 3 when it completed and recorded junk. Exit 4 means the estimate exceeded `--max-minutes` and nothing was indexed. Exit 2 is a usage error, and exit 1 is an endpoint or journal failure. Only 4 is a question.
-**TL;DR** — Exit 3 is a success. `xerj autoindex` exits 0 when the run completed, and 3 when it completed and recorded junk. Exit 4 means the estimate exceeded `--max-minutes` and nothing was indexed. Exit 2 is a usage error, and exit 1 is an endpoint or journal failure. Only 4 is a question.
++**TL;DR** — Read the terminal reason as well as the exit code. Exit 3 with `completed-with-junk` is success; `stale-resume-plan` has `ok=false` because new files were not indexed and needs a `--fresh` rebuild. `xerj autoindex` exits 0 when the run completed, and 3 when it completed and recorded junk. Exit 4 means the estimate exceeded `--max-minutes` and nothing was indexed. Exit 2 is a usage error, and exit 1 is a runtime failure. Only 4 is a question.
## The codes, as the binary states them
@@@ -136,13 -127,13 +136,13 @@@ A person at a terminal is prompted inst
`xerj autoindex` never waits on stdin for a question it did not print.
--## Exit 1 and exit 2 are narrower than "any error"
++## Read the error before retrying exit 1 or 2
--The common shorthand is that 1 means any error. The binary is more specific, and the difference matters to a retry policy.
++Exit 1 covers runtime failures. Exit 2 identifies a usage error. The diagnostic tells you what needs to change.
`2 usage` is a bad command line. Nothing ran, and a retry of the same command will fail the same way.
--`1` is an endpoint or journal failure, a refused corpus removal, or a refused unsafe state transition. The last two are refusals by design, not crashes: removing an indexed file is refused before any remote mutation, because its documents are already live and nothing on that path deletes them.
++`1` covers runtime failures, including node or journal errors, refused unsafe operations, unavailable parser workers, and missing-data verification failures. A refusal need not mean a crash. Follow its recovery message; an unchanged retry does not correct missing or incompatible state.
So a 1 is not always something to retry. Read the error line first.
@@@ -155,7 -146,7 +155,7 @@@ autoindex: stopped by server back-press
xerj-done ok=false exit=1 reason=server-backpressure wall=… ops_applied=N ops_remaining=M
```
--Forced on a real node with a 64 MiB memory cap, that line read `xerj-done ok=false exit=1 reason=server-backpressure wall=609.1s ops_applied=0 ops_remaining=231`. The applied operations are journaled, so the same command resumes with the `M` that remain once the node accepts writes again. On that node, restarted on its default cap, it did. It is exit 1 and not 3 on purpose: 3 means a finished run with nothing to retry, and this generation is not finished. The [back-pressure page](/answers/autoindex-server-back-pressure-429) covers the node side.
++Forced on a real node with a 64 MiB memory cap, that line read `xerj-done ok=false exit=1 reason=server-backpressure wall=609.1s ops_applied=0 ops_remaining=231`. The applied operations are journaled, so the same command resumes with the `M` that remain once the node accepts writes again. On that node, restarted on its default cap, it did. It is exit 1 and not 3 on purpose: the completed-with-junk outcome is finished, while this generation is not finished. The [back-pressure page](/answers/autoindex-server-back-pressure-429) covers the node side.
A request the node calls too large is no longer an exit 1 at all. Until issue #955, both indexing paths sent the catalog as one `_bulk` request, one document per file, per dataset and per run. A corpus whose catalog held more than the engine's `limits.max_actions_per_bulk` (50,000 by default) applied every operation and then failed at the very end. On a 48,533-file corpus the `--no-graph` run ended 10,336 seconds in:
diff --cc engine/crates/xerj-autoindex/src/cli.rs
index f224b37e5,d3eee3e87..a139cda4c
--- a/engine/crates/xerj-autoindex/src/cli.rs
+++ b/engine/crates/xerj-autoindex/src/cli.rs
@@@ -814,9 -810,9 +814,9 @@@ pub fn help_text_with(feedback: bool) -
\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20that does not fit is not started, including with --yes.\n\
\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20Already-indexed files are not deleted unless --drop-indexed\n\
\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20is also set;\n\
-- \x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x202 usage; 1 endpoint/journal failure, a refused corpus removal, a\n\
-- \x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20refused unsafe state transition, or pdf-worker-unavailable — every PDF\n\
-- \x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20failed because the isolated parser could not start. Other files may\n\
++ \x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x202 usage; 1 runtime failure, including endpoint/journal failure,\n\
++ \x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20a refused removal or unsafe state transition, verification failure,\n\
++ \x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20or pdf-worker-unavailable (the isolated PDF parser could not start). Files may\n\
\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20already be indexed. Read `reason` on the xerj-done line; the summary\n\
\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20on stdout opens with `not ok:`\n",
feedback_block = xerj_common::feedback::block(feedback),
diff --cc engine/crates/xerj-autoindex/src/failure_resume_http_tests.rs
index 80f205221,627378b47..b1fdb6d86
--- a/engine/crates/xerj-autoindex/src/failure_resume_http_tests.rs
+++ b/engine/crates/xerj-autoindex/src/failure_resume_http_tests.rs
@@@ -137,6 -137,10 +137,12 @@@ struct MockState
/// `timed_out`. Models a node that accepted the writes and then could
/// not finish a count (merge, deadline). Must not look like zero docs.
fail_counts: bool,
+ /// Opt-in (#2407): `_count` on these indices answers 0. The fixture keeps
+ /// one document map for every index, so this is how a test models one
+ /// dataset index holding nothing while its siblings are live.
+ empty_count_indices: Vec<String>,
++ /// Independent failed counts, including their size:0 search fallback.
++ unknown_count_indices: Vec<String>,
/// Answer the catalog's duplicate-alias sweep — and ONLY that request —
/// with a 500 whose body names the condition. Scoped to the one call so
/// the fixture proves the sweep is what wedged the run (#345), not that a
@@@ -466,17 -470,24 +472,36 @@@ fn handle(mut stream: TcpStream, state
}
(200, json!({"deleted": removed, "failures": []}))
} else if method == "GET" && path.ends_with("/_count") {
- if state.lock().unwrap().fail_counts {
+ let locked = state.lock().unwrap();
- if locked.fail_counts {
++ if locked.fail_counts
++ || locked
++ .unknown_count_indices
++ .iter()
++ .any(|index| path == format!("/{index}/_count"))
++ {
(200, json!({"error": "count unavailable"}))
+ } else if locked
+ .empty_count_indices
+ .iter()
+ .any(|index| path == format!("/{index}/_count"))
+ {
+ (200, json!({"count": 0}))
} else {
- (200, json!({"count": state.lock().unwrap().docs.len()}))
+ (200, json!({"count": locked.docs.len()}))
}
} else if method == "POST"
&& path.ends_with("/_search")
&& serde_json::from_slice::<Value>(&body)
.ok()
.is_some_and(|query| query.get("size").and_then(Value::as_u64) == Some(0))
-- && state.lock().unwrap().fail_counts
++ && {
++ let locked = state.lock().unwrap();
++ locked.fail_counts
++ || locked
++ .unknown_count_indices
++ .iter()
++ .any(|index| path == format!("/{index}/_search"))
++ }
{
(
200,
@@@ -3998,6 -4006,65 +4023,119 @@@ fn zero_live_documents_after_journaled_
);
}
+ /// #2407: the zero-live gate summed live documents over every dataset, so a
+ /// populated sibling hid an index that held nothing. The reporter's re-run
+ /// printed `ok: indexed and searchable` over a 0-document `-docs` index
+ /// beside a live `-json` one. The empty dataset must fail the run by name,
+ /// and it must not be the all-empty error `xerj brain` reads as a wiped
+ /// destination.
+ #[test]
+ fn an_empty_dataset_beside_a_live_one_fails_the_run() {
+ let _guard = FAILPOINT_TEST_LOCK
+ .lock()
+ .unwrap_or_else(|p| p.into_inner());
+ let _io_guard = state::FILE_DONE_IO_FAILPOINT_TEST_LOCK
+ .lock()
+ .unwrap_or_else(|p| p.into_inner());
+ let write_corpus = |root: &Path| {
+ fs::write(root.join("rows.csv"), "id,value\n1,first\n2,second\n").unwrap();
+ fs::write(
+ root.join("notes.md"),
+ "# Notes\n\nTiered merge policy picks segments of similar size.\n",
+ )
+ .unwrap();
+ };
+ let corpus = tempfile::tempdir().unwrap();
+ let state_dir = tempfile::tempdir().unwrap();
+ write_corpus(corpus.path());
+ let endpoint = MockEndpoint::start(usize::MAX);
+ let config = cfg(corpus.path(), state_dir.path(), &endpoint.url);
+ let prefix = config.prefix.clone();
+ assert_eq!(run_index(config.clone()).unwrap(), 0);
+ // Learn the prose dataset's index rather than hard-coding the slug scheme.
+ let prose = {
+ let locked = endpoint.state.lock().unwrap();
+ let slug = data_rows(&locked)
+ .into_iter()
+ .find(|doc| doc["ax_path"] == "notes.md")
+ .and_then(|doc| doc["ax_dataset"].as_str())
+ .expect("notes.md is indexed")
+ .to_owned();
+ format!("{prefix}-{slug}")
+ };
+
- // The re-run resumes over the completed journal while the prose index
- // answers 0, the shape of writes the server refused.
++ let completed = || -> Vec<Value> {
++ fs::read_to_string(state_dir.path().join("journal.ndjson"))
++ .unwrap()
++ .lines()
++ .map(|line| serde_json::from_str::<Value>(line).unwrap())
++ .filter(|row| row["kind"] == "file_done")
++ .collect()
++ };
++ let before_journal = completed();
++ let before_docs = endpoint.state.lock().unwrap().docs.clone();
++ let sibling = {
++ let locked = endpoint.state.lock().unwrap();
++ let slug = data_rows(&locked)
++ .into_iter()
++ .find(|doc| doc["ax_path"] == "rows.csv")
++ .and_then(|doc| doc["ax_dataset"].as_str())
++ .unwrap()
++ .to_owned();
++ format!("{prefix}-{slug}")
++ };
+ endpoint.state.lock().unwrap().empty_count_indices = vec![prose.clone()];
- let error = run_index(config).unwrap_err();
- assert!(
- !error.is::<crate::ZeroLiveVerificationError>(),
- "a live sibling means the destination was not wiped: {error:#}"
- );
- let error = format!("{error:#}");
- assert!(error.contains("verification failed"), "{error}");
- assert!(
- error.contains(&format!("{prose} (")) && error.contains("record(s) from 1 file(s))"),
- "the empty index is named with what the journal sent it: {error}"
- );
- assert!(error.contains("1 of the 2 dataset index(es)"), "{error}");
- assert!(error.contains("--fresh"), "{error}");
++ // A known live sibling and an unknown sibling must both leave the
++ // independently confirmed missing dataset visible as a verification error.
++ for unknown in [false, true] {
++ endpoint.state.lock().unwrap().unknown_count_indices = if unknown {
++ vec![sibling.clone()]
++ } else {
++ vec![]
++ };
++ let error = run_index(config.clone()).unwrap_err();
++ assert!(
++ !error.is::<crate::ZeroLiveVerificationError>(),
++ "partial evidence must not claim a wiped destination: {error:#}"
++ );
++ let error = format!("{error:#}");
++ assert!(error.contains("verification failed"), "{error}");
++ assert!(
++ error.contains(&format!("{prose} (")) && error.contains("record(s) from 1 file(s))"),
++ "the empty index is named with attributable journal counts: {error}"
++ );
++ assert!(error.contains("1 of the 2 dataset index(es)"), "{error}");
++ assert!(error.contains("--fresh"), "{error}");
++ assert_eq!(
++ completed(),
++ before_journal,
++ "completed file authority survives verification failure"
++ );
++ assert_eq!(
++ endpoint.state.lock().unwrap().docs,
++ before_docs,
++ "verification failure must retain existing records"
++ );
++ }
++ // Exercise the recovery the diagnostic recommends, then an ordinary resume.
++ {
++ let mut locked = endpoint.state.lock().unwrap();
++ locked.empty_count_indices.clear();
++ locked.unknown_count_indices.clear();
++ }
++ let mut rebuild = config.clone();
++ rebuild.fresh = true;
++ assert_eq!(run_index(rebuild).unwrap(), 0);
++ assert_eq!(run_index(config).unwrap(), 0);
++ let locked = endpoint.state.lock().unwrap();
++ assert!(data_rows(&locked)
++ .iter()
++ .any(|doc| doc["ax_path"] == "notes.md"));
++ assert!(data_rows(&locked)
++ .iter()
++ .any(|doc| doc["ax_path"] == "rows.csv"));
+ }
+
/// A node that accepted the bulks and then could not count (the size:0
/// fallback comes back `timed_out` with total 0) must not abort finalize.
/// Treating that 0 as "nothing is live" is the count-mismatch abort: the
diff --cc engine/crates/xerj-autoindex/src/incremental_reconcile_http_tests.rs
index 49f8adabc,49f8adabc..c7ab4cc46
--- a/engine/crates/xerj-autoindex/src/incremental_reconcile_http_tests.rs
+++ b/engine/crates/xerj-autoindex/src/incremental_reconcile_http_tests.rs
@@@ -7238,6 -7238,6 +7238,22 @@@ mod delete_gate
after.iter().all(|path| !path.ends_with("rows.csv")),
"the confirmed plan removes the csv: {after:?}"
);
++
++ // A repeated confirmed exclusion, then excluding everything, must not
++ // be mistaken for a lost destination merely because the journal keeps
++ // the old per-file completion records.
++ let mut repeat = graph_cfg();
++ repeat.budget_plan = Some("code-and-docs".into());
++ repeat.drop_indexed = true;
++ assert_eq!(run_index(repeat).unwrap(), 0);
++ assert_eq!(paths(&endpoint.data_docs()), after);
++ fs::write(corpus.path().join(".xerjignore"), "*\n").unwrap();
++ assert_eq!(run_index(graph_cfg()).unwrap(), 0);
++ assert!(
++ paths(&endpoint.data_docs()).is_empty(),
++ "all source-file records were deliberately excluded: {:?}",
++ paths(&endpoint.data_docs())
++ );
}
fn base() -> CommittedManifest {
diff --cc engine/crates/xerj-autoindex/src/lib.rs
index 3ef02c024,008c2b5a8..1d4fa0128
--- a/engine/crates/xerj-autoindex/src/lib.rs
+++ b/engine/crates/xerj-autoindex/src/lib.rs
@@@ -6524,6 -6516,66 +6524,72 @@@ impl std::fmt::Display for ZeroLiveVeri
impl std::error::Error for ZeroLiveVerificationError {}
+ /// A dataset index the resume journal says received records, and that answers
+ /// with zero live documents.
+ #[derive(Debug, Clone, PartialEq, Eq)]
+ struct EmptyDataset {
+ index: String,
- /// Records journaled by completed files that write only to empty datasets.
- records: u64,
++ /// Exact only when every contributing file targets this dataset alone.
++ /// A file-wide journal count cannot be copied into several dataset totals.
++ records: Option<u64>,
+ files: usize,
+ }
+
+ /// The per-dataset half of the #195 gate (#2407). Summing live documents over
+ /// every dataset let a populated sibling hide an index that held nothing, so a
+ /// re-run reported `ok: indexed and searchable` over an empty `-docs` index.
+ ///
+ /// The journal keeps one record count per file, and a file's groups can feed
+ /// several datasets, so records are attributed to a file's datasets only as a
+ /// set: a completed file with records is missing when EVERY dataset it feeds
+ /// answers zero. A dataset with no count (refused, or the count did not
+ /// answer) is unknown, not empty, and never makes a file missing.
+ fn datasets_left_empty(
+ plan: &Plan,
+ done: &HashMap<String, FileDone>,
+ ds_counts: &HashMap<String, u64>,
++ excluded_file_keys: &HashSet<String>,
+ ) -> Vec<EmptyDataset> {
- let mut empty: BTreeMap<String, (u64, usize)> = BTreeMap::new();
++ let mut empty: BTreeMap<String, (Option<u64>, usize)> = BTreeMap::new();
+ for (key, file) in done {
- if file.records == 0 {
++ if file.records == 0 || excluded_file_keys.contains(key) {
+ continue;
+ }
+ let Some(assignment) = plan.files.get(key) else {
+ continue;
+ };
+ let slugs: BTreeSet<&str> = assignment
+ .assignments
+ .iter()
+ .map(|(_, slug)| slug.as_str())
+ .collect();
+ if slugs.is_empty() || !slugs.iter().all(|slug| ds_counts.get(*slug) == Some(&0)) {
+ continue;
+ }
++ let records = (slugs.len() == 1).then_some(file.records);
+ for slug in slugs {
- let entry = empty.entry(slug.to_string()).or_default();
- entry.0 += file.records;
++ let entry = empty.entry(slug.to_string()).or_insert((Some(0), 0));
++ entry.0 = entry
++ .0
++ .zip(records)
++ .and_then(|(total, n)| total.checked_add(n));
+ entry.1 += 1;
+ }
+ }
+ plan.datasets
+ .iter()
+ .filter_map(|dataset| {
+ empty
+ .get(&dataset.slug)
+ .map(|(records, files)| EmptyDataset {
+ index: dataset.index.clone(),
+ records: *records,
+ files: *files,
+ })
+ })
+ .collect()
+ }
+
#[derive(Debug)]
struct UnsupportedInventoryDeltaError {
delta: UnsupportedInventoryDelta,
@@@ -9405,6 -9457,6 +9471,9 @@@ fn run_index_report_inner
// dropped from the resumed plan so the second gate does not see them.
let mut swept_membership = false;
let mut deleted_file_keys: HashSet<String> = HashSet::new();
++ // Excluded files intentionally lose their live documents but retain plan
++ // identity for future inclusion. They are not missing-write evidence.
++ let mut excluded_file_keys: HashSet<String> = HashSet::new();
if let Some(prior_plan) = preflight.plan.as_ref() {
let comparison_keys = if cfg.fresh {
inventory.keys.clone()
@@@ -9482,6 -9534,6 +9551,12 @@@
chrono::Utc::now().timestamp_millis(),
)
.context("sweep newly-excluded content groups")?;
++ excluded_file_keys.extend(
++ delta
++ .excluded_content_groups
++ .iter()
++ .map(|entry| entry.file_key.clone()),
++ );
}
}
// #736: snapshot the PRIOR plan's anchor nodes HERE, before the journal is
@@@ -9877,6 -9929,6 +9952,12 @@@
chrono::Utc::now().timestamp_millis(),
)
.context("sweep newly-excluded content groups")?;
++ excluded_file_keys.extend(
++ delta
++ .excluded_content_groups
++ .iter()
++ .map(|entry| entry.file_key.clone()),
++ );
}
}
@@@ -11805,8 -11857,9 +11886,9 @@@
// "the corpus has no match" from "nothing was ever written". This is
// the last-resort catch for any rejection path the per-bulk
// classification does not recognise.
- let (files_done_journaled, journal_records) = {
+ let (files_done_journaled, journal_records, left_empty) = {
let journal = journal_mx.lock().unwrap();
- let left_empty = datasets_left_empty(&plan, &journal.done, &ds_counts);
++ let left_empty = datasets_left_empty(&plan, &journal.done, &ds_counts, &excluded_file_keys);
// #2314: a file swept because it left the folder is still in
// `journal.done` until the next plan write forgets to republish it.
// Those records are supposed to be gone. Counting them made a folder
@@@ -11814,7 -11867,7 +11896,7 @@@
let mut files_done_journaled = 0usize;
let mut journal_records = 0u64;
for (key, done) in &journal.done {
-- if plan.files.contains_key(key) {
++ if plan.files.contains_key(key) && !excluded_file_keys.contains(key) {
files_done_journaled += 1;
journal_records += done.records;
}
@@@ -11825,7 -11878,7 +11907,8 @@@
if !count_unknown.is_empty() {
pr.warn(&format!(
"finalize-count: {} dataset index(es) did not answer a count, so the \
-- zero-live check was not applied. The journal records {journal_records} \
++ all-indices zero-live check was not applied. Independently confirmed \
++ empty datasets are still checked. The journal records {journal_records} \
record(s). {}",
count_unknown.len(),
count_unknown.join(" | ")
@@@ -11847,7 -11900,32 +11930,37 @@@
state_dir: state_dir.display().to_string(),
}
.into());
- } else if !left_empty.is_empty() {
- // #2407: other datasets are live, so this is not the wiped
- // destination `ZeroLiveVerificationError` stands for, and `xerj
- // brain` must not read it as one.
+ }
++ if !left_empty.is_empty() {
++ // A confirmed empty target still matters when another count is unknown.
++ // This is not evidence that the entire destination was wiped.
+ let named: Vec<String> = left_empty
+ .iter()
- .map(|d| {
- format!(
++ .map(|d| match d.records {
++ Some(records) => format!(
+ "{} ({} record(s) from {} file(s))",
- d.index, d.records, d.files
- )
++ d.index, records, d.files
++ ),
++ None => format!(
++ "{} ({} contributing file(s); record count not attributable per dataset)",
++ d.index, d.files
++ ),
+ })
+ .collect();
+ anyhow::bail!(
+ "autoindex verification failed: {} of the {} dataset index(es) hold 0 live \
- documents although the resume journal records records written to them: {}. \
- The other datasets are live, so the run is not reported as indexed. A \
- server-side rejection of that dataset's writes (for example an embedding \
- width its mapping does not fit) or a deleted index leaves this. Journal \
++ documents although completed files have journaled records and every target \
++ of those files returned zero: {}. Counts from files shared by several \
++ datasets cannot be assigned to a particular target. Other datasets may be \
++ live or unverified; the run is not reported as indexed. Check server-side \
++ write refusals and whether the target indices were deleted. Journal \
+ state dir: {}. Fix the cause, then rerun with --fresh to re-index from scratch",
+ left_empty.len(),
+ plan.datasets.len(),
+ named.join(", "),
+ state_dir.display()
+ );
+ }
// correlations
let mut key_corrs: Vec<correlate::KeyCorr> = Vec::new();
@@@ -14628,6 -14702,99 +14741,110 @@@ mod map_metadata_tests
}
}
+ fn dataset(slug: &str) -> PlanDataset {
+ PlanDataset {
+ slug: slug.into(),
+ index: format!("ax-{slug}"),
+ family: "text".into(),
+ group: None,
+ specs: vec![],
+ time_field: None,
+ semantic_field: None,
+ text_analyzer: None,
+ scope: None,
+ sampled_records: 1,
+ file_count: 1,
+ }
+ }
+
+ fn done(key: &str, records: u64) -> (String, FileDone) {
+ (
+ key.into(),
+ FileDone {
+ file_key: key.into(),
+ path: format!("{key}.dat"),
+ records,
+ junk: 0,
+ bytes: 1,
+ dropped_by_dataset: HashMap::new(),
+ generation: None,
+ },
+ )
+ }
+
+ /// #2407: a live sibling must not hide a dataset that holds nothing. The
+ /// prose file wrote only to `docs`, which answers 0 while `json` is live.
+ /// A file that also feeds a live dataset cannot be shown missing (the
+ /// journal has one count per file), and a dataset with no count is
+ /// unknown, not empty.
+ #[test]
+ fn a_dataset_left_empty_beside_a_live_sibling_is_named() {
+ let plan = Plan {
+ datasets: vec![dataset("docs"), dataset("json"), dataset("mixed")],
+ files: HashMap::from([
+ ("prose-1".into(), assignment(&["docs"])),
+ ("prose-2".into(), assignment(&["docs"])),
+ ("rows".into(), assignment(&["json"])),
+ ("both".into(), assignment(&["mixed", "json"])),
+ ("unknown".into(), assignment(&["refused"])),
+ ]),
+ ..Plan::default()
+ };
+ let journal = HashMap::from([
+ done("prose-1", 3),
+ done("prose-2", 2),
+ done("rows", 120),
+ done("both", 4),
+ done("unknown", 9),
+ // Swept from the folder: in the journal, not in the plan (#2314).
+ done("gone", 7),
+ ]);
+ let counts = HashMap::from([
+ ("docs".to_string(), 0),
+ ("json".to_string(), 120),
+ ("mixed".to_string(), 0),
+ ]);
+ assert_eq!(
- datasets_left_empty(&plan, &journal, &counts),
++ datasets_left_empty(&plan, &journal, &counts, &HashSet::new()),
+ [EmptyDataset {
+ index: "ax-docs".into(),
- records: 5,
++ records: Some(5),
+ files: 2,
+ }]
+ );
+
++ let deliberately_excluded = HashSet::from(["prose-1".into(), "prose-2".into()]);
++ assert!(
++ datasets_left_empty(&plan, &journal, &counts, &deliberately_excluded).is_empty(),
++ "intentional exclusion sweeps are not missing writes"
++ );
++
+ // Every dataset live: nothing to name.
+ let live = HashMap::from([
+ ("docs".to_string(), 5),
+ ("json".to_string(), 120),
+ ("mixed".to_string(), 0),
+ ]);
- assert!(datasets_left_empty(&plan, &journal, &live).is_empty());
++ assert!(datasets_left_empty(&plan, &journal, &live, &HashSet::new()).is_empty());
+
+ // A file whose every dataset is empty names each of them.
+ let both_empty = HashMap::from([
+ ("docs".to_string(), 5),
+ ("json".to_string(), 0),
+ ("mixed".to_string(), 0),
+ ]);
- let named: Vec<String> = datasets_left_empty(&plan, &journal, &both_empty)
++ let ambiguous = datasets_left_empty(&plan, &journal, &both_empty, &HashSet::new());
++ assert!(
++ ambiguous.iter().all(|dataset| dataset.records.is_none()),
++ "one file's shared count must not be duplicated into each dataset: {ambiguous:?}"
++ );
++ let named: Vec<String> = datasets_left_empty(&plan, &journal, &both_empty, &HashSet::new())
+ .into_iter()
+ .map(|d| d.index)
+ .collect();
+ assert_eq!(named, ["ax-json", "ax-mixed"]);
+ }
+
#[test]
fn unchanged_resume_keeps_durable_assignment_aware_dataset_bytes() {
let _guard = state::FILE_DONE_IO_FAILPOINT_TEST_LOCK
diff --cc landing/answers/autoindex-exit-codes.html
index c88cb8a2e,dd5a34d59..b130a28b8
--- a/landing/answers/autoindex-exit-codes.html
+++ b/landing/answers/autoindex-exit-codes.html
@@@ -16,7 -16,7 +16,7 @@@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>What do the xerj autoindex exit codes mean?</title>
--<meta name="description" content="xerj autoindex exits 0 complete, 3 completed-with-junk, 4 needs-a-decision, 2 usage and 1 on an endpoint or journal failure. Only 4 is asking you a question.">
++<meta name="description" content="xerj autoindex exits 0 complete, 3 completed-with-junk, 4 needs-a-decision, 2 usage and 1 on a runtime failure. Only 4 is asking you a question.">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Big+Shoulders+Display:wght@400;700;800;900&family=Inter:wght@400;500;600;700&family=IBM+Plex+Sans:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500;700&display=swap" rel="stylesheet">
@@@ -29,7 -29,7 +29,7 @@@
<meta property="og:site_name" content="XERJ.ai">
<meta property="og:type" content="article">
<meta property="og:title" content="What do the xerj autoindex exit codes mean?">
--<meta property="og:description" content="xerj autoindex exits 0 complete, 3 completed-with-junk, 4 needs-a-decision, 2 usage and 1 on an endpoint or journal failure. Only 4 is asking you a question.">
++<meta property="og:description" content="xerj autoindex exits 0 complete, 3 completed-with-junk, 4 needs-a-decision, 2 usage and 1 on a runtime failure. Only 4 is asking you a question.">
<meta property="og:url" content="https://xerj.org/answers/autoindex-exit-codes">
<meta property="og:image" content="https://xerj.org/og/xerj-card.png">
<meta property="og:image:width" content="1200">
@@@ -38,7 -38,7 +38,7 @@@
<meta property="og:locale" content="en_US">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:title" content="What do the xerj autoindex exit codes mean?">
--<meta name="twitter:description" content="xerj autoindex exits 0 complete, 3 completed-with-junk, 4 needs-a-decision, 2 usage and 1 on an endpoint or journal failure. Only 4 is asking you a question.">
++<meta name="twitter:description" content="xerj autoindex exits 0 complete, 3 completed-with-junk, 4 needs-a-decision, 2 usage and 1 on a runtime failure. Only 4 is asking you a question.">
<meta name="twitter:image" content="https://xerj.org/og/xerj-card.png">
<script type="application/ld+json">
{
@@@ -74,7 -74,7 +74,7 @@@
"@context": "https://schema.org",
"@type": "TechArticle",
"headline": "What do the xerj autoindex exit codes mean?",
-- "description": "xerj autoindex exits 0 complete, 3 completed-with-junk, 4 needs-a-decision, 2 usage and 1 on an endpoint or journal failure. Only 4 is asking you a question.",
++ "description": "xerj autoindex exits 0 complete, 3 completed-with-junk, 4 needs-a-decision, 2 usage and 1 on a runtime failure. Only 4 is asking you a question.",
"url": "https://xerj.org/answers/autoindex-exit-codes",
"image": "https://xerj.org/og/xerj-card.png",
"inLanguage": "en",
@@@ -140,7 -140,7 +140,7 @@@
"name": "How do I tell a failed index from a completed one with junk files?",
"acceptedAnswer": {
"@type": "Answer",
- "text": "Read the exit code and terminal reason. A stale-resume-plan outcome is incomplete and needs --fresh; otherwise 0 and 3 are finished runs; 3 additionally refused at least one file, or a whole dataset whose mapping the server answered HTTP 400 to, in which case the xerj-done line carries datasets_refused and files_refused. 1 is an endpoint or journal failure and nothing about it is a junk report."
- "text": "Read the exit code, not the log volume. 0 and 3 are both finished runs; 3 additionally refused at least one file, or a whole dataset whose mapping the server answered HTTP 400 to, in which case the xerj-done line carries datasets_refused and files_refused. 1 is an endpoint or journal failure and nothing about it is a junk report."
++ "text": "Read the exit code and terminal reason. A stale-resume-plan outcome is incomplete and needs --fresh; otherwise 0 and 3 are finished runs; 3 additionally refused at least one file, or a whole dataset whose mapping the server answered HTTP 400 to, in which case the xerj-done line carries datasets_refused and files_refused. 1 is a runtime failure and nothing about it is a junk report."
}
},
{
@@@ -148,7 -148,7 +148,7 @@@
"name": "Is exit 1 the code for any error?",
"acceptedAnswer": {
"@type": "Answer",
-- "text": "No, and that shorthand is wrong. --help scopes 1 to an endpoint or journal failure, a refused corpus removal, or a refused unsafe state transition. A bad command line is 2. On the --no-graph path, an exit 1 whose terminal line reads reason=server-backpressure means the node rejected every write for the whole 600 s a bulk waits; the line carries ops_applied and ops_remaining."
++ "text": "Exit 1 covers runtime errors, including verification failures, node or journal problems, and refused unsafe operations. A bad command line is 2. On the --no-graph path, an exit 1 whose terminal line reads reason=server-backpressure means the node rejected every write for the whole 600 s a bulk waits; the line carries ops_applied and ops_remaining."
}
},
{
@@@ -232,17 -232,17 +232,17 @@@
<div class="breadcrumb"><a href="/">HOME</a><span class="sep">·</span><a href="/answers/">ANSWERS</a><span class="sep">·</span>THE INDEXER EXITED 3 (OR 4). DID IT FAIL?</div>
<div class="kicker"><span>ANSWERS · OPERATIONS: EXIT CODES</span></div>
<h1>The indexer exited 3 (or 4). Did it fail?</h1>
- <div class="source-note">AUTHOR · XERJ documentation team · REVIEWED BY · XERJ engineering team · PUBLISHED · 2026-08-22 · UPDATED · 2026-10-24</div>
+ <div class="source-note">AUTHOR · XERJ documentation team · REVIEWED BY · XERJ engineering team · PUBLISHED · 2026-08-22 · UPDATED · 2026-10-28</div>
<div class="prompt-card answer-first" id="short-answer">
- <span class="prompt-label">SHORT ANSWER · UPDATED 2026-10-24</span>
- <p>What does indexer exit code 3 mean for xerj autoindex? It means success: the run completed and recorded some junk files. Exit 0 is a clean completion, 4 means the estimate exceeded --max-minutes and nothing was indexed, 2 is a usage error, and 1 is an endpoint or journal failure. Only exit 4 asks you a question.</p>
+ <span class="prompt-label">SHORT ANSWER · UPDATED 2026-10-28</span>
+ <p>Exit 3 means the run finished with an outcome to inspect. Completed-with-junk is success; stale-resume-plan carries ok=false because new files were not indexed and needs a --fresh rebuild. Exit 0 is completion or cancellation, 4 needs approval, 2 is usage, and 1 is a real failure. Read the terminal reason and refusal counts before reporting coverage.</p>
<p class="key-fact"><strong>Key number:</strong> The decision gate that produces exit 4 defaults to 10 minutes of estimated work (<code class="inline">DEFAULT_MAX_MINUTES</code>). <span class="mute">(as of 2026-10-19 · source: <a href="https://github.com/xerj-org/xerj/blob/main/engine/crates/xerj-autoindex/src/gate.rs">engine/crates/xerj-autoindex/src/gate.rs</a>)</span></p>
</div>
- <p><strong>TL;DR</strong> — Read the terminal reason as well as the exit code. Exit 3 with <code class="inline">completed-with-junk</code> is success; <code class="inline">stale-resume-plan</code> has <code class="inline">ok=false</code> because new files were not indexed and needs a <code class="inline">--fresh</code> rebuild. <code class="inline">xerj autoindex</code> exits 0 when the run completed, and 3 when it completed and recorded junk. Exit 4 means the estimate exceeded <code class="inline">--max-minutes</code> and nothing was indexed. Exit 2 is a usage error, and exit 1 is an endpoint or journal failure. Only 4 is a question.</p>
- <p><strong>TL;DR</strong> — Exit 3 is a success. <code class="inline">xerj autoindex</code> exits 0 when the run completed, and 3 when it completed and recorded junk. Exit 4 means the estimate exceeded <code class="inline">--max-minutes</code> and nothing was indexed. Exit 2 is a usage error, and exit 1 is an endpoint or journal failure. Only 4 is a question.</p>
++ <p><strong>TL;DR</strong> — Read the terminal reason as well as the exit code. Exit 3 with <code class="inline">completed-with-junk</code> is success; <code class="inline">stale-resume-plan</code> has <code class="inline">ok=false</code> because new files were not indexed and needs a <code class="inline">--fresh</code> rebuild. <code class="inline">xerj autoindex</code> exits 0 when the run completed, and 3 when it completed and recorded junk. Exit 4 means the estimate exceeded <code class="inline">--max-minutes</code> and nothing was indexed. Exit 2 is a usage error, and exit 1 is a runtime failure. Only 4 is a question.</p>
<div class="prompt-card">
<span class="prompt-label">PASTE THIS TO YOUR AI AGENT — IT DOES THE REST</span>
- <code>Act as a coding agent. Read https://xerj.org/llms.txt, run xerj autoindex on the folder, then branch on the process exit code before you report anything: 0 and 3 are finished runs, 4 is a decision request on stdout that you answer with --approve, 2 is a bad command line, and 1 is a real failure to retry or escalate.</code>
- <button type="button" class="prompt-copy" data-copy="Act as a coding agent. Read https://xerj.org/llms.txt, run xerj autoindex on the folder, then branch on the process exit code before you report anything: 0 and 3 are finished runs, 4 is a decision request on stdout that you answer with --approve, 2 is a bad command line, and 1 is a real failure to retry or escalate.">COPY THE PROMPT</button>
+ <code>Read https://xerj.org/llms.txt, then inspect the terminal reason as well as the exit code. Exit 3 with stale-resume-plan has ok=false and needs --fresh; completed-with-junk requires reading the refusal list. Answer exit 4 with --approve, correct usage on 2, and investigate the error on 1.</code>
+ <button type="button" class="prompt-copy" data-copy="Read https://xerj.org/llms.txt, then inspect the terminal reason as well as the exit code. Exit 3 with stale-resume-plan has ok=false and needs --fresh; completed-with-junk requires reading the refusal list. Answer exit 4 with --approve, correct usage on 2, and investigate the error on 1.">COPY THE PROMPT</button>
</div>
<div class="prompt-card">
<span class="prompt-label">RUN THIS XERJ COMMAND</span>
@@@ -309,17 -307,17 +309,17 @@@
<p>You answer it by re-running the same command with <code class="inline">--approve proceed</code>, <code class="inline">--approve fast</code> or <code class="inline">--approve cancel</code>. <code class="inline">fast</code> also applies <code class="inline">--no-semantic --no-graph</code>.</p>
<p>A person at a terminal is prompted instead, but only when the question can actually be seen: stdin a terminal, stderr a terminal, and the progress surface on. A piped or agent-driven run is never prompted, and <code class="inline">--quiet</code> silences the prompt as well. Every un-prompted run behaves identically — the JSON request goes to stdout, which <code class="inline">--quiet</code> does not silence, and the process exits 4. The payload's <code class="inline">prompt_not_offered_because</code> names which of the three conditions was missing.</p>
<p><code class="inline">xerj autoindex</code> never waits on stdin for a question it did not print.</p>
-- <h2>Exit 1 and exit 2 are narrower than "any error"</h2>
-- <p>The common shorthand is that 1 means any error. The binary is more specific, and the difference matters to a retry policy.</p>
++ <h2>Read the error before retrying exit 1 or 2</h2>
++ <p>Exit 1 covers runtime failures. Exit 2 identifies a usage error. The diagnostic tells you what needs to change.</p>
<p><code class="inline">2 usage</code> is a bad command line. Nothing ran, and a retry of the same command will fail the same way.</p>
-- <p><code class="inline">1</code> is an endpoint or journal failure, a refused corpus removal, or a refused unsafe state transition. The last two are refusals by design, not crashes: removing an indexed file is refused before any remote mutation, because its documents are already live and nothing on that path deletes them.</p>
++ <p><code class="inline">1</code> covers runtime failures, including node or journal errors, refused unsafe operations, unavailable parser workers, and missing-data verification failures. A refusal need not mean a crash. Follow its recovery message; an unchanged retry does not correct missing or incompatible state.</p>
<p>So a 1 is not always something to retry. Read the error line first.</p>
<h3>Two exit-1 endings that name themselves</h3>
<p>On the <code class="inline">--no-graph</code> path, a run whose node answered its writes with HTTP 429 for the whole 600 seconds a bulk waits ends with a reason of its own instead of <code class="inline">aborted</code>:</p>
<pre class="code"><code class="language-text">autoindex: stopped by server back-pressure while applying &lt;file&gt;: N operation(s) are journaled applied, M are not (this one first) — the same command resumes from here once the node accepts writes again
xerj-done ok=false exit=1 reason=server-backpressure wall=… ops_applied=N ops_remaining=M
</code></pre>
-- <p>Forced on a real node with a 64 MiB memory cap, that line read <code class="inline">xerj-done ok=false exit=1 reason=server-backpressure wall=609.1s ops_applied=0 ops_remaining=231</code>. The applied operations are journaled, so the same command resumes with the <code class="inline">M</code> that remain once the node accepts writes again. On that node, restarted on its default cap, it did. It is exit 1 and not 3 on purpose: 3 means a finished run with nothing to retry, and this generation is not finished. The <a href="/answers/autoindex-server-back-pressure-429">back-pressure page</a> covers the node side.</p>
++ <p>Forced on a real node with a 64 MiB memory cap, that line read <code class="inline">xerj-done ok=false exit=1 reason=server-backpressure wall=609.1s ops_applied=0 ops_remaining=231</code>. The applied operations are journaled, so the same command resumes with the <code class="inline">M</code> that remain once the node accepts writes again. On that node, restarted on its default cap, it did. It is exit 1 and not 3 on purpose: the completed-with-junk outcome is finished, while this generation is not finished. The <a href="/answers/autoindex-server-back-pressure-429">back-pressure page</a> covers the node side.</p>
<p>A request the node calls too large is no longer an exit 1 at all. Until issue #955, both indexing paths sent the catalog as one <code class="inline">_bulk</code> request, one document per file, per dataset and per run. A corpus whose catalog held more than the engine's <code class="inline">limits.max_actions_per_bulk</code> (50,000 by default) applied every operation and then failed at the very end. On a 48,533-file corpus the <code class="inline">--no-graph</code> run ended 10,336 seconds in:</p>
<pre class="code"><code class="language-text">xerj-done ok=false exit=1 reason=aborted wall=10336.0s
error: prepared bulk contained 1 rejected items: {"type":"engine_exception","reason":"bulk request contains 102258 lines (~51129 actions); exceeds max_actions_per_bulk of 50000","status":413}
@@@ -359,9 -357,9 +359,9 @@@
<h3>Why did folder indexing stop and ask me to approve?</h3>
<p>The measured phase-A estimate for the indexing phase was longer than <code class="inline">--max-minutes</code> (default 10). With no <code class="inline">--approve</code> or <code class="inline">--yes</code>, nothing is indexed, a JSON decision request goes to stdout and the process exits 4.</p>
<h3>How do I tell a failed index from a completed one with junk files?</h3>
- <p>Read the exit code and terminal reason. A stale-resume-plan outcome is incomplete and needs --fresh; otherwise 0 and 3 are finished runs; 3 additionally refused at least one file, or a whole dataset whose mapping the server answered HTTP 400 to, in which case the <code class="inline">xerj-done</code> line carries <code class="inline">datasets_refused</code> and <code class="inline">files_refused</code>. 1 is an endpoint or journal failure and nothing about it is a junk report.</p>
- <p>Read the exit code, not the log volume. 0 and 3 are both finished runs; 3 additionally refused at least one file, or a whole dataset whose mapping the server answered HTTP 400 to, in which case the <code class="inline">xerj-done</code> line carries <code class="inline">datasets_refused</code> and <code class="inline">files_refused</code>. 1 is an endpoint or journal failure and nothing about it is a junk report.</p>
++ <p>Read the exit code and terminal reason. A stale-resume-plan outcome is incomplete and needs --fresh; otherwise 0 and 3 are finished runs; 3 additionally refused at least one file, or a whole dataset whose mapping the server answered HTTP 400 to, in which case the <code class="inline">xerj-done</code> line carries <code class="inline">datasets_refused</code> and <code class="inline">files_refused</code>. 1 is a runtime failure and nothing about it is a junk report.</p>
<h3>Is exit 1 the code for any error?</h3>
-- <p>No, and that shorthand is wrong. <code class="inline">--help</code> scopes 1 to an endpoint or journal failure, a refused corpus removal, or a refused unsafe state transition. A bad command line is 2. On the <code class="inline">--no-graph</code> path, an exit 1 whose terminal line reads <code class="inline">reason=server-backpressure</code> means the node rejected every write for the whole 600 s a bulk waits; the line carries <code class="inline">ops_applied</code> and <code class="inline">ops_remaining</code>.</p>
++ <p>Exit 1 covers runtime errors, including verification failures, node or journal problems, and refused unsafe operations. A bad command line is 2. On the <code class="inline">--no-graph</code> path, an exit 1 whose terminal line reads <code class="inline">reason=server-backpressure</code> means the node rejected every write for the whole 600 s a bulk waits; the line carries <code class="inline">ops_applied</code> and <code class="inline">ops_remaining</code>.</p>
<h3>Does exit 0 always mean the folder was indexed?</h3>
<p>No. Answering the decision gate with <code class="inline">--approve cancel</code> also exits 0, and that run indexes nothing on purpose. Read the terminal line or the journal before you report a corpus as searchable.</p>
<h3>Why did my run print no terminal line at all?</h3>
diff --cc landing/answers/autoindex-exit-codes.md
index f1de58fd0,53d54f8f9..7c8d12d02
--- a/landing/answers/autoindex-exit-codes.md
+++ b/landing/answers/autoindex-exit-codes.md
@@@ -12,7 -12,7 +12,7 @@@ source: "content/answers/autoindex-exit
**Key number:** The decision gate that produces exit 4 defaults to 10 minutes of estimated work (`DEFAULT_MAX_MINUTES`). (as of 2026-10-19; source: [engine/crates/xerj-autoindex/src/gate.rs](https://github.com/xerj-org/xerj/blob/main/engine/crates/xerj-autoindex/src/gate.rs))
- **TL;DR** — Read the terminal reason as well as the exit code. Exit 3 with `completed-with-junk` is success; `stale-resume-plan` has `ok=false` because new files were not indexed and needs a `--fresh` rebuild. `xerj autoindex` exits 0 when the run completed, and 3 when it completed and recorded junk. Exit 4 means the estimate exceeded `--max-minutes` and nothing was indexed. Exit 2 is a usage error, and exit 1 is an endpoint or journal failure. Only 4 is a question.
-**TL;DR** — Exit 3 is a success. `xerj autoindex` exits 0 when the run completed, and 3 when it completed and recorded junk. Exit 4 means the estimate exceeded `--max-minutes` and nothing was indexed. Exit 2 is a usage error, and exit 1 is an endpoint or journal failure. Only 4 is a question.
++**TL;DR** — Read the terminal reason as well as the exit code. Exit 3 with `completed-with-junk` is success; `stale-resume-plan` has `ok=false` because new files were not indexed and needs a `--fresh` rebuild. `xerj autoindex` exits 0 when the run completed, and 3 when it completed and recorded junk. Exit 4 means the estimate exceeded `--max-minutes` and nothing was indexed. Exit 2 is a usage error, and exit 1 is a runtime failure. Only 4 is a question.
## Agent prompt
@@@ -125,13 -116,13 +125,13 @@@ A person at a terminal is prompted inst
`xerj autoindex` never waits on stdin for a question it did not print.
--## Exit 1 and exit 2 are narrower than "any error"
++## Read the error before retrying exit 1 or 2
--The common shorthand is that 1 means any error. The binary is more specific, and the difference matters to a retry policy.
++Exit 1 covers runtime failures. Exit 2 identifies a usage error. The diagnostic tells you what needs to change.
`2 usage` is a bad command line. Nothing ran, and a retry of the same command will fail the same way.
--`1` is an endpoint or journal failure, a refused corpus removal, or a refused unsafe state transition. The last two are refusals by design, not crashes: removing an indexed file is refused before any remote mutation, because its documents are already live and nothing on that path deletes them.
++`1` covers runtime failures, including node or journal errors, refused unsafe operations, unavailable parser workers, and missing-data verification failures. A refusal need not mean a crash. Follow its recovery message; an unchanged retry does not correct missing or incompatible state.
So a 1 is not always something to retry. Read the error line first.
@@@ -144,7 -135,7 +144,7 @@@ autoindex: stopped by server back-press
xerj-done ok=false exit=1 reason=server-backpressure wall=… ops_applied=N ops_remaining=M
```
--Forced on a real node with a 64 MiB memory cap, that line read `xerj-done ok=false exit=1 reason=server-backpressure wall=609.1s ops_applied=0 ops_remaining=231`. The applied operations are journaled, so the same command resumes with the `M` that remain once the node accepts writes again. On that node, restarted on its default cap, it did. It is exit 1 and not 3 on purpose: 3 means a finished run with nothing to retry, and this generation is not finished. The [back-pressure page](/answers/autoindex-server-back-pressure-429) covers the node side.
++Forced on a real node with a 64 MiB memory cap, that line read `xerj-done ok=false exit=1 reason=server-backpressure wall=609.1s ops_applied=0 ops_remaining=231`. The applied operations are journaled, so the same command resumes with the `M` that remain once the node accepts writes again. On that node, restarted on its default cap, it did. It is exit 1 and not 3 on purpose: the completed-with-junk outcome is finished, while this generation is not finished. The [back-pressure page](/answers/autoindex-server-back-pressure-429) covers the node side.
A request the node calls too large is no longer an exit 1 at all. Until issue #955, both indexing paths sent the catalog as one `_bulk` request, one document per file, per dataset and per run. A corpus whose catalog held more than the engine's `limits.max_actions_per_bulk` (50,000 by default) applied every operation and then failed at the very end. On a 48,533-file corpus the `--no-graph` run ended 10,336 seconds in:
@@@ -211,11 -202,11 +211,11 @@@ The measured phase-A estimate for the i
### How do I tell a failed index from a completed one with junk files?
- Read the exit code and terminal reason. A stale-resume-plan outcome is incomplete and needs --fresh; otherwise 0 and 3 are finished runs; 3 additionally refused at least one file, or a whole dataset whose mapping the server answered HTTP 400 to, in which case the `xerj-done` line carries `datasets_refused` and `files_refused`. 1 is an endpoint or journal failure and nothing about it is a junk report.
-Read the exit code, not the log volume. 0 and 3 are both finished runs; 3 additionally refused at least one file, or a whole dataset whose mapping the server answered HTTP 400 to, in which case the `xerj-done` line carries `datasets_refused` and `files_refused`. 1 is an endpoint or journal failure and nothing about it is a junk report.
++Read the exit code and terminal reason. A stale-resume-plan outcome is incomplete and needs --fresh; otherwise 0 and 3 are finished runs; 3 additionally refused at least one file, or a whole dataset whose mapping the server answered HTTP 400 to, in which case the `xerj-done` line carries `datasets_refused` and `files_refused`. 1 is a runtime failure and nothing about it is a junk report.
### Is exit 1 the code for any error?
--No, and that shorthand is wrong. `--help` scopes 1 to an endpoint or journal failure, a refused corpus removal, or a refused unsafe state transition. A bad command line is 2. On the `--no-graph` path, an exit 1 whose terminal line reads `reason=server-backpressure` means the node rejected every write for the whole 600 s a bulk waits; the line carries `ops_applied` and `ops_remaining`.
++Exit 1 covers runtime errors, including verification failures, node or journal problems, and refused unsafe operations. A bad command line is 2. On the `--no-graph` path, an exit 1 whose terminal line reads `reason=server-backpressure` means the node rejected every write for the whole 600 s a bulk waits; the line carries `ops_applied` and `ops_remaining`.
### Does exit 0 always mean the folder was indexed?
diff --cc landing/answers/index.html
index 2af85eeaa,418848942..2c0b59314
--- a/landing/answers/index.html
+++ b/landing/answers/index.html
@@@ -304,7 -304,7 +304,7 @@@
<h2>Operations: exit codes</h2>
<ul>
<li><a href="/answers/autoindex-dataset-refused-by-server">One dataset was REFUSED by the server. Did I lose the whole index?</a> — When the server refuses one dataset's mapping, xerj autoindex records that dataset's files as junk, indexes every other dataset, and exits 3 with datasets_refused on the terminal line.</li>
-- <li><a href="/answers/autoindex-exit-codes">The indexer exited 3 (or 4). Did it fail?</a> — xerj autoindex exits 0 complete, 3 completed-with-junk, 4 needs-a-decision, 2 usage and 1 on an endpoint or journal failure. Only 4 is asking you a question.</li>
++ <li><a href="/answers/autoindex-exit-codes">The indexer exited 3 (or 4). Did it fail?</a> — xerj autoindex exits 0 complete, 3 completed-with-junk, 4 needs-a-decision, 2 usage and 1 on a runtime failure. Only 4 is asking you a question.</li>
<li><a href="/answers/autoindex-server-back-pressure-429">The server pushed back with HTTP 429. Did xerj autoindex lose the run?</a> — When the node answers a bulk, or items inside one, with HTTP 429 (its memory circuit breaker), xerj autoindex re-sends the rejected items, waits out the moment, and reports bulk_retries on the terminal line. Only 600 s of re-sends that never clear is fatal.</li>
<li><a href="/answers/autoindex-says-extract-the-archive-first">xerj autoindex recorded my Takeout .zip as junk and said to extract it first. Why?</a> — autoindex never opens archives. A .zip, .tgz, .7z, .rar or .xz is marked as junk with the exact extraction command; the run continues. Index the extracted folder.</li>
</ul>