Repository navigation
Description
Summary
On a VOD session over an unstable / low-bandwidth connection (reproduced on cellular), playback occasionally jumps backward a few seconds — a short replay — with no freeze or visible buffering stall. I've traced it to the #65 backpressure-wedge consumer re-engage path: it nudges AVPlayer with a zero-tolerance seek to a position captured before the re-engage grace window. Because AVPlayer keeps advancing its render clock during that window on VOD (it's still draining already-buffered segments), the nudge seeks the playhead behind the on-screen frame — the visible backward skip.
Observed on dc766ad.
Environment
- Downstream app linking the
AetherEngineSPM product; native loopback /.softwaredemux path (nativeRemoteHLSis not used, so remote VOD runs the FFmpeg-demux →127.0.0.1loopback AVPlayer path). - Remote HTTP VOD (debrid/torrent links + media-server HLS). Not live.
- Trigger: cellular, where download throughput periodically collapses to ~0 then recovers. Never seen on wired / strong Wi-Fi.
Symptom (field report)
- "It's actually replaying the last few seconds. There is no buffering, the video never stops, it just skips back."
- "When the current bitrate goes up again from zero, that's the moment it skips back a bit."
- In stats: AVPlayer forward buffer (
loadedTimeRangesahead of playhead) drains toward 0 and then jumps back up on recovery; the backward skip coincides with that recovery.
Root cause (code trace, dc766ad)
HLSVideoEngine.handleBackpressureWedge() — Sources/AetherEngine/Video/HLSVideoEngine+LiveReopen.swift:
- L118 captures
let pos = currentPlaybackPositionProvider?()— AVPlayer's rendered position at wedge-trip time. - Re-anchors the producer via
recoveryAnchorPosition(frozenPosition: pos, pendingSeekTarget:)(this part is fine). - L171–L184 schedules a
consumerReengageGraceSecondsgrace check, then callsonConsumerReengageNeeded?(pos)— passing the sameposcaptured at L118, not refreshed after the grace window elapses.
Host side — Sources/AetherEngine/AetherEngine+Loading.swift:
- L273–L296
session.onConsumerReengageNeeded = { position in self.reengageStalledConsumer(position: position, trigger: "wedge re-anchor") ... } reengageStalledConsumer(position:trigger:)—Sources/AetherEngine/AetherEngine.swift:786— issuesplayer.seek(to: CMTime(seconds: position…), toleranceBefore: .zero, toleranceAfter: .zero).
Since the seek is zero-tolerance to a pre-grace-window pos, and AVPlayer keeps advancing the render clock during the grace window (VOD buffered playback continues — matching "the video never stops"), the seek lands behind the on-screen frame → the visible backward replay.
Internal inconsistency that pinpoints it: every other recovery path re-reads the position at nudge time; only this one reuses a stale capture.
- stall-count watchdog (
AetherEngine+Loading.swift~L645 / ~L659):reengageStalledConsumer(position: player.currentTime().seconds, …)andreloadStalledConsumerItem(position: player2.currentTime().seconds)— read after their grace sleep. - item-death
failedToPlayToEndTime(~L701):reloadStalledConsumerItem(position: host.renderedTime, allowPausedConsumer: true)— fresh. - wedge → consumer-nudge (
HLSVideoEngine+LiveReopen.swift:183): staleposfrom L118. ← the outlier.
Why VOD-only and flaky-only
- VOD-only:
handlePumpFinishedroutes.backpressureWedgetohandleBackpressureWedge()before theguard isLiveSession else { return }, and the comment marks it "Presented frame drifts ~6 s ahead of currentTime/sourceTime after a rapid bidirectional seek burst (loopback-HLS native path) — frameAhead/producerShift/hostShift all report 0 #65 (VOD only)." - Flaky-only: the wedge trips and the re-engage grace window fully elapses only when throughput starves the producer long enough that the consumer stops fetching. On a healthy link the consumer resumes fetching inside the grace window and the nudge never fires.
How to confirm from logs
When it happens, these two lines fire with a pos behind the live playhead:
[HLSVideoEngine] #65 consumer re-engage: no segment fetch for <N>s after wedge re-anchor (pos=<X>s); asking host to nudge AVPlayer
[AetherEngine] #65 re-engaging stalled AVPlayer (wedge re-anchor): nudge seek to <X>s
<X> will be less than AVPlayer.currentTime at that instant — the gap is the backward skip.
Proposed fix
Refresh the position at nudge time rather than reusing the pre-grace capture — mirror what the stall-watchdog path already does. In handleBackpressureWedge's grace closure, re-read currentPlaybackPositionProvider?() at the moment of onConsumerReengageNeeded?(…) (and/or clamp the nudge target so it can never be less than the current rendered position, e.g. route through recoveryAnchorPosition with a max(anchor, currentRendered) guard). This preserves the recovery effect (a zero-tolerance seek rebuilds AVFoundation's loader) without rewinding.
Test
recoveryAnchorPosition(frozenPosition:pendingSeekTarget:) is nonisolated static and already covered by Tests/AetherEngineTests/RecoverySeekTargetTests.swift. The invariant "the recovery nudge target is never below the current rendered position" can be pinned there red→green (adding a currentRendered parameter / clamp), in the same deterministic style as Issue65LivelockTests and SourceThrottleTests — no live network needed to prove the fix is correct.
Repro note
This is cellular-only and hard to reproduce on demand (needs a live throttle plus a wired debugger), so I don't have an aetherctl repro to attach — but the code path, the field telemetry, and the two log lines above localize it precisely. Happy to capture the on-device pos= log line next to currentTime if that would help confirm before a fix.
Activity
fix(recovery): nudge the stalled consumer at the rendered frame, not …
Merge fix/issue115-wedge-nudge-fresh-position: nudge at the rendered …
superuser404notfound commentedon Jul 9, 2026
Fixed on main in f83fe86 (fix commit 62b4b1d).
Your trace was exactly right, thanks for the precise localization. The wedge path was the only recovery path reusing the pre-grace capture; the stall watchdog and item-death paths already re-read after their grace sleeps.
What changed:
handleBackpressureWedgenow re-readscurrentPlaybackPositionProviderat nudge time, after the grace window elapses, and passes that fresh position toonConsumerReengageNeeded. The log line keeps the wedge capture when they diverge, so the stale gap stays visible for diagnosis:... (pos=<fresh>s, wedge capture <stale>s); asking host to nudge AVPlayer.player.currentTime()at reload time now, matching the stall watchdog's stage 2 (that capture was two grace windows stale).recoveryAnchorPositiongained acurrentRenderedparameter with amax(frozen, currentRendered)clamp, so without a pending user seek target the nudge/reload target can never sit below the rendered frame (this also covers the MainActor hop between the engine callback and the host seek). A pending backward user seek still wins, so the Loopback-HLS: a single backward seek on heavy 4K can wedge the segment producer (video stalls, audio continues -> A/V desync) #93 recovery-intent semantics are preserved.RecoverySeekTargetTests.528 tests green, tvOS build green. The fix will ship with the next release. If you get a chance to run a build off main on the same cellular setup, the backward skips at throughput recovery should be gone, and any remaining re-engage logs should show
pos=at or ahead of the on-screen frame.dlev02 commentedon Jul 9, 2026
Perfect, I'll try to reproduce the same scenario in the next couple of days and report back!
chore(release): prepare 5.0.0
dlev02 commentedon Jul 21, 2026
Reporting back after more testing on cellular: big improvement, the backward skip is basically gone. It's not 100% though (I haven't personally experienced it, relying on a few beta testers to report back); They still occasionally see a tiny stutter/buffer/skip on a flaky mobile connection, much smaller and rarer than before. I saw the follow-up work in #129 and the related report in #141, so some of what's left may be covered there. It's hard to reproduce on demand, but I'll keep an eye on it and report back if I catch anything more concrete.
superuser404notfound commentedon Jul 21, 2026
Thanks for the retest and for relaying the beta feedback, that is exactly the verification I was hoping for.
On the residual, it is worth separating two symptoms:
... (pos=<fresh>s, wedge capture <stale>s); asking host to nudge AVPlayer. Apos=behind the on-screen frame would be a real regression, and I would want that log immediately.Also worth checking which engine revision the beta builds pin. The #115 fix shipped in 5.0.0, and a lot has landed in this exact area since: the #129 bounded-seek and sparse-cache coverage work (5.4.1), the #141 far-forward re-anchor (5.9.1), and the #174 backpressure rework on the remote HTTP read path (5.17.3), which changed how the transfer behaves under exactly this kind of stall-and-recover cycle. Current release is 5.18.0. If the testers are on anything older, I would bump first before chasing what is left.
I will leave this open for a bit while your testers keep watching. If what remains turns out to be plain rebuffering rather than a backward jump, we can close this one and take anything concrete to a fresh issue with the logs above.
fix(native): recovery paths must not read AVPlayer on the main actor (s…
dlev02 commentedon Oct 20, 2026
Following up after a few months on newer engine releases: no more reports of the backward jump from my testers, only the occasional normal rebuffer on a really bad connection, which you explained is expected. Closing this one. Thanks for the fix and for breaking down the two symptoms so clearly.
G00380316 commentedon Oct 20, 2026
Hey @dlev02 do you have any socials by any chance?