Skip to content

VOD stall recovery: #65 consumer re-engage nudge seeks to a stale (pre-grace) position → backward skip on flaky connections #115

Closed

Description

@dlev02

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 AetherEngine SPM product; native loopback / .software demux path (nativeRemoteHLS is not used, so remote VOD runs the FFmpeg-demux → 127.0.0.1 loopback 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 (loadedTimeRanges ahead 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 consumerReengageGraceSeconds grace check, then calls onConsumerReengageNeeded?(pos) — passing the same pos captured 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 — issues player.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, …) and reloadStalledConsumerItem(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): stale pos from L118. ← the outlier.

Why VOD-only and flaky-only

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

  1. superuser404notfound commented on Jul 9, 2026

    @superuser404notfound
    Owner

    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:

    • handleBackpressureWedge now re-reads currentPlaybackPositionProvider at nudge time, after the grace window elapses, and passes that fresh position to onConsumerReengageNeeded. 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.
    • The wedge path's stage-2 escalation (item reload) also reads player.currentTime() at reload time now, matching the stall watchdog's stage 2 (that capture was two grace windows stale).
    • Defense in depth, as you proposed: recoveryAnchorPosition gained a currentRendered parameter with a max(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.
    • The invariant "the recovery nudge target is never below the current rendered position" is pinned red to green in 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.

  2. dlev02 commented on Jul 9, 2026

    @dlev02
    ContributorAuthor

    Perfect, I'll try to reproduce the same scenario in the next couple of days and report back!

  3. dlev02 commented on Jul 21, 2026

    @dlev02
    ContributorAuthor

    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.

  4. superuser404notfound commented on Jul 21, 2026

    @superuser404notfound
    Owner

    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:

    1. A backward jump (replaying already-watched seconds) was the VOD stall recovery: #65 consumer re-engage nudge seeks to a stale (pre-grace) position → backward skip on flaky connections #115 defect. If any tester catches that again, the re-engage log lines are the tell. Since the fix, the engine logs the fresh position and keeps the wedge capture when they diverge: ... (pos=<fresh>s, wedge capture <stale>s); asking host to nudge AVPlayer. A pos= behind the on-screen frame would be a real regression, and I would want that log immediately.
    2. A brief stutter or rebuffer at the moment throughput recovers from ~0 is expected once the forward buffer has fully drained. The fix removed the rewind, not the physics of an empty buffer on a dead link.

    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.

  5. dlev02 commented on Oct 20, 2026

    @dlev02
    ContributorAuthor

    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.

  6. G00380316 commented on Oct 20, 2026

    @G00380316

    Hey @dlev02 do you have any socials by any chance?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions