Skip to content

fix(seek): re-anchor producer for far-forward seeks above retained scrub bands (#141) - #147

Merged
superuser404notfound merged 1 commit into
mainfrom
fix/ae141-far-forward-seek-stale-band
Jul 19, 2026
Merged

superuser404notfound merged 1 commit into
mainfrom
fix/ae141-far-forward-seek-stale-band

Conversation

@superuser404notfound

Copy link
Copy Markdown
Owner

Summary

Fixes #141: a far-forward VOD seek whose target sat just above a retained (dead) scrub band's resident top parked in three 30 s cache-miss serve timeouts, tore the loopback connection into -1017 / failedToPlayToEndTime item death, and only reached the requested target via stage-2 reload roughly 108 s after the seek command.

Root cause

The reporter's scripted sequence (600 s, 30 s, 302 s, 640 s) built exactly the one geometry the serve path trusts blindly:

  1. The 600 s seek re-anchored the producer at seg150; its band (segments ~150-158) stayed resident under the Loopback-HLS: a single backward seek on heavy 4K can wedge the segment producer (video stalls, audio continues -> A/V desync) #93 retention budget after later seeks moved the producer away.
  2. The 302 s seek re-anchored the producer at seg75 through the provider's restart branch, which resets the cache high water; by the 640 s seek the active march front was ~seg79 (~316 s).
  3. The 640 s seek made AVPlayer request seg159, which fell in the forward-wait window just above the dead band's top (r.1 < index <= r.1 + 8). That branch read the resident max as "the producer is about to write this" and parked the request in the 30 s backpressure fetch with no restart, three times. The gen 1-3 seeks all took branches that DO check the active producer (out-of-range, interior-hole coverage), which is why only the fourth seek died.
  4. The 8 s seek-deadline path (fix: bound stalled seeks and recover sparse cache holes #129) declined its backstop restart too: seekIsWedged saw 6.5 s of forward buffer at the old position (healthy, progressing) and "reconciled the clock without restarting the progressing producer". The target sat ~330 s beyond the march; at that bitrate the sequential fill needs ~2 minutes, far past the consumer's 3x30 s budget, so a late landing was structurally impossible.

Fix

Two layers, matching the two misreads:

  • VideoSegmentProvider (primary): the forward-wait branch now keys on the active producer's write front, max(highWater since restart, lastRestartIndex), instead of the resident maximum. A request beyond front + forwardWaitWindow re-anchors the producer immediately. In normal single-band operation the front equals r.1, so healthy catch-up backpressure is unchanged.
  • Seek-deadline backstop (AetherEngine): shouldReanchorProducerAfterSeekDeadline now also re-anchors when the pending seek target lies beyond active march coverage (producerCoversPlaylistTime -> activeMarchCovers). Starvation is no longer the only trigger; a healthy march filling toward a reachable target still keeps its progress (fix: bound stalled seeks and recover sparse cache holes #129 semantics preserved).

The deadline log line now names the third case (old position still buffered, target beyond producer coverage ... and re-anchored producer at ...), so a recurrence is directly attributable in reporter logs.

Testing

  • New Issue141FarForwardSeekTests: device geometry red-to-green (restart fires instead of a 30 s park; with the stale band resident under a retention budget, the pre-fix code parks the full injected wait and serves nil), healthy catch-up still backpressure-waits with no restart, and the activeMarchCovers span (anchor-to-front + window, cold-start anchor window, behind-anchor and beyond-window excluded).
  • RecoverySeekTargetTests pins the extended deadline decision table (starved, target-beyond-coverage, both, neither).
  • The 30 s forward backpressure wait is injectable for tests; the production default is unchanged.
  • Full suite: 734 Swift Testing + 311 XCTest tests green, Swift 6 strict concurrency clean, tvOS Simulator build green.

🤖 Generated with Claude Code

https://claude.ai/code/session_01NAPCg4tCDdSqkK6tPkNptw

…rub bands

A far-forward VOD seek whose target sat just above a dead scrub band's
resident top parked in 3x30 s cache-miss serve timeouts (restarted=false),
tore the connection into -1017 item death, and only reached the target via
stage-2 reload ~108 s after the seek command (issue #141, n=1 device log).

Two layers misread the geometry:

- VideoSegmentProvider's forward-wait branch (r.1 < index <= r.1 + window)
  read the resident max as "the producer is about to write this". With the
  #93 retention budget, r.1 can belong to a dead producer's band far above
  the active march (band 150-158 from a 600 s scrub; producer re-anchored
  at 75, front ~79; request seg159). The branch now keys on the active
  producer's write front, max(highWater since restart, lastRestartIndex),
  and re-anchors when the request is beyond the reachable window. In
  normal single-band operation the front equals r.1, so behavior there is
  unchanged.

- The 8 s seek-deadline path (#129) kept the "progressing" producer because
  the old position still had forward buffer (seekIsWedged=false), blind to
  the pending target sitting ~330 s beyond the march. The deadline backstop
  now also re-anchors when the pending target lies beyond active march
  coverage (activeMarchCovers via producerCoversPlaylistTime); a healthy
  march filling toward a reachable target still keeps its progress.

The 30 s forward backpressure wait is now injectable for tests (production
default unchanged). New Issue141FarForwardSeekTests pin the device
geometry (restart fires, no 30 s park), healthy catch-up backpressure, and
the march-coverage predicate; RecoverySeekTargetTests pins the extended
deadline decision table.

Fixes #141.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NAPCg4tCDdSqkK6tPkNptw
@superuser404notfound
superuser404notfound merged commit 4d2a486 into main Jul 19, 2026
3 checks passed
@superuser404notfound
superuser404notfound deleted the fix/ae141-far-forward-seek-stale-band branch July 19, 2026 13:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Far-forward seek into an unproduced region (loopback-HLS VOD)

1 participant