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.
Rust agent-memoryai-agentsbm25claude-codeclicode-searchcursordatabaseelasticsearchfull-text-searchhybrid-searchjsonllocal-firstmcpmcp-servermodel-context-protocolragrustsearch-enginevector-search
merge: bring in main (#247 lifecycle, #260 index:false, #265/#267 search order)
xerj-org6e222b87369d
diff --cc CHANGELOG.mdindex 1a32cf870,7851c4917..27d530d2d--- a/CHANGELOG.md+++ b/CHANGELOG.md@@@ -80,83 -80,194 +80,271 @@@ and this project adheres to [Semantic V### Fixed+- **An index whose metadata will not parse is refused instead of silently+ reopened with an empty mapping**+ ([#202](https://github.com/xerj-org/xerj/issues/202)). `Index::open` treated+ "this file is not there" and "this file does not parse" as the same thing:+ `load_schema`/`load_settings` mapped ENOENT, EACCES, EIO and malformed JSON+ alike to one anonymous error, and the caller answered all of them with a+ fresh dynamic mapping. Measured on a field deliberately mapped `keyword`:+ after `schema.json` was truncated to half its bytes the index still opened+ `Ok` with `field_count = 0`, the field came back `None`, and one further+ document re-inferred it as `long` — a mapping silently replaced by a+ different one, with nothing in any response saying so. Absent stays absent+ (indices predating create-time schema persistence legitimately have no+ `schema.json`); present-but-unparseable now fails the open with an error+ naming the file. `es_mapping.json` — the full-fidelity mapping behind+ `GET /_mapping` — was logged-and-ignored on a parse failure and now fails the+ index too, on the boot scan, on snapshot restore and on a retry.++ **Visible on upgrade:** a node whose data dir already holds a corrupt sidecar+ now boots **red** with that index unserved, where it previously came up green+ with an empty mapping. It joins the failed set+ [#206](https://github.com/xerj-org/xerj/issues/206) introduced, so every+ surface that set feeds already reports it — measured on a node holding two+ user indices, `victim` with a truncated `schema.json`:++ ```+ GET /_cluster/health -> red, unassigned_primary_shards: 1+ GET /_cluster/health?level=indices+ -> victim red, unassigned_info.details = the+ absolute path of schema.json and the parse error+ GET /_cat/indices -> "red open victim <uuid> 1 0 0 0 0b 0b 0b"+ GET /_cluster/indices/failed -> the reason, plus the retry and delete calls+ PUT /victim, POST /victim/_doc, POST /victim/_search+ -> 503 no_shard_available_action_exception+ carrying that same reason+ GET /health/ready -> 200 "ready (degraded): 1 of 2 indices+ serving, 1 failed to open; see GET+ /_cluster/indices/failed"+ POST /healthy/_search -> 200+ ```++ The readiness counts above are the two-index test router's. A running node+ also holds its internal `.xerj_*` indices, so the same condition on the shipped+ binary reads `ready (degraded): 15 of 16 indices serving, 1 failed to open` —+ the 200 and its meaning are unchanged, only the totals move with what else the+ node holds.++ Recovery is the three doors #206 added. Two were measured end to end on the+ shipped binary: repair the file and+ `POST /_cluster/indices/failed/{index}/_retry` (503 while it is still torn,+ `200 {"reopened": true}` once it is not, health back to green), and+ `DELETE /{index}` (200, directory removed, health back to green). The third —+ restore the index from a snapshot — is the path this change touches (a+ successful restore now clears the recorded failure, which it has to or health+ would stay red after the repair worked); it is covered by an engine-level+ test rather than measured over HTTP. The node stays in kubelet rotation as+ long as any index is still serving.++- **Concurrent sidecar writes can no longer manufacture the torn file the reader+ now refuses.** `write_file_atomic` staged every write in+ `path.with_extension("tmp")` — one shared name for all writers of that file —+ so two concurrent writers of one sidecar (`PUT /{index}/_settings` racing+ another settings update, two API-key mints for `api_keys.json`) both opened it+ `O_TRUNC`, interleaved their bytes, and each renamed it into place. The rename+ is atomic; the content being renamed was not one writer's. Measured with the+ old shared name, 4 threads × two different-length settings bodies × 200+ rounds, over four runs: **86–294 of 800 writes failed with ENOENT** (the loser+ renaming a file the winner had already moved) and, with those errors swallowed+ as the callers did, **1–16 of 200 rounds left an unparseable `settings.json`**.+ The counts are race-dependent and vary with machine load; what does not vary is+ that both are non-zero on every run with the shared name and **0 and 0** on+ every run with a unique staging name. Each write now stages+ in its own sibling file (`<file>.tmp.<pid>.<seq>`) in the target's directory+ and removes its own debris on failure — which for `api_keys.json` is key+ material. `update_settings` also writes `settings.json` through+ `write_file_atomic` rather than a plain `fs::write`; it was the last+ non-atomic sidecar writer left.++ - **`index` on the mapping is now honoured instead of silently ignored**+ ([#204](https://github.com/xerj-org/xerj/issues/204)). `"index": false` was+ accepted by `PUT /{index}`, echoed back verbatim by `GET /{index}/_mapping`,+ and then had no effect at all: the field kept a full inverted index and+ `match`, `term`, `match_phrase`, `prefix` and `wildcard` against it all+ returned the document, where Elasticsearch answers 400. It is the sibling of+ the `doc_values` fix in rc.12 and follows its shape.++ The line is drawn where ES draws it. Since 8.1, `"index": false` on a+ keyword / numeric / date / boolean / ip field keeps the doc-values column and+ stays queryable — `MappedFieldType.isSearchable()` is "has postings **or** has+ doc values" — so those queries keep working here, unchanged. Only a field with+ neither (a `text` field, or anything with an explicit `"doc_values": false`)+ is unsearchable, and a query naming one is now rejected with ES's own+ sentence, `Cannot search on field [f] since it is not indexed nor has doc+ values.`, as a 400 `search_phase_execution_exception` /+ `query_shard_exception`. The check lives in one place — `search_inner` — and+ these surfaces were each measured reporting the rejection rather than+ absorbing it, including the three that were swallowing it: `_search`,+ `_count` on all four selectors (single index, `logs-*`, a comma list and the+ cluster-wide `POST /_count`), `_msearch`, `_msearch/template`, `_explain`,+ `_delete_by_query` and `_rank_eval`. `_explain` answers the 400 instead of a+ confident `"matched": false` for a query it never ran; `_msearch` and+ `_msearch/template` render it as a per-response 400 envelope with `type` and+ `root_cause`, leaving the sibling sub-requests in the batch untouched; and+ `_rank_eval` records the refused request under `failures` instead of dropping+ it from `details` *and* `failures`. It still publishes a `metric_score`, and+ that number is still the mean over the requests that actually ran — which is+ ES's behaviour too — but the batch no longer shrinks silently underneath it:+ a two-request batch in which one is refused now answers `details: {good}`,+ `failures: {bad}`, `metric_score: 1.0` (measured), so a relevance gate reading+ a clean score can see what did not contribute to it.++ A multi-index `_count` follows ES's broadcast rule rather than failing+ outright: the failure status is returned only when **no** index answered+ (`RestStatus.status`, semantics only), so `/t/_count` and a `logs-*` whose+ indices all carry the offending mapping both 400 exactly as `_search` does,+ while a mixed selector returns 200 with the partial count and the refusal+ visible as `_shards.failed: 1` plus a `_shards.failures` entry carrying the+ `query_shard_exception`. What it will not do any more is what it did before:+ report `count: 0` with `"successful": 2, "failed": 0`.++ `exists` is unaffected and still returns zero hits rather than an error, which+ is also what ES does.++ The multi-field query types follow ES's own split rather than a blanket rule.+ An explicitly *named* field is rejected like any other named field —+ `multi_match` / `simple_query_string` / `query_string` with+ `"fields": ["note"]`, and `query_string` with `"default_field": "note"` —+ while a *wildcard* spec such as `"fields": ["*"]` is never an error, because+ ES expands a pattern over the searchable fields and silently drops the rest+ (`QueryParserHelper.resolveMappingField`). Before this, the same user intent+ got two different answers: the `simple_query_string` form was rejected (the+ parser lowers it to a `match`) while the `multi_match` form returned the+ document through the unsearchable field.++ Reaching the `query_string` half of that meant fixing a second+ accepted-and-ignored key in the same family: **`query_string`'s `fields`+ array was never read by the parser**, so `{"query":"x","fields":["title"]}`+ searched every field, and — once `index: false` became a real rejection —+ disagreed with `{"default_field":"title"}`, which is the same request written+ the other way. `fields` now selects the targets for a clause that named no+ field of its own (a `dis_max` over one leaf per field when there is more than+ one, `^boost` honoured) — the same job `simple_query_string`'s `fields` list+ was already doing. A clause that does name its own field keeps it, as in ES.++ The field is dropped from the full-text index at flush and merge only where+ the stored-doc fallback is *equivalent* — a non-indexed `text` field. An+ exact-typed field that kept its doc values keeps its whole-value postings,+ because the fallback scan splits on non-alphanumerics and would start matching+ `192.168.0.1` against `192.168.0.2`. So no byte-saving claim is made for this+ change: for those types the footprint the option implies is knowingly forgone+ rather than bought with wrong answers.++ Known gaps, measured and left open rather than claimed shut. **Aggregations+ and sort do not inherit the check**: only the `query` clause is walked, so+ `{"size":0,"aggs":{"a":{"terms":{"field":"note"}}}}` still answers 200 with a+ bucket built from `_source`, and `{"sort":[{"note":"asc"}]}` still answers 200.+ ES rejects those too, but for an unrelated reason and with an unrelated+ sentence — `Fielddata is disabled on [f] in [i]…`, which it raises for *any*+ `text` field whether or not `index: false` was declared — so reusing this+ error there would misreport a wider divergence as this one. **The field-less+ arms of the stored-document scan are schema-free**, walking every `_source`+ key, so a token living only in an unsearchable field can still match when+ **no** field is named: `query_string {"query":"…"}` and `more_like_this` with+ no `fields` both still return the document. (Their *named* forms are+ rejected — `more_like_this` with `fields` lowers to a `bool.should` of+ `match` at parse time and inherits the check.) **A wildcard `fields` spec+ reaches that same field-less arm**: `simple_query_string` / `query_string`+ with `"fields": ["*"]` lowers to the `"*"` placeholder and is answered by the+ schema-free scan, so it can still match through an unsearchable field. It is+ never an *error*, which is ES's rule and deliberate — but it is not "answered+ over the searchable fields" either, and that is a pre-existing property of+ wildcard expansion, identical on `main`. (`multi_match` with a pattern is+ different: it is answered by the FTS projection, which does apply+ `isSearchable()`, and finds nothing in an unsearchable field.) **The opaque+ `query_string` fallback still ignores a multi-field `fields` list**: a query+ string the parser declines to lower keeps the whole string for the FTS path,+ where a one-element `fields` is carried across as `default_field` and a+ longer list has nowhere to go. And **`_validate/query` never opens the+ index** — it answers from the parse alone, so it reports `{"valid": true}`+ for a body `_search` refuses. That too is unchanged from `main`, but it now+ disagrees with `_search`, so it is written down rather than left to be+ discovered. Every one of these gaps is pinned by an assertion in+ `index_false_is_honoured::documented_gaps_are_still_open_and_still_documented`,+ so closing one fails the test that says it is open.++ ### Added — incremental `--no-graph` corpus reconciliation++ - **`xerj autoindex --no-graph` now reconciles a changed folder instead of+ re-deriving it.** A `--no-graph` run commits a durable *corpus generation*: a+ manifest of content groups (stable group identity, content digest and byte+ length, canonical path plus aliases, dataset assignment, validated output+ counts) plus a sealed source snapshot of the prepared records. A later run+ projects the current inventory onto the committed manifest and publishes only+ the difference — additions, content changes, deletions, renames, junk+ transitions and duplicate-alias moves all converge, and a no-op re-run issues+ no data bulk and appends no new generation. A run interrupted mid-generation+ replays from its own sealed snapshot, so the result never depends on whether+ the source tree changed after the crash. Dataset and mapping identity is+ frozen at generation 1: a file that would need a *new* dataset or a mapping+ change is refused before any remote mutation rather than silently widening+ the schema.++ Scope, plainly: only `--no-graph`. Graph-enabled runs are unchanged, and each+ changed generation still copies and prepares the full corpus (O(N) staging) —+ the win is in what gets published and verified, not yet in what gets read.+ `--snapshot-max-gb` (default 64) caps the logical staged payload; it is a+ payload budget, not a disk-space or peak-memory guarantee.++ Original work by Leonid Bugaev (@buger).++ - **Junk keeps the contract it always had on the generated path: recorded,+ never fatal.** A file that cannot be read or recognised (`plan.junk_files`)+ and a record that no dataset assignment accepts (`stats.junk`) both used to+ abort a `--no-graph` run outright — the first with+ `plan has no assignment for <file>`, the second with+ `durable preparation of <file> produced N junk records`. A single zero-byte+ file was enough to make a whole folder unindexable. Both are now counted+ instead: the sealed prepared artifact carries its junk-record count, the+ manifest group carries it into the generation, and the catalog's per-file+ `junk` and run-level `junk_records_total` report it instead of a hardcoded+ zero. Such a run exits **3** ("completed with junk"), the same signal the+ legacy path publishes — the generated path previously returned a flat `0`+ and lost it.++ - **`--dry-run` is honoured on an already-generated state directory.** It was+ evaluated only after the pending-replay and reconcile branches had already+ published and committed, so on any state directory past generation 1 the flag+ was accepted, silently ignored, and the destination mutated. It is now decided+ before either branch: it prints the plan a real run would act on — the+ projected reconcile plan, or the sealed plan of a pending generation — and+ returns without opening the journal for write, without snapshot GC, and+ without a single bulk request.++ ### Changed — `autoindex --fresh` is refused on a durable generation++ - **`--fresh` no longer silently destroys a committed corpus generation.**+ `--fresh` deletes the resume journal, and the snapshot GC that follows every+ journal open then sees an empty protected set and removes every sealed+ snapshot — so on a generated state directory `--fresh` would discard the+ committed manifest, the pending replay evidence, and the alias/path/+ stale-record knowledge, while cleaning nothing at the destination. It is now+ refused up front, naming the generation that blocks it, and pointing at the+ plain re-run (which reconciles the change) or at an isolated rebuild with a+ new `--state-dir` and `--prefix`.++ **Unchanged for everyone else.** On a legacy (non-generated) journal —+ including every graph-enabled corpus and anything `xerj brain` writes —+ `--fresh` behaves exactly as before: it ignores the journal and restarts,+ which is what `xerj brain`'s documented self-heal for a wiped data directory+ depends on.++ ### Migration — pre-generation `--no-graph` state directories must be rebuilt++ - **A `--no-graph` state directory written before this release cannot be+ adopted as generation zero, and the first `--no-graph` run against it will+ refuse with a followable rebuild command.** This is a deliberate, versioned+ format boundary (`sync::GENERATION_FORMAT_VERSION = 1`), not a validation+ failure: a pre-generation resume plan records no stable group identity, no+ content byte length and no validated per-group output counts, so no amount of+ evidence in it could reconstruct a manifest group. The refusal prints the+ exact `xerj autoindex` argv for an isolated rebuild into a new `--state-dir`+ and `--prefix`; the old target and the shared `autoindex-catalog` are left+ alone and require explicit, validated cleanup once the new target is+ verified. Nothing is migrated in place and no destination data is touched by+ the refusal. Graph-enabled state directories are not affected.+## [1.0.0-rc.14] - 2026-08-10### Changed