<!-- generated by build_articles.py — edit content/answers/autoindex-exit-codes.md instead -->
---
title: "What do the xerj autoindex exit codes mean?"
canonical: "https://xerj.org/answers/autoindex-exit-codes"
updated: "2026-10-28"
source: "content/answers/autoindex-exit-codes.md"
---

# The indexer exited 3 (or 4). Did it fail?

**Short answer** (updated 2026-10-28): 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.

**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. With `stale-resume-plan`, `ok=false` means new files were not indexed.

## Agent prompt

```text
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.
```

## Commands

### Command 1

Note: Print the exit-code contract from the binary you actually installed.

```sh
xerj autoindex --help
```

### Command 2

Note: A normal run. Inspect the terminal reason and refusal counters; exit 3 may also mean a stale resume plan.

```sh
xerj autoindex ./corpus --url http://127.0.0.1:9200 --prefix ax --state-dir ./state --progress plain
```

### Command 3

Note: Set a low budget so the estimate can trip the decision gate and exit 4.

```sh
xerj autoindex ./corpus --url http://127.0.0.1:9200 --prefix ax --state-dir ./state --max-minutes 1 --progress plain
```

### Command 4

Note: Answer a decision request by re-running the same command with --approve.

```sh
xerj autoindex ./corpus --url http://127.0.0.1:9200 --prefix ax --state-dir ./state --approve proceed --progress plain
```

### Command 5

Note: Read the journal when the process is gone and you have no terminal line.

```sh
xerj autoindex status --url http://127.0.0.1:9200 --state-dir ./state
```

Rebuild with `--fresh` to include new files after `stale-resume-plan`. Exit 0 means the run completed; exit 3 means it completed with a reported limitation or 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

The table summarizes `xerj autoindex --help`; the terminal reason distinguishes partial outcomes. Run that command yourself before you write a branch on any of these numbers.

| Exit | Name in `--help` | What it means for the corpus |
| --- | --- | --- |
| 0 | complete | The run finished and refused nothing. A gate answered with `--approve cancel` also exits 0. |
| 3 | completed with a reported outcome | Read `reason`: completed-with-junk is success with refusals to inspect; stale-resume-plan means new files were skipped and needs `--fresh`. Refused datasets can leave an entire dataset missing. |
| 4 | NEEDS A DECISION | The estimate exceeded `--max-minutes`. Nothing was indexed. A JSON decision request is on stdout. |
| 2 | usage | The command line was wrong. Nothing ran. |
| 1 | endpoint/journal failure | The node or the resume journal failed, a corpus removal was refused, or an unsafe state transition was refused. |

Read the table in that order rather than in numeric order. It is the order the help text uses, and it is the order of decreasing goodness.

## Exit 3 is a finished run

`3 completed-with-junk (junk recorded, never fatal) — SUCCESS` is the phrase in the help text, and it says to treat 0 and 3 alike as a finished run. That describes completed-with-junk. For `reason=stale-resume-plan`, the run instead reports `ok=false` and leads with `not ok:`: new files were left out of its frozen plan.

A folder of real files almost always contains something XERJ will not parse. An unknown binary, an image, a file above `--max-file-gb`. Those files are recorded in the catalog with a reason, and the rest of the folder is indexed and queryable.

An agent that treats a non-zero exit as a failure will therefore throw away a perfectly good index. Branch on the specific value.

The companion check is the refusal list, not the exit code: read `autoindex-catalog` and match each refused path to its reason. The [skipped-files page](/answers/why-autoindex-skipped-files) covers that query.

## Exit 3 with a stale resume plan needs a rebuild

With `reason=stale-resume-plan`, `skipped_appeared` counts files that arrived
after the saved plan was frozen. The terminal event carries `ok=false`, names
the skipped paths, and gives a `--fresh` recovery command. Existing indexed
files remain searchable. Re-run the same indexing command with `--fresh` to
rebuild the plan and include the new files; an unchanged resume still uses the
old plan. This outcome is not a junk classification.

## Exit 3 can also mean a whole dataset is missing

The server can refuse the mapping of one dataset with an HTTP 400. That used to abort the entire run with exit 1 and index nothing. It now costs that one dataset: its files are recorded as junk with the server's reason, every other dataset is indexed, and the run exits 3.

The terminal line says so, and only when it happened:

```text
xerj-done ok=true exit=3 reason=completed-with-junk wall=0.7s files=1 records=1 generation=1 datasets_refused=1 files_refused=2 code_files=0 code_files_indexed=0 code_files_junked=0
```

