Repository navigation
Description
What happened?
Two related timing races cause a user-issued seek(to:) to either be dropped entirely or resolved to the wrong target during VOD playback startup / mid-stream restarts on the loopback-HLS local remux path:
-
AetherEngine.seek(to:) unconditionally no-ops while state == .loading (AetherEngine.swift:2304-2307), with no queuing or replay. A seek issued anywhere in the multi-second initial-load window (probe -> native load -> readiness gate) is silently discarded. Hosts that optimistically render the seek target (then fall back to engine.currentTime once the pending target clears) will visibly show playback "snap back" to the pre-seek position once the no-op is observed.
-
In RestartCoalescer.begin() (Video/RestartCoalescer.swift:20-30), once an authoritative restart (a recovery re-anchor computed from AVPlayer's real rendered position, e.g. a stalled-seek-deadline reconcile) occupies the single pending slot, a subsequent ordinary scrub restart is dropped outright rather than queued. The code comment assumes "AVPlayer re-requests on the next segment GET, so nothing is lost," but in the log below the second, real seek target is never honored -- the producer instead lands on the authoritative recovery position.
Expected: every user-issued seek either takes effect at (approximately) its requested target, or is queued/replayed once the engine can act on it -- never silently dropped.
Actual: seeks issued during .loading, or ordinary seeks arriving while an authoritative restart is pending, are discarded with no queuing, producing either a visible position snap-back or a seek that lands ~10s+ away from the requested target.
Steps to reproduce
- Start VOD playback on the native (AVPlayer) path over the loopback-HLS local remux backend.
- While the engine is still in state == .loading (the first few seconds after load(), before the readiness gate fires), issue seek(to:) to a target well past the current position (e.g. +30s from ~5s in).
- Observe: the seek is a no-op (logged as "seek(to:...) ignored: load in progress"); once any host-side optimistic "pending target" display clears, the shown position reverts to the original (~5s) position instead of the requested target.
Alternative repro for the second mechanism:
- Start VOD playback and let it reach .playing.
- Issue a seek that is slow enough to hit the native seek-reconcile deadline (or otherwise trigger an authoritative recovery re-anchor) -- this occupies the RestartCoalescer pending slot as pendingAuthoritative = true.
- While that authoritative restart is still in flight, issue a second, different seek (an ordinary scrub).
- Observe: the second seek's target is discarded; the segment producer restarts only at the authoritative recovery position, not the second requested target.
AetherEngine version or commit SHA
5.14.0 / 396d138 -- confirmed still present, byte-for-byte identical in both files, in the latest tag 5.17.3 (published 2026-07-21)
Host app
Custom / my own integration
Platform
tvOS
OS version
tvOS 26.5
Device / chip
Apple TV
Playback path
Native AVPlayer
Source media (for playback bugs)
MP4 container / H.264 High Profile, Level 5.1, yuv420p, BT.709 (SDR), 3840x2160 / AAC-LC stereo, 44100 Hz
Error codes / log lines
[AetherBackend] coalesced seek dispatch target=102.32s
[NativeAVPlayerHost] #1 timeControlStatus=waitingToPlay reason=AVPlayerWaitingWhileEvaluatingBufferingRateReason t+73.29s
[NativeAVPlayerHost] #1 timeControlStatus=waitingToPlay reason=AVPlayerWaitingToMinimizeStallsReason t+73.29s
[NativeAVPlayerHost] #1 timeControlStatus=playing t+73.73s
[AetherBackend] coalesced seek dispatch target=132.92s
[HLSVideoEngine] seg24: out-of-range fetch (cache.range=0..21 highWater=14 attempt=1/3), restarting producer
[HLSSegmentProducer] seg-15.m4s partial at teardown (4472221 B) discarded, not adopted
[HLSSegmentProducer] pump finished: reason=stopRequested packetsRead=1854 packetsWritten=556 lastError=0 elapsed=17079ms cacheCount=16
[HLSSegmentProducer] init OK (baseIndex=24, segments=516, targetDur=4.000s, srcVideoTb=1/90000) audio=stream-copy inTb=1/44100
[HLSVideoEngine] producer restarted at idx=24 (seek=119.92s [absolute source-PTS], restart took 110ms; stopWait=109ms seek=0ms build=0ms)
Note the requested seek target was 132.92s, but the producer restarted at source-PTS 119.92s -- a ~13s discrepancy consistent with mechanism #2 above (the second seek was discarded by RestartCoalescer, and the producer landed on an authoritative recovery position instead).
Anything else
Relevant code: Sources/AetherEngine/AetherEngine.swift:2297-2331 (seek(to:), .loading guard at 2304-2307), Sources/AetherEngine/Video/RestartCoalescer.swift:1-52 (whole file; begin() at 20-30).
Closed issue #127 addresses a related but narrower case (deferred pre-ready seek across background-teardown reload) -- its "stash target, replay at readiness" pattern does not cover the general initial-.loading case in mechanism #1 above, nor does it interact with RestartCoalescer's authoritative-slot logic in mechanism #2.
Not a duplicate of #37 (checked before filing): #37 was a clock/state-publishing race where the periodic time observer overwrote the optimistic post-seek clock before a slow AVPlayer seek physically landed, and was fixed by making the host seek async and awaiting its completion before flipping state back. That fix is present in the version pinned here (seekGeneration guard visible at AetherEngine.swift ~2338) and does not touch either mechanism below: mechanism #1 returns out of seek(to:) before any host seek is ever issued (the .loading guard fires first), and mechanism #2 lives entirely in RestartCoalescer's restart-coalescing logic, a different subsystem than the native host's clock publishing.
Possible directions (not prescriptive): for #1, apply the same "stash and replay once loading completes" pattern already used for #127 to the general .loading branch; for #2, either give RestartCoalescer a way to queue an ordinary scrub behind an in-flight authoritative restart (rather than dropping it), or have the authoritative path re-check for a newer ordinary target once it lands.
Activity
superuser404notfound commentedon Jul 21, 2026
Thanks for the exceptionally precise report. Both mechanisms were exactly where you pointed, and fixes for both are released in 5.18.2 (PR #185).
Mechanism 1 (
.loadingguard):seek(to:)now stashes the latest loading-window seek instead of dropping it, publishes it optimistically to the scrub clock (so an optimistic host UI no longer snaps back), and replays it through the normalseek(to:)path once the engine settles out of.loadinginto a playable state. The replay hook is the state transition itself rather than the #127 readiness sink, because on autostart paths readiness fires whilestateis still.loadingand a sink-driven replay would just re-enter the guard. A load that dies (.idle/.ended/.error) discards the stash so it cannot leak into the next session. Expected log lines:seek(to:...) stashed during load; will replay when the session settles (#178)followed byreplaying seek stashed during load to ...s (#178).Mechanism 2 (RestartCoalescer authoritative slot): your read was right, and it was slightly worse than the code comment suggested. The "AVPlayer re-requests on the next segment GET, so nothing is lost" safety net was defeated by the provider's own bookkeeping:
VideoSegmentProviderrecordslastRestartIndex = indexand setsfiredThisCallaround therestart(index)call, and when the coalescer drops that call, the same-index guard then suppresses subsequent re-fires for that index and starves the orphan backstop within that fetch. That is how your producer stayed anchored on the recovery position ~13 s from the requested target until the seek deadline reconciled the clock back to the rendered frame.The fix takes your second suggested direction, inverted: instead of queuing the ordinary scrub behind the authoritative pending, a new user seek releases the superseded authoritative claim (
RestartCoalescer.clearSupersededAuthoritativePending) before the host seek is dispatched, so the new target's segment-driven restart takes the pending slot normally. The re-anchor was computed for the seek being superseded, so dropping it (rather than running both restarts back to back) also avoids re-anchoring the producer away from where AVPlayer plays next. The #79 lock is unchanged for the case it was built for: stale burst-tail scrubs arriving without a fresh user seek are still blocked, and the live-reopen authoritative anchors are untouched.New coverage in
Issue178LoadingSeekStashTestsplus supersede cases inRestartCoalescerTests; all pre-existing #35/#79 coalescer expectations pass unchanged.A retest on your setup would be appreciated, in particular the initial-load repro (seek well past the current position while still in
.loading) and the double-seek sequence from your log. I will keep this open until then.fix(seek): stop dropping seeks during load and against pending author…
feat(seek): publish a seek-lifecycle event stream and make the fallin…