Repository navigation
[Iterator Revalidation][MOD-17393] Keep exhaustion terminal across revalidate and resume - #10839
Merged
Merged
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #10839 +/- ##
==========================================
- Coverage 82.95% 82.09% -0.87%
==========================================
Files 606 630 +24
Lines 80704 82136 +1432
Branches 35621 37397 +1776
==========================================
+ Hits 66951 67427 +476
- Misses 13414 14361 +947
- Partials 339 348 +9
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
An iterator that has run past its last result must stay past it until `rewind`. The trait says so, composites rely on it — a union drops children that report `at_eof`, `Intersection::revalidate` early-returns on `is_eof` — and `ContractChecker` asserts it. It was violated anyway. `RawInvIndIterator::revalidate` and `resume_in_place` both restore position with `rewind()` followed by `skip_to(last_doc_id)`. `rewind` clears `at_eos`, so for an iterator that was *at* EOF the re-seek finds the document it already yielded and it comes back reporting `at_eof() == false` and `Ok` — claiming its position never changed while EOF silently flipped. A composite that had dropped the child on EOF then re-admits it behind the position it has moved on to. `union_flat` and `union_heap` carry compensation code naming this exact cause: a workaround at the parent for a bug at the leaf. Capture `at_eos`/`last_doc_id`/`result.doc_id` before the rewind and restore the past-the-end position instead of re-seeking. The `rewind` itself has to stay: `ResumableReader::refresh_pointers` deliberately leaves the buffer pointer stale on the GC path because a rewind is coming, and `IndexReader::reset` is the only thing that refreshes `gc_marker`. Skipping the re-seek also skips the re-decode that would have rebuilt the result's borrowed offsets, so clear them explicitly — we only reach this after a GC cycle, and `RefreshOutcome::NeedsReseek` documents that an `RSOffsetSlice` borrowed from the old buffer does not survive one. The resume path already cleared them ahead of its own cast. A second defect surfaced from the same `rewind`: on a `Moved`-to-EOF the re-seek finds nothing, and `last_doc_id()` was left at the 0 the rewind wrote rather than the document the last yield left. Restored on that arm too, in both functions. `NotOptimized::revalidate` assigned rather than latched its EOF flag, so a wildcard that recovered documents could revive it. Latched now, with `past_end` folded into the guard — `read` recomputes `past_end` from `read_inner`, so latching that alone would be dropped on the next read. Defensive rather than a reachable bug with today's wildcards, but `W` also admits `CRQEIterator` wrapping a C implementation. Why this was not already caught: `revalidate_at_eof` revalidated without dirtying the index, so `needs_revalidation()` was false and `revalidate` returned before reaching the `rewind`. The new `revalidate_at_eof_after_gc` removes a document first, across all five inverted-index leaves, on both the revalidate and resume paths. `ContractChecker` covers the `RQEIterator` surface but not suspend/resume, so the cross-cycle guarantees now sit in `revalidate_via_resume`, the single funnel every resume test goes through. The union compensation stays: with `QUICK_EXIT` laggers are intrinsic to the mode, and a full union can still see one from a child that breaks the contract, which `revalidate_resurrected_child_does_not_drag_a_full_union_backwards` covers deliberately. Only the comments are retargeted. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
LukeMathWalker
force-pushed
the
luca-eof-terminal-across-revalidate
branch
from
August 11, 2026 08:02
4c2de26 to
7a56d81
Compare
1 of 2 tasks
Review follow-ups on the exhaustion-is-terminal change: - Move the contract text onto `RQEIterator::at_eof`, which the citations added in core.rs, not_optimized.rs and both unions already pointed at; `revalidate` keeps only the re-seek trap, and `resume` links to both. - A full union now `debug_assert!`s that no child lands behind its position instead of quietly recovering: children are covered by flow tests and the disk iterators run our suite, so a violation is a bug to surface, not a case to absorb. The recovery stays for release builds. The resurrection test asserts the panic instead of the compensation. - Trim the rationale restated at the three restore sites down to what each one owns locally. - Assert that a restored exhausted leaf stays exhausted on a read, on both the revalidate and resume paths - the flags and the rewound reader are two mechanisms and only a read proves they agree. - `debug_assert!` that the re-seek's `Moved` arm carries a current, so a `None` cannot quietly downgrade it to 'exhausted'.
LukeMathWalker
force-pushed
the
luca-eof-terminal-across-revalidate
branch
from
August 11, 2026 15:27
f1a7771 to
067d01c
Compare
gdesmott
reviewed
Aug 11, 2026
- `union_flat::revalidate` justified revalidating exhausted children by claiming they may become active again. That is what this branch abolishes: they are revalidated because they still hold index references and an aborted one has to be removed, not because they can come back. - The `NotOptimized` latch did not say when `forced_eof` and `wcii.at_eof()` disagree. They do whenever `max_doc_id` closed the window with the wildcard still live on a document, which `skip_to` sets in two places and the read loop in a third - so assigning cleared a flag set for an unrelated reason. Name that, and say which of the two guards covers which call.
The existing latch test reaches it through a contract-violating mock, which left the impression the latch was hardening. It is not: `skip_to` past `max_doc_id` ends the iterator without touching the wildcard, so a wildcard that later moves forward under GC - all a conforming one ever does - made the old assignment clear `forced_eof`, and the next `read` resumed an iterator that had already reported it was done. Red before green: with the assignment restored, ContractChecker fails the new test with 'an exhausted iterator must keep returning None, but it yielded doc 60'.
`forced_eof` and `past_end` recorded overlapping facts, which is what made the latch hard to read: every site setting `forced_eof` also left `past_end` set, and where `past_end` was set alone it was because the position had reached `max_doc_id`, which `has_next`'s second term already catches. So `past_end` latched - cleared only by `rewind`, as exhaustion being terminal requires - covers both roles, and `forced_eof` goes. `read_inner` now owns the invariant that every `Ok(false)` leaves `past_end` set, so `read`/`skip_to` relay its answer instead of re-deriving one. That also retires `skip_to`'s `past_end = false`, which could only ever have run when the flag was already clear. `OptionalOptimized` has always been built this way; this brings the two siblings back into line. No behaviour change: breaking the latch still fails the same two tests, and only those.
|
gdesmott
approved these changes
Aug 12, 2026
GuyAv46
approved these changes
Aug 13, 2026
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.