So an exit 3 is still a finished run, but it is not always a small gap. Read `datasets_refused` before you report a corpus as searchable. The [refused-dataset page](/answers/autoindex-dataset-refused-by-server) covers what is recorded and how to recover.

Only a 400 is a refusal. A 401, 403, 404, 408, 429 or 5xx on the same request says nothing about that dataset, so it still exits 1.

A 429 *on a bulk* is different, whether it is the whole request or some of its items marked `status: 429`. When the node's memory circuit breaker answers that way, the run re-sends the rejected items after a backoff and carries on. It exits 1 only after 600 seconds of re-sends the node never takes.

The error line begins `the server kept rejecting`. The terminal line of a run that met back-pressure and finished carries `bulk_retries=N`. The [back-pressure page](/answers/autoindex-server-back-pressure-429) covers it.

## Exit 4 is a question, and nothing was written

Phase A reads and parses every file to sniff and sample it, so it measures throughput per format family on the machine you are on. It turns that into a range for the indexing phase, and the gate compares the upper end of the range against `--max-minutes` (default 10).

If the upper end is longer and no `--approve` or `--yes` was given, **nothing is indexed**. A JSON decision request goes to stdout and the process exits 4.

You answer it by re-running the same command with `--approve proceed`, `--approve fast` or `--approve cancel`. `fast` also applies `--no-semantic --no-graph`.

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 `--quiet` silences the prompt as well. Every un-prompted run behaves identically — the JSON request goes to stdout, which `--quiet` does not silence, and the process exits 4. The payload's `prompt_not_offered_because` names which of the three conditions was missing.

`xerj autoindex` never waits on stdin for a question it did not print.

## Read the error before retrying exit 1 or 2

Exit 1 covers runtime failures. Exit 2 identifies a usage error. The diagnostic identifies the required change.

`2 usage` is a bad command line. Nothing ran, and a retry of the same command will fail the same way.

`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.

### Two exit-1 endings that name themselves

On the `--no-graph` 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 `aborted`:

```text
autoindex: stopped by server back-pressure while applying <file>: 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
```

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:

```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}
```

Every `_bulk` body now goes out in windows of at most 10,000 actions. A request the node still refuses for its size is cut in two and sent again, and the terminal line carries `bulk_splits=N` when that happened. Against real nodes with `max_actions_per_bulk = 64` and with `max_body_bytes = 98304`, each run ended `ok=true exit=3 records=1663 bulk_splits=1`, the same documents as a control run. Resuming that same generation with the change committed it:

```text
xerj-done ok=true exit=3 reason=completed-with-junk wall=415.0s files=47444 records=821840 generation=1 code_files=34324 code_files_indexed=34324 code_files_junked=0
```

One document that is larger than the node's `limits.max_body_bytes` cannot be cut, and it still ends the run with exit 1 and an error that names that setting.

## Do not read the code alone

Every run that reaches an exit, success or error, ends with one terminal line in every progress mode except `none`.

```text
xerj-done ok=true exit=3 reason=completed-with-junk wall=0.6s files=4 records=1 generation=1
```

That line carries the reason string, the wall time and the code-coverage counters `code_files`, `code_files_indexed` and `code_files_junked`. A corpus whose source files were all dropped therefore cannot print the same line as a healthy one.

Two cases print no terminal line at all. `--quiet` and `--progress none` print none by design, so poll `xerj autoindex status --state-dir <dir>` or read the exit code instead of waiting for output that never comes. A run killed by a signal cannot print one either — a missing terminal line after the process is gone means it died, not that it finished.

## What an agent should do with each code

| Exit | Corpus state | Next action |
| --- | --- | --- |
| 0 | indexed, nothing refused (or cancelled on purpose) | Read the terminal line, then query. |
| 3 | indexed, something refused | Read `datasets_refused` on the terminal line, query, then read `autoindex-catalog` for the refusals. |
| 4 | untouched | Re-run the same command with `--approve proceed`, `fast` or `cancel`. |
| 2 | untouched | Fix the command line. Do not retry unchanged. |
| 1 | partial or untouched | Read the error, check the node and the journal, then decide. |

Pair this with the four-number reconciliation on the [completeness page](/answers/check-codebase-index-is-complete). The exit code tells you how the process ended; only the counts tell you what is in the index.

## How this page was checked

The codes above were read from `xerj autoindex --help` on a built binary and cross-checked against the help string in `engine/crates/xerj-autoindex/src/cli.rs`. Both agree.

One code was forced for this page. It is the exit 3 of a refused dataset, on a throwaway node, by pre-creating the dataset's index with a conflicting field type. That capture is committed under `benchmarks/autoindex-resilience/`.

The folder also holds the full-corpus exit 1 in `finalize-catalog`. It holds the exit 3 of the same generation resumed after issue #955 was fixed (`before-955.stderr.txt`, `after-955.full-corpus-resume.stderr.txt`). It holds a `reason=server-backpressure` exit 1 forced with a 64 MiB memory cap (`limits-real-node.txt`).

The other codes were not forced, so there is no capture for them here and no timing. If you want the codes on your own build, `xerj autoindex --help` prints them in one screen.

## FAQ

### What does indexer exit code 3 mean?

It means the run completed and recorded junk. `xerj autoindex --help` states it as `3 completed-with-junk (junk recorded, never fatal) — SUCCESS` and says to treat 0 and 3 alike as a finished run. For completed-with-junk, read the refusal list. For reason=stale-resume-plan, ok=false means new files were not indexed; rebuild with --fresh.

### The indexer exited 3 (or 4). Did it fail?

3 requires checking its reason: a stale resume plan leaves new files unindexed. 4 did not index anything: it is a decision request waiting for `--approve`. Only 1 and 2 are failures.

### Why did folder indexing stop and ask me to approve?

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.

### 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 a runtime failure and nothing about it is a junk report.

### Is exit 1 the code for any error?

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?

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.

### Why did my run print no terminal line at all?

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.

### Which codes should an agent retry?

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.

## Evidence

- Exit 3 completed-with-junk is success. The separate stale-resume-plan outcome carries ok=false and requires --fresh to include new files. Dataset refusal counters name missing datasets even when ok=true. Exit 1 reports real errors; usage is 2 and a decision request is 4. Source: `engine/crates/xerj-autoindex/src/cli.rs:771`
- Exit 4 is a code of its own; 1 is the catch-all for real failures, and the decision request is answered by re-running the same command with --approve proceed, fast or cancel. Source: `engine/crates/xerj-autoindex/src/cli.rs:771`
- A forced mapping refusal ended xerj-done ok=true exit=3 reason=completed-with-junk wall=0.7s files=1 records=1 generation=1 datasets_refused=1 files_refused=2, with the other dataset indexed. Source: `benchmarks/autoindex-resilience/refusal-e2e.run1.stderr.txt`
- Before issue #955 was fixed, a 48,533-file --no-graph run applied every operation and then ended xerj-done ok=false exit=1 reason=aborted wall=10336.0s, because the catalog went out as one bulk request of 51,129 actions and the engine's max_actions_per_bulk is 50,000. Source: `benchmarks/autoindex-resilience/before-955.stderr.txt`
- Resuming that same generation with the fix ended xerj-done ok=true exit=3 reason=completed-with-junk wall=415.0s files=47444 records=821840 generation=1. Source: `benchmarks/autoindex-resilience/after-955.full-corpus-resume.stderr.txt`
- On a real node started with a 64 MiB memory cap, a --no-graph run ended xerj-done ok=false exit=1 reason=server-backpressure wall=609.1s ops_applied=0 ops_remaining=231; against real nodes with max_actions_per_bulk = 64 and with max_body_bytes = 98304, each run ended ok=true exit=3 records=1663 bulk_splits=1. Source: `benchmarks/autoindex-resilience/limits-real-node.txt`
- Every run that reaches an exit ends with one terminal line in every progress mode except none, which --quiet selects; a run killed by a signal cannot print one either. Source: `engine/crates/xerj-autoindex/src/lib.rs:277`

## Related

- [My codebase indexer says indexed but I don't see my code. How do I check it actually finished?](/answers/check-codebase-index-is-complete)
- [How do I read autoindex progress?](/answers/read-autoindex-progress)
- [How do I estimate folder-indexing time?](/answers/estimate-autoindex-time-before-running)
- [The indexer died overnight. Do I have to start over?](/answers/resume-interrupted-autoindex-run)
- [Why would a folder search miss files that I can see on disk?](/answers/why-autoindex-skipped-files)
- [One dataset was REFUSED by the server. Did I lose the whole index?](/answers/autoindex-dataset-refused-by-server)
- [The server pushed back with HTTP 429. Did xerj autoindex lose the run?](/answers/autoindex-server-back-pressure-429)
- [xerj autoindex recorded my Takeout .zip as junk and said to extract it first. Why?](/answers/autoindex-says-extract-the-archive-first) (same intent: operating autoindex)
- [How do I keep a search index up to date as files change, without re-indexing everything?](/answers/keep-index-current-as-files-change) (same intent: operating autoindex)
- [How do I keep an index current when the files live in an object store?](/answers/keep-s3-bucket-index-current) (same intent: operating autoindex)
