8000 fix(api): fields/docvalue_fields pierce an explicit _source includes filter (#932) by xerj-org · Pull Request #991 · xerj-org/xerj · GitHub
[go: up one dir, main page]

Skip to content

fix(api): fields/docvalue_fields pierce an explicit _source includes filter (#932) - #991

Closed
xerj-org wants to merge 1 commit into
mainfrom
fix/issue-932-fields-source-includes
Closed

xerj-org wants to merge 1 commit into
mainfrom
fix/issue-932-fields-source-includes

Conversation

@xerj-org
Copy link
Copy Markdown
Owner

Problem

A fields clause was silently dropped from every hit whenever the same request carried an explicit _source includes list that did not contain the requested field. {"_source": ["title"], "fields": ["body"]} returned HTTP 200 with no fields block at all — for text and keyword fields alike — while the identical clause worked with no _source filter and with _source: false. Because an unresolvable fields entry is legally omitted, callers got the accepted-and-ignored class of failure (#204): a 200, no warning, nothing. This is the sibling of #310, which fixed the same symptom for the default _source projection; the explicit-includes path was not covered.

Root cause

The engine narrows hit.source for an explicit SourceFilter::Includes/Fields before the response layer runs (apply_source_filter, engine/crates/xerj-engine/src/index.rs), and the per-hit fields / docvalue_fields builders resolve every value out of that already-narrowed source (get_source_value_by_path(&h.source, …) in search_impl). The #310 pierce cannot fire here: it is keyed on body.source.is_none() and companion-gated, so any explicit _source clause — including the ?_source= and ?_source_includes= URL spellings promoted into body.source — kept the narrowed source and lost the named field.

Elasticsearch treats the two clauses as independent: fields reads the stored _source and parses/formats it via the mappings, while source filtering only selects "what fields of the source are returned" (docs/reference/elasticsearch/rest-apis/retrieve-selected-fields.md).

Fix

The #310 approach applied to the explicit-filter path, entirely inside search_impl in engine/crates/xerj-api/src/es_compat.rs — no engine change:

  • value_bearing_names is now comp 8000 uted for both projections (es_compat.rs:11266).
  • New source_filter_drops_a_name (es_compat.rs:6110) decides coverage by running the production projection (xerj_engine::filter_object, already pub) over probe documents in both spellings the fields builder resolves — the whole dotted path as a literal key, and the nested walk. A wildcarded name counts as dropped (conservative direction: emission re-applies the filter verbatim, so an unnecessary pierce costs only the _savings note, a missed one is the silent 200 of this issue).
  • pierce_explicit_source (es_compat.rs:11320): when the caller's own includes/excludes drop a value-bearing name, the search runs with SourceFilter::Enabled(true) — the same shape "_source": false already uses for exactly this resolution. Unlike fields API silently omits embedding companions under the new default _source (follow-up to #309) #310 it is not companion-gated: the dropped field is the caller's own, text or keyword alike. A filter that already covers every named field does not pierce at all, so those requests stay byte-identical, engine-side narrowing and _savings note included.
  • Emission site 1 (es_compat.rs:12503): the wire _source is re-narrowed with the caller's exact patterns after the sentinel strips and before the synthetic block — same filter_object, same input the engine would have filtered.
  • Emission site 3, the scroll snapshot (es_compat.rs:12251): re-narrowed before the scroll context is stored, preserving the collapse sentinels exactly as the engine's own Includes/Fields branches do (take → filter → reattach, collapse: an explicit _source.includes that omits the collapse sentinel drops the leader's inner_hits #651), so continuation pages neither leak the pierced field nor lose inner_hits.

Deliberate trade (same one #310's pierce makes, now pinned by a test): a pierced request loses its _savings note because Enabled(true) is not a measured engine shape; covered requests keep theirs. _msearch and _async_search render hits through their own minimal builders that never render a fields block at all, so this interplay does not exist there — a pre-existing, separate gap.

Evidence

New integration test engine/crates/xerj-api/tests/fields_pierce_explicit_source_includes.rs (6 tests, every assertion paired positive/negative):

  • FAIL-BEFORE (src fix stashed, tests only): 6/6 failed with the exact issue symptom — hits.hits.N.fields.body = null under _source: ["title"], and the would-be-pierced request still carried a _savings note (no pierce existed).
  • After the fix: 6/6 pass — the issue's five-row repro table (including the keyword cat row), the object spelling _source: {"includes": […]}, the URL spellings ?_source_includes=title and ?_source=title&fields=body, docvalue_fields, an excludes-only filter, scroll continuation pages, and the _savings-note oracle proving covered names do not pierce while pierced ones trade the note.
  • Full xerj-api crate suite: 638 passed / 0 failed (includes the existing gates fields_pierce_default_source, collapse_inner_hits_under_source_includes, savings_stat_is_honest, rerank_stage_http, and the scroll-suppression suites).
  • cargo clippy --profile ci-test -p xerj-api -- -D warnings: clean.
  • ES-YAML conformance suite against a private-port server (throwaway data dir) built from this branch: 1371 passed / 0 failed / 3 skipped — gate at 0 failed holds.

Fixes #932

…filter (#932)

A `fields` clause was silently dropped from every hit whenever the same
request carried an explicit `_source` includes list that did not contain the
requested field. `{"_source": ["title"], "fields": ["body"]}` returned HTTP
200 with no `fields` block at all — for text and keyword fields alike — while
the identical clause worked with no `_source` filter and with `_source: false`.

Root cause: the engine narrows `hit.source` for an explicit
SourceFilter::Includes/Fields BEFORE the response layer runs
(xerj-engine/src/index.rs apply_source_filter), and the per-hit `fields` /
`docvalue_fields` builders resolve every value out of that already-narrowed
source (es_compat.rs:12670+ get_source_value_by_path(&h.source, ...)). An
unresolvable `fields` entry is legally omitted, so the caller got the
accepted-and-ignored shape of #204: 200, no warning, nothing. The #310 pierce
covers only the DEFAULT projection — it is keyed on `body.source.is_none()`
and companion-gated, so any explicit `_source` clause (including the
`?_source=` / `?_source_includes=` URL spellings promoted into body.source)
never pierced.

Fix — the #310 approach applied to the explicit-filter path, entirely in
search_impl (no engine change):

- value_bearing_names is now computed for BOTH projections (es_compat.rs:11266).
- New source_filter_drops_a_name (es_compat.rs:6110) decides coverage by running
  the production projection (xerj_engine::filter_object, already pub) over
  probe documents in both spellings the fields builder resolves (whole dotted
  path as a literal key, and the nested walk); a wildcarded name counts as
  dropped (conservative — emission re-applies the filter verbatim, so an
  unnecessary pierce costs only the _savings note).
- pierce_explicit_source (es_compat.rs:11320): when the caller's own
  includes/excludes drop a value-bearing name, search runs with
  SourceFilter::Enabled(true) — the shape `_source: false` already uses for
  exactly this resolution. Not companion-gated: the dropped field is the
  caller's own. A filter that covers every named field does not pierce at all,
  so those requests stay byte-identical, engine-side narrowing and _savings
  note included.
- Emission site 1 (es_compat.rs:12503): the wire `_source` is re-narrowed with
  the caller's exact patterns after the sentinel strips, before the synthetic
  block — same filter_object, same input order the engine would have used.
- Emission site 3, the scroll snapshot (es_compat.rs:12251): re-narrowed before
  the context is stored, preserving the collapse sentinels exactly as the
  engine's own Includes/Fields branches do (take/filter/reattach, #651), so
  scroll continuation pages neither leak the pierced field nor lose inner_hits.

Known, deliberate trade: a PIERCED request loses its `_savings` note
(Enabled(true) is not a measured shape) — the same trade #310's pierce makes;
covered requests keep theirs. `_msearch` and `_async_search` render hits
through their own minimal builders that never render a `fields` block at all,
so the #932 interplay does not exist there (a pre-existing, separate gap).

Test evidence: new fields_pierce_explicit_source_includes.rs (6 tests) fails
6/6 on main with the exact issue symptom (fields Null under explicit includes;
savings note present on the pierced shape) and passes with this fix. Full
xerj-api suite 638 passed / 0 failed; cargo clippy -D warnings clean; ES-YAML
conformance 1371 passed / 0 failed / 3 skipped against a private-port server
built from this branch.
@xerj-org
Copy link
Copy Markdown
Owner Author

Merged to main as commit 6f149fc (merge of this branch, pushed directly because the merge API was wedged on a mergeability recompute). Verified: the branch head is an ancestor of main. All checks were green on head d3566f0. Issue #937 is closed by this.

Amakurai pushed a commit to Amakurai/xerj that referenced this pull request Sep 27, 2026
…, rc.78 queue

The 2026-09-21 review of this file was stale within hours: xerj-org#950 closed
19:33, xerj-org#941 19:38, xerj-org#1015 20:49 (all 2026-09-21), xerj-org#874 2026-09-22, and the
stage-1 gating trio xerj-org#937/xerj-org#938/xerj-org#939 closed the same evening — every one
recorded here as open or "under way". This pass re-checks every status
claim against live tracker state and rolls the file forward:

- Next release: the two "in flight" items (xerj-org#1015, xerj-org#950) are closed with
  fixes on main riding to rc.78 — the section now records what actually
  landed since the rc.77 tag (xerj-org#1009, xerj-org#1017, xerj-org#1018, xerj-org#1020, xerj-org#1021, xerj-org#1023,
  xerj-org#1025, xerj-org#1026, xerj-org#1033, xerj-org#1034) with PR links, including xerj-org#874's budget met
  at ~3x margin (206 -> 64 kB per idle index) and discussion xerj-org#1012's
  email-labelling measurement (1.000 templated tier / 0.625 at 0.902
  confidence on the hard tier — wrong-and-confident).
- Open defects: now xerj-org#1031 and xerj-org#1032 only; xerj-org#1015/xerj-org#950 removed (closed);
  trackers sentence corrected (xerj-org#941, xerj-org#874 closed — only xerj-org#298 remains by
  design).
- GA gate: "Close the CHANGELOG gap" marked closed 2026-09-26 (the
  rc.19-rc.70 backfill, PR xerj-org#1035); the record-complete note replaces the
  gap warning under "Shipping today".
- Zero-token: stage-1 gating trio recorded as fixed (xerj-org#991, xerj-org#995, xerj-org#979)
  with the old measured costs kept as the before-state; the xerj-org#940
  hash-seed spread annotated as a pre-fix measurement; stage-2 object
  storage marked done (xerj-org#965 wired in rc.77 — the old bullet contradicted
  this file's own "Shipping today" section); mail ingest "unreleased"
  corrected to "shipped in rc.75"; three stale "In flight:" labels on
  landed stage-1 items relabelled "History:".
- Mail-ingest memory line: xerj-org#948's runaway is fixed (xerj-org#1002) — the line
  now carries the fixed numbers and points at xerj-org#1032 for the residual.

Review line updated to 2026-09-26 (machine-checked format), scoped
honestly as a desk review. The milestones line is true again: rc.78
milestone created, all four open issues triaged (xerj-org#1030/xerj-org#1031/xerj-org#1032 ->
rc.78, xerj-org#298 -> GA).
neoneye pushed a commit to agent-memory-atlas-archive/xerj-org--xerj that referenced this pull request Oct 1, 2026
…FAIL), BM25 +0.0160/+0.0179 (PASS)

Motivation: issue xerj-org#1059 (rc.79) ships stemming-by-default via PR xerj-org#1070 and
binds a release gate: "NFCorpus zero-hit queries 25 -> <=10; BEIR BM25 >=
+0.01 over 0.657 SciFact / 0.302 NFCorpus." PR xerj-org#1070 measured nothing on the
BEIR arms (its motivation figure is the published docs/ZERO_TOKEN_DIRECTION.md
number); this is that measurement, on the release binary.

Method: release binary (version string "xerj v1.0.0-rc.78", main @ a179e1e,
which includes the xerj-org#1070 merge), one node on private port 9620, --insecure
--embed-mode lexical, throwaway data dir. BEIR SciFact + NFCorpus downloaded
from the URLs this README already uses (sha256s in run-meta.txt). Four
indexes on one node — {scifact,nfcorpus} x {std,stem} — differing only in the
create-time PUT: the stem arm declares settings.analysis.analyzer.default
{"type":"stemmer"} (the exact xerj-org#1070/xerj-org#991 surface, added to the load step by
load_stem.py exactly as xerj-org#1070's PR body anticipated); the std arm is the
plain rc.74 baseline path. eval_bm25.py replays eval.py's bm25 arm verbatim
(default-OR multi_match on title+text, size=100, graded nDCG@10) and writes
one raw line per test query.

Numbers (paired, same binary/node/datasets):
- std arm reproduces the rc.74 published row EXACTLY: SciFact 0.6572 (300 q),
  NFCorpus 0.3016 (323 q), zero-hit 25 — same 25 qids as the committed
  results/nfcorpus-lexical-gap.txt list.
- stem arm: SciFact 0.6732 (+0.0160), NFCorpus 0.3195 (+0.0179) — both clear
  +0.01: sub-gate B PASS.
- NFCorpus zero-hit 25 -> 15: sub-gate A FAIL (needed <=10). Stemming fixed
  exactly the 10 inflection-class queries (bagels, leeks, pineapples,
  turnips, whiting, deafness, antinutrients, airport scanners, canker sores,
  Alli); the remaining 15 are single words whose stem also occurs nowhere in
  the corpus (Fosamax, Zoloft, Mevacor, Splenda, eggnog, halibut, mesquite,
  okra, taro, amnesia, myelopathy, Peoria, Tufts, Yale, Czechoslovakia) —
  not bridgeable by any stemmer; recorded, not tuned.

Caveats recorded in gate-summary.txt: GET _settings does not echo the
analysis block and _analyze shows the standard token path even on the stem
arm, while search provably honours the declared default (std "bagels" 0
hits / stem 1 hit) — an observed display gap; latencies are wall-clock on a
shared 32-core sandbox and are not gate inputs.

File pointers: benchmarks/beir-hybrid/{load_stem.py,eval_bm25.py},
results/2026-09-30-stemming-1059/{gate-summary.txt,run-meta.txt,
<ds>-<arm>-bm25.tsv x4, <ds>-<arm>-summary.txt x4}, README.md stem-gate
section.
thomas-villani added a commit to thomas-villani/xerj that referenced this pull request Oct 9, 2026
…stop documenting them as working

The accepted-and-ignored class (xerj-org#204), continued on the convention `[merge]`
(xerj-org#207) and `[compression]` (xerj-org#318) set: thirteen more keys were accepted,
validated where they have a range, documented as working, and read by
nothing, with no startup warning.

- fts.default_analyzer: a text field uses its own analyzer, else the index's
  analysis.analyzer.default (xerj-org#991), else standard.
- vector.default_metric: similarity comes from the mapping, cosine when omitted.
- vector.hnsw_m / hnsw_ef_construction / hnsw_ef_search: the graph builds
  with fixed M=16 / ef_construction=200 (HnswParams::new); the beam width is
  the request's num_candidates.
- vector.default_quantization: only the `binary` refusal reads it.
- vector.max_dimensions: validated >= 1, never checked against anything.
- logs.retention_days / time_partition: xerj-logs is a dependency but nothing
  outside the crate uses it; no retention job runs, while four pages promised
  deletion after 90 days (one as the ILM replacement).
- indexing.turbo_batch_size / turbo_parallel / turbo_fast_analyzer: one batch
  per turbo request; parallel is a no-op since M5.9; fast_analyzer reaches an
  unused parameter.
- storage.local_cache_dir: dormant since xerj-org#965 per its rustdoc, but not in any
  dormant_overrides.

Each gets a DORMANT rustdoc note and a dormant_overrides() entry;
Config::dormant_overrides() collects every section and main.rs WARNs through
one loop (which previously covered merge and compression).

That loop also had to move. It ran inside load_config(), which main() calls
before init_tracing() so that [logging] governs the first line, so every
warning was emitted with no subscriber and dropped: xerj-org#207's merge warning and
xerj-org#318's compression warning have never printed. Measured on origin/main
(e260e07, release build): [merge] io_rate_mb_per_sec = 50 boots with zero
WARN lines. warn_dormant_overrides() now runs right after init_tracing() in
both entry points (the server and `xerj index`). No hard errors:
configs the project handed out must keep booting (xerj-org#207's rationale). Docs —
xerj.default.toml, config.html, the log-analytics playbook, migration-from-es,
analyzers, vectors, troubleshooting (which recommended the unread
default_quantization as a RAM fix), engine/README — now say not wired.

Evidence (agent-run): on v1.0.0-rc.89, fts.default_analyzer = "whitespace",
vector.default_metric = "euclidean" and vector.max_dimensions = 4 changed
nothing (match still hit "Foo-Bar"; kNN scored [1,0..] and [10,0..] both
1.0; 8-dim vectors indexed) with no warning. New test
every_dormant_setting_is_named_only_when_an_operator_sets_it: each key named
alone when set; nothing for the default or the shipped xerj.default.toml;
wired neighbours never named. cargo test -p xerj-common --lib: 195 passed. On this branch's release build
the same boot WARNs once per key set.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fields clause is silently dropped when _source includes omits the field (sibling of #310)

1 participant

0