Repository navigation
fix(xerj-engine): capture-scope every live version-map read in scans - #1218
Merged
Merged
Conversation
…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.
This was referenced Oct 7, 2026
This was referenced Oct 7, 2026
Merged
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
ver.segment_id != seg_id-> drop,!= __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_outabsent, self-healing on the next capture.Live evidence (#1212)
unknown_value(it only fires onhits.is_empty())Fix
A scan may only apply version entries that describe the world it captured.
CapturedEntryVerdictclassifies each live entry against the captured segment-id set (built once per search, O(segments)):__memtable__or a captured segment -> describes the capture: deleted/superseded-within-capture =>Invisible(drop, as before); live copy =>Live(report seq/version, as before)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 neededa_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), completesrun_merge_onceinside the window, asserts the entries repointed at the merged segment, releases; page still returns both hitsa_scan_parked_across_a_flush_publication_keeps_its_captured_memtable_hits- same park, flush publishes into the window; the captured memtable's copy survivesBoth 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--lib --testsclean