Describe the changes in the pull request
Current. An iterator that has run past its last result must stay there until
rewind: composites drop children that report EOF and cannot take them back. Inverted-index leaves broke that.revalidateandresume_in_placerestored position by rewinding and re-seeking, and the rewind clears the past-the-end state — so an exhausted leaf came back live on a document it had already yielded. Both unions carried compensation code naming this exact cause, andinterop.rsleft C and Rust disagreeing about whether a child was still alive.NotOptimizedreached the same end by its own route:skip_topastmax_doc_idends it without touching its wildcard, and it then re-derived its EOF flag from that wildcard — so any later forward move by the wildcard cleared it.Change. Exhaustion is terminal on both paths: leaves restore the past-the-end position instead of seeking back to it, and
NotOptimizedlatches its EOF flag. Full unions now assert that no child sits behind them rather than absorbing one that does. New tests cover all five leaves on both paths — the existing at-EOF tests never dirtied the index, sorevalidatereturned before reaching the rewind, which is how this survived a harness built to catch it.Outcome. A resurrected child can no longer replay documents into a parent that has moved on, enforced by assertions and tests rather than by parents compensating. Each fix was confirmed red before green.
Notes for reviewers
Movedand the leaf went on to yield those newer documents. It no longer does. I read that as bringing the GC path in line with the no-GC path, where such documents were never picked up. Flip the release-notes box if you disagree — the title would then need to state the user impact.NotOptimizedlatch fixes a reachable case, not a theoretical one, and it needs no misbehaving child to get there: a wildcard moving forward under GC is all a conforming one ever does. That is the second half of the release-notes call above — the symptom is an iterator yielding again after reporting it had nothing left.revalidate_after_skip_past_max_doc_id_does_not_revive_the_iteratorcovers it; with the old assignment restored,ContractCheckerfails it with "an exhausted iterator must keep returning None, but it yielded doc 60".Verification.
cargo nextest run,make lint,make fmt CHECK=1green on the current head. Miri (528) and./build.sh RUN_PYTESTwere green on the first commit — 61 pre-existing environmental failures, none touching query iteration — and no commit since addsunsafe.Which additional issues this PR fixes
None.
Main objects this PR modified
RawInvIndIterator::{revalidate, resume_in_place}—rqe_iterators/src/inverted_index/core.rsNotOptimized::revalidate—rqe_iterators/src/not_optimized.rsUnionFlat/UnionHeaprevalidate — assertion in place of the compensationrevalidate_via_resume,ContractChecker, andrevalidate_at_eof_after_gcacross the five leavesRQEIterator::at_eof, which now owns the exhaustion contractMark if applicable
Release Notes