Repository navigation
fix(seek): recover slow-source VOD seeks without reverting the clock - #216
Conversation
1e18ee6 to
d7bd00e
Compare
On a high-latency source (Dolby Vision over SMB, HLS re-mux path) a VOD seek can miss its deadline while the producer is still genuinely serving the target. The deadline recovery reverted the reported clock to the frozen pre-seek position and reconciled the transport, which on device is the reported failure: the scrubber visibly jumps back to the old spot and the session parks flapping paused<->playing for ~40s while the orphaned old-position segment drains. Four parts: 1. Extend the deadline while progress is real. AVPlayer buffers the target region into an island that is NOT contiguous with the pinned old playhead, so the old-playhead buffer metric (bufferedEnd) structurally reads 0 there and cannot distinguish "slow but working" from "wedged". Measuring the disjoint forward island (total forward ahead minus the contiguous portion) can, so a filling island extends the deadline instead of triggering a teardown. 2. Hold the clock at the target on fallthrough. Rather than reverting, keep the clock at the target (same UX contract as the extend branch: scrubber parked at target + spinner), re-anchor the producer to the target once, re-issue the seek so AVPlayer abandons the old-position buffer, and wait a bounded number of windows -- reconciling FORWARD to the target, never back, and never flapping the transport. Budget exhausted while still buffering parks the spinner at the target instead of reverting; the $renderedTime sink then settles the clock and clears the seek state when the producer finally serves it. 3. Accept a forward overshoot as a landing. A zero-tolerance seek lands AT the target and a playing item then advances, so a forward seek can render past it. Reading that as "still pending" triggered a backward-yank re-seek on an already-playing item. The pinned pre-seek playhead sits far on the opposite side, so a directional check cannot mistake it for a landing. 4. Edge-detect the landing on the extend/wait path at AVPlayer's own ~100ms observer cadence, so the host's loading state clears when playback actually resumes instead of lagging it by up to a full window (that left a spinner over playing video). Bounded throughout: at most 4 deadline extensions, one re-anchor, and 4 post- re-anchor waits, then a terminal return -- worst case ~10 loop iterations. Every continuing branch increments a monotone counter that is never reset, and every await is followed by a load/seek generation re-check before publishing state. Scoped to the native VOD deadline branch; live and software/audio host paths are untouched. Preserves superuser404notfound#65 (true-wedge bound), superuser404notfound#122 (paused-seek transport intent) and superuser404notfound#123 (buffering-toward-target sourceTime hold).
d7bd00e to
a4e049b
Compare
10c5ea0
into
superuser404notfound:main
Follow-up to #216 on three edges the new wait windows opened. 1. The $renderedTime sink can finalize the same seek underneath the deadline loop, and its landing predicate is looser than the loop's: pendingSeekLanded accepts anything within +-5s of the target (symmetric), seekLandedAtTarget wants +-0.75s on the near side. A landing 3s short of a forward target therefore ran finalizeLateRecoverySeekLanding (clearing the seek gate, reconciling the transport) while the loop still read "pending" and would go on to re-anchor the producer and re-seek backward onto an item already reported as playing -- the yank the overshoot rule exists to prevent, reintroduced through the back door. Guard on programmaticSeekInFlight, the authoritative "this seek is still ours" latch. 2. bufferedSecondsAtTarget's 30s window only keeps a FAR backward seek clear of the abandoned playhead's forward buffer. A backward seek of less than the window leaves that buffer inside the measurement range, where a still-full old buffer reads as "the producer is serving the target" and earns an extension it has not earned. The deadline loop now passes the frozen playhead as an exclusion bound on backward seeks. Extracted the window arithmetic into a pure bufferedSecondsInWindow so the case is testable without an item. 3. awaitPendingSeekLanding sleeps on the caller's task, so a cancelled task makes every remaining window return false in microseconds: the loop burned its whole budget in one runloop turn and still restarted the producer on the way through. (host.seek(to:deadlineSeconds:) runs its deadline on a detached task, which is why this could not happen before the wait windows existed.) Terminate on the give-up contract instead. Full suite green (1066 tests) plus iOS/tvOS simulator builds. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01QYhPvBB1sLCYoZNasEXFeB
House style is commas, colons or parentheses. The 11 the seek-recovery change introduced were the only ones in either file. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01QYhPvBB1sLCYoZNasEXFeB
|
Merged as 10c5ea0. Thank you for this one, it is a genuinely hard piece of reasoning and the writeup carried it: the observation that Rebased onto 5.23.1 (the only conflict was the CHANGELOG entry landing next to the new release sections) and followed up with three bits of hardening in 46d50bc, all on edges the new wait windows opened rather than anything wrong in the original reasoning:
Also dropped the em-dashes from the new comments (f88cd48), house style here is commas, colons or parentheses. Full suite green at 1066 tests plus both simulator builds. It will go out in the next release. |
|
Shipped in 5.23.2. Both consumers are pinned to it and building clean. |
Summary
On a high-latency source (Dolby Vision over SMB) a VOD seek can miss its deadline while the producer is still genuinely serving the target. Recovery then reverted the clock to the pre-seek position, so the scrubber visibly jumps back and the session parks flapping paused↔playing for ~40 s. This makes recovery reconcile forward to the target instead.
What changed
Four related changes on the native VOD seek-deadline path:
bufferedEndstructurally reads 0 there and cannot tell "slow but working" from "wedged". A newNativeAVPlayerHost.bufferedSecondsAtTarget(_:)measures what the producer has actually served at the target, referencing no playhead at all — deliberately, becausebufferedEnd/avPlayerBufferAheadSeconds()are measured fromitem.currentTime()while the loop's frozen position isrenderedTime, and those two legitimately diverge during a buffering landing (Queued seek bursts: engine clock adopts each target immediately while the player rebuilds — 10-30s clock/presentation divergence; subtitle cues pace with the clock over a stale frame #123). An extension additionally requires that figure to be growing between windows (presence alone cannot distinguish a producer still filling from one that served 4 s and died) and is vetoed when the target is beyond producer coverage (AE#141).$renderedTimesink settles the clock and clears the seek state when the producer finally serves it.renderedTimerather thanavPlayer.currentTime()(no synchronous XPC per tick, LiveTelemetrySampler: synchronous AVFoundation IPC on the main actor at 1 Hz → fatal app hangs on the native path #134) and bounds itself withDispatchTime, not wall clock. It requires position evidence and deliberately does not accept "the seek completion ran":reengageStalledConsumercallscancelPendingSeeks()without bumping the seek generation, so a cancelled seek would otherwise report as a landing and silently retire the recovery target (Loopback-HLS: a single backward seek on heavy 4K can wedge the segment producer (video stalls, audio continues -> A/V desync) #93).Bounded throughout: at most 4 deadline extensions, one re-anchor, and 4 post-re-anchor waits, then a terminal return — worst case ~10 loop iterations, so
await seek(to:)stays suspended at most ~44 s (documented onnativeSeekExtensionBudgetSeconds). Every continuing branch increments a monotone counter that is never reset, and everyawaitis followed by a load/seek generation re-check before any published state is mutated. The terminal give-up holds the clock at the target but clears the programmatic-seek gate and reconciles as starved, so a source that never serves the target reports.rebuffering/.stalledinstead of parking in.seekingforever — the permanent-spinner class this PR exists to remove must not simply relocate to the give-up.Scoped to the native VOD deadline branch; live and software/audio host paths are untouched. Preserves #65 (true-wedge bound), #122 (paused-seek transport intent) and #123 (buffering-toward-target
sourceTimehold).Test plan
RecoverySeekTargetTestscoverage for the growth/coverage/budget rules of the extension decision, overshoot acceptance and the recovery anchor.Checklist
CHANGELOG.mdupdatedfeat(...),fix(...),chore(...))