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.

Merge remote-tracking branch 'origin/main' into unblock-258-local

xerj-org483efa3a8c93
diff --cc CHANGELOG.md
index 060973e70,9160e83f7..b0671888b
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@@ -7,140 -7,194 +7,328 @@@ and this project adheres to [Semantic V
## [Unreleased]
+### Changed
+
+- **BREAKING — `PUT /{index}` now refuses an `analysis` block XERJ cannot
+ honour, instead of accepting it and analysing differently**
+ ([#204](https://github.com/xerj-org/xerj/issues/204)).
+ `AnalyzerRegistry::apply_settings` is total by design (it also runs when an
+ existing index is opened, where a hard failure would brick it), so an
+ unresolvable tokenizer silently became `standard` and an unresolvable token
+ filter was dropped — the index was created, `GET /_settings` echoed the block
+ back, and the field was analysed in a way nobody asked for. Index creation
+ now validates the block and answers `400` with the exact constructs it cannot
+ build. `PUT /{index}/_settings` with an `analysis` block is likewise refused
+ (it only ever changed what `GET /_settings` echoed; the registry is built
+ once, at create/open, and there is no rebuild path — Elasticsearch also
+ refuses analysis updates on an open index).
+
+ **This rejects settings blocks that XERJ used to accept with a `200`, and the
+ ES-YAML conformance suite does not cover them — CI being green is not
+ evidence that your index still creates.** What is honoured:
+
+ | | honoured (still `200`) |
+ |---|---|
+ | `analysis.filter.*.type` | `synonym`, `length`, `shingle`, `asciifolding` |
+ | `analysis.tokenizer.*.type` | `ngram`, `edge_ngram`, `pattern` |
+ | `analysis.analyzer.*.type` (non-custom) | any name the built-in registry resolves — measured: `standard`, `english`, `whitespace`, `keyword` |
+ | `analysis.char_filter` | nothing — the char-filter slot is hard-coded empty |
+ | `analysis.normalizer` | nothing — never built |
+
+ Anything else in those positions is now a `400`. There is one important
+ exception to read first: XERJ resolves a declared filter or tokenizer by
+ **name**, not by `type`, so a declaration whose *name* is a built-in is still
+ honoured whatever its type says. Measured, all still `200`:
+ `{"english_stop": {"type": "stop", "stopwords": "_english_"}}`,
+ `{"lowercase": {"type": "lowercase"}}`,
+ `{"stemmer"|"english_stemmer": {"type": "stemmer", "language": "english"}}`
+ — the canonical Elasticsearch-docs `rebuilt_english` block among them, which
+ has a regression test pinning it. Naming a built-in analyzer on a field
+ (`"analyzer": "english"`) needs no `analysis` block at all and is unaffected.
+
+ What now fails is a declaration under a name that does NOT resolve — which is
+ the usual ES habit of naming filters after what they do in *your* index.
+ Measured blocks that returned `200` in rc.14 and return `400` from this
+ release:
+
+ - a `keyword` field's `normalizer` (any);
+ - a `char_filter` (any, including `html_strip` and `mapping`), declared
+ either under `analysis.char_filter` or as an analyzer's `char_filter`;
+ - a custom-named token filter whose `type` is `lowercase`, `stop`, `stemmer`,
+ `snowball`, `kstem`, `porter_stem`, `ngram`, `edge_ngram`,
+ `word_delimiter_graph`, `trim`, `unique`, `elision`, `decimal_digit`,
+ `apostrophe`, `limit`, `truncate`, `pattern_replace`, `keyword_marker`,
+ `uppercase` or `reverse` — e.g. `{"my_lowercase": {"type": "lowercase"}}`,
+ which never lowercased anything, because the analyzer referencing
+ `my_lowercase` found no such filter and dropped it;
+ - a custom-named tokenizer whose `type` is `standard`, `whitespace`,
+ `keyword`, `classic`, `uax_url_email`, `path_hierarchy`, `char_group`,
+ `letter`, `lowercase` or `simple_pattern`;
+ - an analyzer whose non-custom `type` is `simple`, `stop`, `pattern`,
+ `fingerprint`, or a language other than `english`;
+ - a `synonym` filter whose `synonyms` is a bare string rather than an array
+ (it built a filter with zero rules).
+
+ **Upgrading:** there is no opt-out flag. Either remove the analysis block and
+ name a built-in analyzer on the field (`"analyzer": "english"`), or keep only
+ the constructs in the table. The `400` names every offending construct in one
+ response, so one round-trip is enough to see the whole list. **Two paths are
+ not covered and still accept these blocks silently: an index template's
+ `template.settings.analysis` is dropped wholesale before the gate ever sees
+ it, and option-level divergence inside a supported type (`synonyms_path`,
+ `length.min`, `asciifolding.preserve_original`) is not checked at all.**
+
+### Fixed
+
+- **`200 acknowledged` on an ingest pipeline now means "we will run this", and
+ every write path enforces it**
+ ([#204](https://github.com/xerj-org/xerj/issues/204)).
+ `PUT /_ingest/pipeline/{id}` used to store the raw body first and only
+ warn-log a compile failure, so a pipeline that could never run was
+ acknowledged and echoed back by `GET`. It now compiles first, with three
+ outcomes: compiled → stored and acknowledged; a processor config we refuse →
+ `400`; a processor or option this build cannot honour → accepted (as
+ Elasticsearch does) but recorded as **unrunnable**, so the write refuses
+ rather than storing an untransformed document.
+
+ Defects this surfaced, each of which answered `200`/`201` and did something
+ smaller than asked: **every** ES `rename` processor failed to compile (the
+ handler emitted `{from, to}`, the plugin requires `{mappings: {…}}`) and
+ renamed nothing; ES `append` was executed as `set`, replacing the field
+ instead of extending it, and disagreeing with `_simulate`, which implemented
+ a real append; `set.override` defaulted to `false` where Elasticsearch
+ defaults it to `true`; an unknown `pii_redaction` type built an empty pattern
+ set and redacted nothing; an unknown `grok` pattern name silently became the
+ catch-all; an unknown `convert` target left the field unconverted per
+ document; array-typed keys given as a bare string were dropped and the stage
+ behaved as if unconfigured; and `DELETE /_ingest/pipeline/{id}` removed the
+ definition while leaving the compiled pipeline live under the same name.
+ ES `convert` `long`/`double` now map to XERJ's equivalent `integer`/`float`
+ rather than being refused.
+
+ Two more of the same, at the definition's own edges: a **pipeline-level**
+ `on_failure` block (the top-level body key, not the processor-level one) was
+ accepted, echoed by `GET`, and never run — the pipeline is now recorded
+ unrunnable, exactly as its processor-level twin already was; and `set` with
+ Elasticsearch's `copy_from` is reported as an unsupported *option* (accepted
+ at `PUT`, refused at the write) rather than as `mapper_parsing_exception:
+ missing value`, which told the caller their valid ES pipeline was malformed.
+
+ **The refusal now covers every ingest path, not only `PUT /{index}/_doc`.**
+ `POST /_bulk?pipeline=`, `index.default_pipeline` under `_bulk`,
+ `_reindex` `dest.pipeline` and `POST /{index}/_update_by_query?pipeline=`
+ previously read the instruction and dropped it — a redaction pipeline that
+ the single-document endpoint refused was ignored in bulk, and the document
+ was stored verbatim under `errors: false`. All four now run the pipeline, and
+ refuse when it cannot run. `_reindex` and `_update_by_query` validate the
+ name before touching a single document, so a bad pipeline fails the request
+ instead of half of it.
+
+ Two related honesty fixes on the same paths: `_clone` / `_shrink` / `_split`
+ copied at most 10,000 documents and swallowed every per-document write error
+ before answering `{"acknowledged": true}` (now full keyset paging, and any
+ failed write — or a failed source flush — fails the request); and a failed
+ `_bulk` item no longer reports `"result": "deleted"` alongside its own
+ `status: 400`, which claimed a deletion that never happened.
+
+ **Known gaps, stated rather than closed:** `_simulate` interprets the stored
+ ES body directly and covers processors the compiled path does not, so a
+ pipeline recorded as unrunnable can still show a transformation under
+ `_simulate` that ingest refuses to perform; `GET /_ingest/pipeline/{id}`
+ returns the ES body with no runnability signal, so an operator only learns at
+ write time; a write addressed to an **alias** does not pick up the backing
+ index's `default_pipeline`; and `_update_by_query` reports a `drop`
+ processor as a per-document failure, because it updates in place and has no
+ delete path.
+
+ ## [1.0.0-rc.14] - 2026-08-10
+
+ ### Changed
+
+ - **One documented core and memory policy, and the worker knobs are live**
+ ([#240](https://github.com/xerj-org/xerj/issues/240)). XERJ had no single
+ answer to "how much of this machine may I take?", and the scattered answers it
+ did have disagreed with each other — and, on Darwin, with the OS.
+ `engine.flush_workers`, `engine.merge_workers` and `engine.search_workers`
+ were documented but inert; they now drive real pool widths, and a value of `0`
+ refuses startup instead of being silently reinterpreted. `--bulk-mb` above 24
+ and `--workers 0` are likewise refused rather than clamped, so a request the
+ engine will not honour fails loudly. Only hand-written configs are affected:
+ the shipped `xerj.default.toml` has no `[engine]` section.
+
+ - **One 16 MiB file no longer costs 65 GB of RSS**
+ ([#239](https://github.com/xerj-org/xerj/issues/239)). `split_sections` was
+ quadratic in both time and memory: a 16 MiB text file with no blank line
+ needed **65.6 GB of peak RSS and 16.3 s** to produce 16.8 MB of sections.
+ Now linear — the same input takes **8.3 ms and 35 MB**.
+
+ - **BREAKING — `server.bind_address` now defaults to `127.0.0.1`, and a
+ cleartext node refuses to publish itself to the network**
+ ([#228](https://github.com/xerj-org/xerj/issues/228)). The old default was
+ `0.0.0.0` while TLS is off by default, so an out-of-the-box node accepted its
+ admin API key over plain HTTP on every interface the host had — verified on a
+ stock boot, where `curl -H "Authorization: ApiKey …" http://<lan-ip>:9200/…`
+ answered `200` and the same URL over `https` had no listener to hand shake
+ with. Auth being on did not help: the credential *is* the thing on the wire.
+
+ A fresh node is now reachable from its own host and nowhere else. Exposing it
+ is two statements, not zero: set `server.bind_address` (or `--bind` /
+ `XERJ_BIND_ADDRESS`), and — while `tls.enabled = false` — also set
+ `server.allow_insecure_network_bind = true` (env
+ `XERJ_ALLOW_INSECURE_NETWORK_BIND`). Without the second, startup exits
+ non-zero before the data directory is created or a first-run admin key is
+ minted. `--insecure` does not evade it; it clears `tls.enabled`, which is
+ exactly what the check keys on. Same fail-closed shape as
+ [#229](https://github.com/xerj-org/xerj/issues/229), whose TLS-on gRPC check
+ is untouched and cannot be relaxed by this opt-out.
+
+ **Upgrading:** a deployment that relied on the old default becomes
+ unreachable from other hosts until it sets both; one that already wrote
+ `bind_address = "0.0.0.0"` without TLS now fails to start with a message
+ naming the setting that unblocks it. The shipped Docker image, compose file
+ and Helm chart set both, because a container's network namespace is the
+ boundary and its published port is where TLS belongs.
+
+ Two documentation claims that were false as written are now true: the CLI and
+ security pages both said `--insecure` "refuses to run with a non-loopback
+ bind", and it did not — a `--insecure` node on `0.0.0.0` accepted an
+ unauthenticated `PUT /leak/_doc/1` from the LAN (`201`). The startup banner
+ also prints the bind address on every listener line, so a loopback node and a
+ world-facing one no longer look identical.
+
+ A `bind_address` that is not an IP literal is rejected first, ahead of both
+ exposure checks, with the fault it actually has. Host names have never been
+ resolved — the pre-#228 code parsed `"{bind}:{port}"` as a socket address and
+ failed on them too — but the exposure predicates fail closed on anything they
+ cannot parse, so without that ordering `bind_address = "localhost"` was
+ refused with a message asserting that localhost "is not loopback" and would
+ "serve plain HTTP on a network-reachable interface", and pointed at an opt-out
+ that fixed nothing: setting it let the boot run on to the bind and fail there
+ instead, after the data directory, the `.xerj_*` system indices, the master
+ key and a printed first-run `admin.key` already existed.
+
+ ### Security
+
+ - **API key secrets are no longer stored in the clear**
+ ([#201](https://github.com/xerj-org/xerj/issues/201)). `api_keys.json` held
+ the secret verbatim. 0600 plus atomic rename is right for a secret a *process*
+ owns, but a file has more readers than a process: a backup, a snapshot, a
+ container layer, a support bundle, a decommissioned disk. Secrets are now
+ stored as a salted SHA-256 (`$ssha256$<salt>$<digest>`) and compared in
+ constant time, with existing plaintext records migrated on load. The fast hash
+ is deliberate: the secret is two v4 UUIDs — 244 bits of CSPRNG output, never
+ human-chosen — so offline guessing is out of reach whatever the hash costs,
+ while this comparison runs on *every authenticated request*, where an Argon2id
+ would add tens of milliseconds per request and hand out a free CPU-exhaustion
+ DoS. The same release makes `_security/_authenticate` report the key's real
+ identity instead of a hardcoded `superuser`, and gives the audit chain durable
+ storage.
+
+ - **The node refuses to start when TLS is on but gRPC would answer in cleartext
+ off-loopback** ([#229](https://github.com/xerj-org/xerj/issues/229)).
+ `tls.enabled = true` encrypted two of the three data-plane listeners; the
+ third never participated, because the gRPC server is built without tonic's
+ `tls` feature. Nothing surfaced it — gRPC clients connected and worked
+ identically either way — so an operator who enabled TLS and bound a network
+ interface got no error, no failed handshake and no symptom, while API keys and
+ document bodies crossed the network in the clear. Auth was never the gap;
+ confidentiality was. Boot now fails closed unless
+ `tls.allow_insecure_grpc_h2c` says otherwise.
+
+ ### Fixed
+
+ - **`multi_match` returns the same hit set before and after `_flush`**
+ ([#218](https://github.com/xerj-org/xerj/issues/218)). The memtable and
+ segment paths disagreed on multi-token semantics, so flushing an index could
+ change which documents a query matched — verified live on a one-document
+ index where an OR query returned 0 hits before `_flush` and 1 after, with ES
+ returning 1 throughout.
+
+ - **Dynamic string fields get Elasticsearch's default `.keyword` multi-field**
+ ([#209](https://github.com/xerj-org/xerj/issues/209)). Dynamic mapping
+ inferred every string as bare `text`, so `GET _mapping` never showed a
+ `.keyword` sub-field and `_field_caps` never listed one. Anyone arriving from
+ Elasticsearch — or any tool that reads `_field_caps` for field discovery,
+ Kibana included — could not see that `category.keyword` existed.
+
+ - **`min_score` is honoured at `size:0`, and an external scalar N keeps its
+ ghosts** ([#193](https://github.com/xerj-org/xerj/issues/193)). A
+ `size:0 + min_score` body never materialised a hit, so the threshold had
+ nothing to filter and `hits.total` reported the raw match count — measured at
+ **65** where the same query at `size:100` counted **5**. The tie-break
+ comparator item from that issue is deliberately not included here; it belongs
+ with [#191](https://github.com/xerj-org/xerj/issues/191).
+
+ - **Index blocks can be removed, `read_only_allow_delete` means what its name
+ says, and a blocked write answers 403 rather than 500.** Three compounding
+ defects: `PUT /_settings` wrote only the display-side map while enforcement
+ read the per-index `settings.json`, so a block was acknowledged, invisible to
+ `GET /_settings`, and — with `_block` registered PUT-only — removable only by
+ restarting with a hand-edited file. The one block that fires automatically did
+ the inverse of its name, and clients hitting any of it were told the server
+ had faulted.
+
+ - **`llms.txt` no longer tells agents six things the binary does not do.** The
+ "Running an index for a human" section is executed, not just read: an agent
+ follows it literally and then reports the result to its user. Corrected: the
+ job-size line is not the first line printed; `--dry-run` does not write
+ *nothing* (it creates and locks the state dir and appends a journal record);
+ a dry run reuses a frozen plan instead of re-costing the job, so it is not a
+ floor for the real run; exit `1` is the catch-all for every error, not
+ "endpoint unreachable"; `status` needs the same explicit `--state-dir` the run
+ used; and `--workers`/`--pdf-workers` bound the client-side extractor, not the
+ server (with `--pdf-workers` capped to 1–4).
+
+ - **A failed index can now be inspected, deleted and retried without stopping
+ the server** ([#206](https://github.com/xerj-org/xerj/issues/206)). An index
+ directory that refused to open at boot was recorded in a map that only
+ `Engine::health` ever read. Live-reproduced with a corrupt `snapshot.json`:
+ it was absent from `_cat/indices` and `_cluster/state`, `DELETE /{index}`
+ answered `404 index_not_found` and left the bytes on disk, and the only
+ recovery was to stop the server and edit the data directory by hand. A
+ failed index is now a real state: listed as `red` in `_cat/indices`, present
+ in `_cluster/state` as an `UNASSIGNED` primary with `ALLOCATION_FAILED` and
+ the verbatim open error, enumerated with its reason by
+ `GET /_cluster/indices/failed`, reopenable via
+ `POST /_cluster/indices/failed/{name}/_retry` once the cause is fixed, and
+ deletable through the ordinary `DELETE /{index}`. Searches, writes and
+ creates against it return `503 no_shard_available_action_exception` carrying
+ the reason instead of a `404` that claimed it did not exist, while the
+ metadata surfaces — `GET /{index}`, `HEAD /{index}` (the `indices.exists()`
+ every ES client calls), `_mapping`, `_settings`, `_cat/indices` — report it
+ as an index that exists, the way ES answers those from cluster metadata
+ rather than from a shard. Before this, `HEAD` said the name was free and the
+ following `PUT` said it was unavailable.
+
+ Two related defects in the same report are fixed with it. **Readiness no
+ longer hard-fails on a partly degraded node** — `/health/ready` returned
+ `503` for any red status, so one broken index pulled a pod holding 200
+ healthy ones out of service permanently; it now reports `200 ready
+ (degraded)` while the node can still serve something and `503` only when
+ every index it holds failed to open. And **`_cat/health` no longer prints a
+ hardcoded `green`** — the one health surface an existing ES dashboard points
+ at was the one that could not report a broken node; it and `_cluster/health`
+ now count an unopenable index as an unassigned primary, agreeing with
+ `/v1/health` and `/v1/cluster/health`.
+
+ Because `red` is now reachable on `_cluster/health` for the first time, the
+ two conditions that gate on it are consulted rather than assumed:
+ `wait_for_active_shards=all` and `wait_for_status=green|yellow` both answer
+ `408` with `timed_out: true` on a red node instead of `200 timed_out: false`.
+ `GET /_cluster/health?wait_for_status=green&timeout=30s` is the bootstrap gate
+ every docker healthcheck, CI wait loop and Kibana startup uses; a red node
+ used to sail straight through it. A green or yellow cluster is unaffected.
+
+ - **A `DELETE /{index}` that could not remove the bytes no longer strands the
+ index.** The open-index path pulled the handle out of the engine before
+ `remove_dir_all`, so a removal that failed (read-only mount, `EACCES`) freed
+ the name while the directory survived: no handle, no failed-index entry,
+ nothing on `_cat/indices`, and the next `DELETE` answered `404` — the same
+ dead end as [#206](https://github.com/xerj-org/xerj/issues/206), reached from
+ the other side. The handle is now restored on failure, so the index stays in
+ service and addressable and the operator can retry the delete once the cause
+ is fixed.
+
- **`autoindex` no longer leaves immortal catalog entries for skipped files**
([#238](https://github.com/xerj-org/xerj/issues/238)). A file added after the
resume plan was frozen is skipped and reported in the catalog — but that