Repository navigation
fix(video): bound the buffer frontier anchor to the consumer's fetch sequence - #226
Merged
superuser404notfound merged 1 commit intoJul 26, 2026
Merged
Conversation
…sequence The #223 anchor (max(playhead, consumer fetch target)) rests on everything below the target sitting in the consumer's buffer. That holds only inside an uninterrupted fetch sequence: AVPlayer fetches no further ahead than its own buffer reaches, which is what bounds target - playhead during normal playback. A seek removes the bound, and since declareTarget lands at the destination before currentTime() reports it, the walk measured the freshly produced band there against the position the seek jumped away from and reported a lead the size of the seek distance for one tick (field report on 5.23.4, ~35 min claimed over a playhead with nothing resident ahead of it). SegmentCache now tracks the current sequence (floor plus front) and the anchor falls back to the playhead outside it, which reports what is genuinely reachable from there or nothing when its own segment is gone. A jump is an index above front + 1 or more than backwardWindow below the front; the Continuous-Audio handover refetch and its return to the front stay inside the sequence, since treating those as a seek would re-open the #207 collapse the anchor exists to prevent. 4 new tests: the forward-seek claim with the old band resident and evicted, a forward seek below the pre-seek front (which needs the backward seek to end the sequence too), and the handover guard. 1100 green, strict-concurrency clean. Co-Authored-By: findussoft <[email protected]> Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
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.
Follow-up to #223, from the field report on 5.23.4 in #207.
The report
With the opt-in prefetch active, a far seek made
clock.bufferedPositionclaim a lead the size of the seek distance for one tick: jumping out of the resident band and then forward to segment 729, the tick taken while the clock still read the old position showed ~35 min of lead over a playhead with nothing resident ahead of it. It corrected as soon as the clock landed.Root cause
The #223 anchor is
max(playhead, consumer fetch target), and its safety rests on everything below the target sitting in the consumer's own buffer. That is true only inside an uninterrupted fetch sequence: AVPlayer fetches no further ahead than its buffer reaches, which is what keepstarget - playheadbounded during normal playback (~30 segments, ~120 s).A seek removes that bound.
declareTargetlands at the destination beforecurrentTime()reports it (AVPlayer needs the data to seek), so for the ticks in between the walk starts at the destination, runs through the freshly produced band, and measures it against the position the seek jumped away from.Worth noting for the reading of the report: the quoted
fwd=2089.6is AVPlayer's ownloadedTimeRangesvalue, notbufferedPosition; AVPlayer makes the same axis error during the seek. The engine-side number lands in the same magnitude for the reason above.The change
SegmentCachetracks the current fetch sequence (fetchFloor,fetchFront), and the anchor falls back to the playhead outside it:A jump is an index above
fetchFront + 1or more thanbackwardWindowbelow the front. The second clause is load-bearing: the Continuous-Audio handover refetches ~7-10 segments backward and returns to the fetch front, and reading that as a seek would re-open the #207 collapse this anchor exists to prevent (the guard test covers it, and it fails against the naive "any non-sequential index ends the sequence" rule).Ending the sequence on a backward seek is what lets a later forward seek that lands below the pre-seek front still be recognised as a jump.
The four #223 invariants are unchanged: no unbounded hole skip,
maxstill keeps a backward refetch from dragging the anchor back, anchor and walk still share one lock hold, and the caller's guard still measures against the playhead (#54 clamp).Residual
A scrub shorter than the backward window stays inside the sequence, so a tick or two around it can still anchor on the old target. The error is bounded by that window instead of by the seek distance, and it is documented at the call site.
Verification
Issue207FrontierAnchorTests(forward-seek claim with the old band resident and with it evicted, forward seek below the pre-seek front, handover guard), each watched failing firstIssue207FrontierAnchorTestsalso now models the consumer's sequential fetches instead of a single declared target, which is what the anchor's premise is aboutswift build -Xswiftc -strict-concurrency=completecleanAnalysis and device logs by @fxndxs, credited as co-author.