8000 fix(xerj-engine): capture-scope every live version-map read in scans by xerj-org · Pull Request #1218 · xerj-org/xerj · GitHub
[go: up one dir, main page]

Skip to content

fix(xerj-engine): capture-scope every live version-map read in scans - #1218

Merged
xerj-org merged 1 commit into
mainfrom
fix/scan-liveness-capture-scope
Oct 7, 2026
Merged

xerj-org merged 1 commit into
mainfrom
fix/scan-liveness-capture-scope

Conversation

@xerj-org
@xerj-org xerj-org commented Oct 7, 2026
Copy link
Copy Markdown
Owner

What

Engine half of #1212 (the issue stays open until this is released and the standing rebuild verifies against it; do not auto-close).

A scan captures its world once (#1013): segment snapshot Arc + read lease + memtable snapshot, validated by a writer-free capture bracket. After the bracket the scan runs on frozen state, but three per-hit liveness checks kept reading the LIVE version map:

  • the main stored-doc walk's ver.segment_id != seg_id -> drop,
  • the residual (fused-bool remainder) walk's copy of that check,
  • the memtable ghost filter's != __memtable__ arm.

A merge publishing after the capture does snapshot.rcu + version_repoints.commit (entries point at the merged segment); a flush does the same off __memtable__. The frozen scan's hits from merged-away segments then fail the equality check and are silently dropped: short or empty page, HTTP 200, timed_out absent, self-healing on the next capture.

Live evidence (#1212)

  • read-back walk observed 56,441 of 58,568 catalog documents; minutes later an agg counted all 58,568 over the same data
  • a term query returned 0 hits and the zero-hit sampler answered unknown_value (it only fires on hits.is_empty())
  • 9 full pages then an empty page in one walk
  • idle-node clean walk; load correlation (merges run during finalize ingest)

Fix

A scan may only apply version entries that describe the world it captured. CapturedEntryVerdict classifies each live entry against the captured segment-id set (built once per search, O(segments)):

  • entry on __memtable__ or a captured segment -> describes the capture: deleted/superseded-within-capture => Invisible (drop, as before); live copy => Live (report seq/version, as before)
  • entry naming a real segment NOT in the captured set -> PostCapture: a publication after this capture, invisible in both directions (cannot supersede the hit; its seq/version are not the hit's)

Design cross-check (reference retrieval, xerj-code / xerj-search corpus): tantivy keeps the published SearcherInner immutable behind an ArcSwap swap (tantivy/src/reader/mod.rs:152-186), opens segment readers under META_LOCK (:192-201) and pins live generations' files via an Inventory (:203-212) - the snapshot is the only authority a scan consults. Our captured-set rule gives the same single-authority property without moving the whole version map into the snapshot.

Tests

  • captured_entry_verdict_table - full decision table of both verdict fns, no server needed
  • a_scan_parked_across_a_merge_publication_keeps_its_captured_hits - parks a real-field match query at its validated capture (new cfg(test) hook, mirroring the merge hooks), completes run_merge_once inside the window, asserts the entries repointed at the merged segment, releases; page still returns both hits
  • a_scan_parked_across_a_flush_publication_keeps_its_captured_memtable_hits - same park, flush publishes into the window; the captured memtable's copy survives

Both regression tests were verified to FAIL with the pre-fix dropping semantics restored (PostCapture => continue / the old equality arms) and PASS with this change.

Gates

  • cargo test -p xerj-engine --lib -> 740 passed / 0 failed
  • clippy --lib --tests clean
  • ES-YAML full suite, private port + throwaway data dir -> 1385 passed / 0 failed / 4 skipped (hard gate holds)

…1212)

Root cause. A scan captures its world once (#1013): the segment snapshot
Arc + its read lease, plus the memtable snapshot, validated by a
writer-free capture bracket (index.rs, "capture-bracket validation").
After the bracket the scan is supposed to run on immutable state — but
three per-hit liveness checks kept reading the LIVE version map:

- the main stored-doc walk's check (`ver.segment_id != seg_id` -> drop),
- the residual (fused-bool remainder) walk's copy of the same check,
- the memtable ghost filter's `!= __memtable__` arm.

A merge that publishes after the capture does snapshot.rcu (merged
segment replaces its inputs) and then version_repoints.commit (entries
point at the merged segment) — index_store.rs apply_merge_inner. A flush
does the same off __memtable__. The frozen scan's hits from merged-away
segments then fail the equality check and are silently `continue`d: the
page comes back short or empty, HTTP 200, `timed_out` absent,
self-healing on the next capture. The memtable arm has the identical
tear in the flush flavor.

Live evidence (issue #1212, standing xerj-search rebuild on rc.88):
- read-back walk observed 56,441 of 58,568 catalog documents; minutes
  later an agg counted all 58,568 over the same data;
- a term query returned 0 hits and the zero-hit sampler answered
  `unknown_value` because it only fires on hits.is_empty();
- 9 full pages then an empty page in one scroll-style walk;
- idle-node clean walk; load correlation (merges run during finalize).

Fix. The invariant the #1013 comment already claims for the snapshot is
now enforced for the version map too: a scan may only apply version
entries that describe the world it captured. New CapturedEntryVerdict
classifies each live entry against the captured segment-id set built
once per search (O(segments)):

- entry on __memtable__ or a captured segment -> describes the capture;
  deleted or superseded-within-capture => Invisible (drop, as before),
  live copy => Live (report its seq/version, as before);
- entry naming a real segment NOT in the captured set => PostCapture: a
  publication after this capture. Invisible in both directions — it
  cannot supersede the hit, and its seq_no/version are not the hit's.

Reference retrieval (xerj-code / xerj-search corpus, on-disk checkout):
tantivy keeps the published SearcherInner immutable behind an ArcSwap
swap (tantivy/src/reader/mod.rs:152-186), opens segment readers under
META_LOCK (:192-201) and pins live generations' files via an Inventory
(:203-212) — the snapshot is the only authority a scan consults; no
mutable per-doc map is read during collection. Our captured-set rule
gives the same single-authority property without repointing the whole
version map into the snapshot.

Tests (xerj-engine lib, 740 passed / 0 failed):
- captured_entry_verdict_table: the full decision table of both verdict
  fns, pinned without a server;
- a_scan_parked_across_a_merge_publication_keeps_its_captured_hits:
  parks a real-field match query at its validated capture (new
  cfg(test) hook test_pause_search_after_capture, mirroring the merge
  hooks), runs run_merge_once to completion inside the window, asserts
  the entries repointed at the merged segment, releases, and the page
  still returns both hits. Pre-fix semantics (PostCapture => drop)
  reproduce 0 hits;
- a_scan_parked_across_a_flush_publication_keeps_its_captured_memtable_hits:
  same park, flush publishes into the window; the captured memtable's
  copy survives. Pre-fix reproduces the live 0-hit term query.
  Both regression tests verified to FAIL with the pre-fix dropping
  semantics restored (PostCapture => continue / equality arms) and PASS
  with this change.

Gates: cargo test -p xerj-engine --lib -> 740/0; cargo clippy --lib
--tests clean; ES-YAML full suite on a private port + throwaway data
dir -> 1385 passed / 0 failed / 4 skipped (hard gate holds).

Known scope: this makes the scan self-consistent with its capture; it
does not change what a capture bracket admits (that is #1013's retry
logic, untouched). Hit seq/version are simply not reported when only a
later world knows them.

Files:
- engine/crates/xerj-engine/src/index.rs: CapturedEntryVerdict +
  entry_describes_capture/captured_verdict_for_{segment,memtable}_hit
  (near is_collection_capture_retry); captured_segment_ids + cfg(test)
  park hook after the capture-bracket check in the scan; three walk
  sites switched to the verdict; Index test hooks
  test_pause_search_after_capture/test_search_capture_parked.
@cla-bot cla-bot Bot added the cla-signed label Oct 7, 2026
@xerj-org
xerj-org merged commit 6b31b0a into main Oct 7, 2026
22 checks passed
neoneye pushed a commit to agent-memory-atlas-archive/xerj-org--xerj that referenced this pull request Oct 10, 2026
Workspace version + Cargo.lock (17 member entries). Release window:
xerj-org#1211, xerj-org#1213, xerj-org#1215, xerj-org#1216, xerj-org#1217, xerj-org#1218.
neoneye pushed a commit to agent-memory-atlas-archive/xerj-org--xerj that referenced this pull request Oct 10, 2026
Six window entries: xerj-org#1211 (blog guest post), xerj-org#1217 (kNN exact-scan
column ranking, its Unreleased entry carried verbatim under
Performance), xerj-org#1213/xerj-org#1216 (the two xerj-org#1212 client legs: explicit page
timeouts + observed-vs-projection re-walk), xerj-org#1215 (xerj-org#1214: corpus
index refuses an unresumable run over a recorded build), xerj-org#1218 (the
xerj-org#1212 engine half: capture-scoped version-map reads). Every xerj-org#1212
entry says the issue stays open — it closes only on a released,
verified standing rebuild. xerj-org#1220 cited as the follow-up the xerj-org#1217
review surfaced.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet
3AF6

Development

Successfully merging this pull request may close these issues.

1 participant

0