Skip to content

fix(playback): reanchor a seek below a restarted window and refuse an anchor-less remux start - #461

Merged
randrini merged 10 commits into
mainfrom
fix/seek-after-restart
Nov 21, 2026
Merged

randrini merged 10 commits into
mainfrom
fix/seek-after-restart

Conversation

@randrini

@randrini randrini commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

Related issue: N/A
Validation tasks: none

The playback matrix run on af63a080e left two seek cells failing for four
separate reasons. The earlier round narrowed both failures but did not close
them.

F1 — transcode video, backward seek after a forward restart (tv-seek).
Item file_id=1760202, session 3f3f561a-aaa9-4b51-99cd-9baf85a2fcdd, route
transcode / server_transcode_hls. A forward scrub to 939.4 s restarts
FFmpeg at segment 468. The backward scrub to 347.2 s is answered by a
seek_reanchor (2017 ms) that lands at 346.5 s and plays, but the client
requests the fenced seg_00173.ts twice (412 at 20:26:41.944 and again at
20:26:42.452) before the replan answers. The second answer falls through to the
ordinary playlist refetch, which seeks the restarted generation on the
playlist's own clock and asks for seg_00346.ts (692 s). In one of four probe
runs (session f83ab3d1-f987-4d94-9353-1f01c7b1d6e4) that left the content
position at 346.75 s for 35 s while the UI showed the Pause control: the
element was not advancing and the controls claimed it was.

F2 — progressive remux, forward seek (pr-seek). Item file_id=37985,
session 47a20041-c461-4b28-a80f-7e5b38338f48, route remux /
server_remux_progressive. The seek replan now answers the retryable
transcode_start_failed verdict instead of a 15 s no-byte stream, but it takes
15.0 s and then 24.9 s to decide, and the seek path shows no retry: the position
stays on the failed target with no error and no Try again. The start path
showed the card at 15.1 s and its retry played (pr-sub). File 37985 later
lost its probe data, and the matrix substituted 1614887, where the steps
passed; that was the substitution mechanism working, not this repro being
fixed.

The retry this card offers is a known limitation of this change. The card
appears after about 5 s, the viewer presses Try again, and the fresh start
re-runs the same 5 s anchor probe against the same slow source and is refused
again. A fix was attempted and reverted: granting the retry a longer bounded
window plus a keyframe fallback leaked into non-seek replans, turned a 203 ms
track_change into a 5 s probe with no frame and a 24.7 s pause, and still
delivered no frame on the fallback (remux produced no output: EOF). That work
is deferred to its own change. The harness cell pr-seek-retry exists to prove
it when it lands.

Approach

The previous round translated the 412 into a seek_reanchor but left hls.js's
own fragment retry in flight, so the fence still saw the dead URL twice. The
second answer then fell through to the playback playlist refetch, which is what
moved the restarted generation to seg_00346 and froze it. The round also sized
the progressive anchor probe by its own cap, and the player never surfaced the
seek terminal it received.

These changes close the residuals:

  • The first 412 on a pending seek stops the hls.js instance, so the fenced URL
    is requested exactly once. A pending seek never refetches the fenced
    playlist. If the reanchor reuses the same generation, a planRevision effect
    refetches that playlist once with the live token and resumes at the seek
    target instead of leaving a stopped instance behind.
  • A progressive remux has no segment layer to wait for the target, so its
    anchor probe is bounded by the seek's first-output window (8 s) minus the
    rebuilt transport's share (3 s): 5 s, not the probe's own 15 s cap. A probe
    that cannot answer returns the retryable transcode_start_failed verdict at
    that bound. A fast failure still leaves room for the bounded retry inside the
    window. Segmented HLS keeps its adaptive budget because its segment layer can
    wait or restart for the requested segment.
  • A seek replacement keeps the play intent sampled when the seek was sent, so a
    pause forced by tearing down the old transport cannot hand the replacement
    shouldAutoPlay=false. The controls also stop claiming to play when a seek
    replacement attaches, until its own play event.
  • The player shows the same Try again card for a replan the server marked
    retryable as it does for a refused start, including on the seek path. It
    pauses the surviving stream and puts the controls back on the seek's origin,
    not the target that never played. A refused subtitle pick keeps its menu
    toast.
  • The refused seek keeps its own retry card: a queued track_change no longer
    fires as the replan settles and clears it. The card stays until a new seek, a
    real failure, or its own fresh start. The retry it offers is the known
    limitation described above.

can_seek_anywhere is unchanged, there is no /api/v1 change, and subtitle
delivery is untouched.

Head 8c6cf6000 re-check

The two cells were re-run against the head. The fence and the audio sampling
behave as intended. The audio switch still starts at the copy-video keyframe;
that offset is intended, bounded, and documented below — not an open defect.

tv-seek: what the three requests are

Session 12247eef-aeb6-4c7e-92e2-4ed128f7b1bb, item 1760202, backward seek to
about 22%.

UTC segment token (sgen) result
12:26:04.491 seg_00173.ts ...:5a01800f...:0 (displaced) 412
12:26:06.608 seg_00173.ts ...:5d0011f0...:0 (rebuilt) ERR_ABORTED, first attempt
12:26:06.709 seg_00173.ts ...:5d0011f0...:0 (rebuilt) 200, 996 588 B

The 412 is the fenced token, requested once. The displaced generation's FFmpeg
process was stopped at 12:26:06.574, before either 200, so neither 200 can be
old-generation bytes. In the reproduction the aborted request and the 200 both
carry the rebuilt generation's token: the new transport's first attempt and its
retry. The rebuilt generation may serve the segment under its own token, and it
does. The matrix verdict now treats that single 412 as the expected fence when
the same segment is served under a different sgen; a repeat of the displaced
sgen still fails.

ta-audio: where the 3.69 s comes from

Session 801f11cb-4614-42f1-8046-444c72c089f3, item 1978284, Japanese at
66.919 s.

  • The replan body carries position_seconds: 67.449; the click lands 0.53 s
    after the harness sample at 66.919. The plan's source_start_seconds is
    67.449.
  • The plan's stream_origin_seconds is 63.146, the preceding keyframe, and
    player_start_seconds is 4.303. The first frame is 63.229.
  • The source's keyframes here are 63.146 and then 70.57. A copy-video
    progressive remux cannot start within 1 s of 67.449 without re-encoding the
    leading GOP or changing delivery. The sampling is at the click; the 3.69 s
    is the keyframe pre-roll.

This is intended transport behaviour. The anchor is the last source keyframe at
or before the requested position, so the offset is bounded by the GOP that
contains the click: at most one GOP, not a fixed number of seconds. The client
cannot correct it — any video.currentTime seek on that stream restarts at the
origin. Re-encoding the leading GOP was considered and rejected: it changes the
play method and its CPU cost, and a forward skip to the next keyframe would be
worse for the viewer. Segmented HLS does not carry the same offset because its
segment layer can wait for, or restart at, the target. The invariant is
documented in
docs/architecture/playback-protocol-v3.md §5.

Far-seek latency

The time goes to the anchor probe and the rebuilt transport, not the client
sampler. Same head, same cells:

cell click to first frame replan anchor probe
ds-seek far forward 1.21 s 0.59 s 0.54 s
ds-seek far back 1.51 s 0.95 s 0.89 s
ta-seek far forward 1.88 s 1.01 s 0.93 s
ta-seek far back 2.79 s 0.63 s 0.60 s

The far-back figure includes playing from the keyframe to the target. The
progressive anchor probe is bounded at 5 s. The last commit's server change is
the non-seek position preference; its client changes only affect play intent,
refused-seek cards, and fenced HLS transports. The 4.5 s matrix number was a
cold probe on the same path, not a structural regression. Removing the
pre-roll would require starting at the next keyframe (a forward skip on sparse
GOPs) or changing delivery; both are separate correctness decisions, so this
change leaves the probe and the pre-roll as they are.

Exercisable pr-seek

Use item episode-tvdb-74796-1-2, fileId=1614975 (DTS-HD 1080p virtual;
494047 resolves to the same file), or the same-release substitute 37973
(effective 1614886) when that row is unavailable. Play from the start, wait
until the element is at about 25 s, then scrub to about 919 s (63% of 1462 s).
The copy-video anchor probe on the 4.49 GB remote source exceeds its 5 s
progressive window, the replan answers the retryable transcode_start_failed
verdict, and the player shows Try again with the pre-seek position restored.

1614975 has since been marked failed_at with available=false and its
pinned candidate is gone, so the substitute is the reproducible path. 37985
and 37971 no longer start, and 38193 substitutes 1614887 and completes
the seeks.

Deferred: the retry after the refusal

The card's Try again re-runs the same 5 s anchor probe against the same slow
source and is refused again. A fix was built and reverted in ba74013c8:

  • it granted the viewer-initiated retry the probe's 15 s cap plus the 3 s
    transport reserve (an 18 s first-output window), and it fell back to the
    keyframe origin when the probe still could not answer;
  • on the deployed build it did not converge. The extended window and the
    fallback leaked into non-seek replans: a track_change that replanned in
    203 ms spent a 5 s anchor probe, presented no frame, and left the element
    paused for 24.7 s. The keyframe fallback was taken but the stream ended
    remux produced no output: EOF. When the source could not be resolved at all,
    the retry showed the same card again.

So the retry leg is a known limitation of this change, not a regression it
introduces: before this branch the seek refusals did not exist at all. Fixing it
is its own piece of work, and the harness cell pr-seek-retry already records
the first attempt (fast refusal, one enabled card, position continuity) and the
retry leg separately so the follow-up has a bound to prove against.

Validation

  • go build ./...: passes.
  • gofmt and go vet ./internal/playback ./internal/api/handlers: clean.
  • go test -count=1 ./internal/playback: passes except
    TestResolveCopySeekAnchorRecordsMeasuredProbeCost, a timing-sensitive
    cost-tracker test that failed once and passed on rerun. This diff does not
    touch internal/playback.
  • go test -count=1 ./internal/api/handlers: the same three failures as b9ee2f384:
    TestVirtualMetadataUpdateRecoversEvidenceAfterTransientTimeout,
    TestAggregateSectionsOmitRowsWithNoAccessibleItemsDB, and
    TestPluginUploadSeamsOnRealManager (group-writable TMPDIR); 593 s. The
    final head changes only the retry test fixture path..
  • tsc -b via web/scripts/typecheck.mjs: clean.
  • vitest run src/player/components/VideoPlayer.test.tsx src/player/hooks/usePlaybackSession.test.ts: 514 passed.
  • BASE_REF=b9ee2f384 make lint-changed: 0 issues.
  • make verify-local-paths: passes.
  • Head: ba74013c85911ccb1ce5c1e934f7086b52476317 (revert(playback): defer the seek-anchor retry round).
  • Image: Docker Image run 44940572215:
    ghcr.io/kipsilabs/vio:ba74013c85911ccb1ce5c1e934f7086b52476317 and
    ...-base, multi-arch.
  • CI on ba74013c8: green.
  • Deployed as that tag and confirmed by the matrix: the audio switch replans in
    212 ms and plays at −3.68 s (inside one GOP), all seven regression cells
    pass, and the retry cell records known-limitation.

Tests added: a 412 with a pending seek stops the transport and answers exactly
one reanchor request; a reanchored transport autoplays and does not claim to
play before it; a refused seek shows Try again with the position restored; a
progressive anchor that cannot answer fails inside its seek window with one
bounded probe; a fast transient failure still reserves its retry; a stopped
fenced transport restarts when the reanchor reuses its generation; a rebuilt
generation loads its own playlist under its own token; an audio switch carries
the click position instead of the last progress sample.

Risks

A progressive-remux seek whose anchor genuinely needs more than 5 s fails its
first attempt with the retryable verdict instead of succeeding late. That is the
requested trade. The retry the card offers is a known limitation: it re-runs the
same probe and can be refused again. Fixing that is deferred, because the
attempt to fix it leaked into non-seek replans and broke the audio switch.

The player now pauses the old stream when it shows a retryable refused-replan
card. The card covers the player, so letting audio continue behind it would
leave the visible position disagreeing with playback.

A progressive copy-video start begins at the preceding keyframe, so an audio
switch in the middle of a long GOP presents up to one GOP of earlier content.
That is intended and bounded by the source GOP; removing it needs a delivery
change or a re-encoded leading GOP, a separate play-method decision that does
not belong in this fence-and-retry fix.

Checklist

  • I read and can explain the complete diff.
  • This pull request addresses one concern.
  • Each test this pull request adds meets "Decide what to test" in CONTRIBUTING.md.
  • The Evidence section shows every change a user can see, or says there is none.

AI Disclosure

  • Harness: OpenCode
  • Tool(s): OpenCode agent (shell, read/edit, execute, subagent)
  • Model(s): ollama-cloud/deepseek-v4.1-flash:1017
  • Involvement: Fully AI-generated (maintainer review and merge pending)
  • Adversarial review: n/a

… anchor-less remux start

A seek that restarts an HLS generation in place leaves the plan the client
holds advertising the window from before the restart. The next backward seek
requested a segment below where the new generation begins and got 412 four
times; the client then refetched the playlist and clamped the playhead forward
(328 s to 931 s in production).

- Reject the reuse of a live HLS generation for a seek target before that
  generation's own start, so the server rebuilds the transport at the target
  instead of serving a playlist that begins past it.
- Translate a 412 for a pending seek into a seek_reanchor at the target
  instead of retrying the dead URL or refetching a playlist that would clamp
  it. A 412 during ordinary playback now refetches the playlist with the live
  sgen token, bounded to two attempts.

A progressive remux start that cannot resolve its copy seek anchor degraded to
an unanchored stream that produced no bytes for 15 s and froze the playhead.

- Answer the existing retryable seek terminal instead of returning that plan;
  the start path already carries Retry-After, and the next attempt is sized
  from the probe cost just recorded. Segmented HLS keeps its degrade because
  its segment layer can wait or restart for the target.
- Bound a progressive remux replacement started for a seek to the same
  first-output window; a stream that produces nothing now surfaces a retry
  instead of leaving the playhead on the target.

Tests: a backward seek after an in-place restart rebuilds at the requested
position; a 412 with a pending seek reanchors and does not refetch the
playlist; a 412 during playback refetches it; an anchor-less progressive remux
start refuses with a retryable seek error. Existing progressive Range,
anchor-budget and seek tests still pass.
…or by its seek window

The af63a08 matrix run narrowed both seek failures but left four defects.

A 412 on the segment route is the server's generation fence. With a pending
seek the client reanchored, but hls.js had already queued its own retry of the
same fragment, so the dead URL was requested twice and its second answer fell
through to the ordinary playlist refetch. On a restarted generation that
refetch seeks to the element's media position on the playlist's own clock,
which asked for seg_00346 (692 s) while the target was 346 s and left the
picture frozen for 35 s. hls.js is now stopped on the first 412, a pending seek
never refetches the fenced playlist, and an in-place reanchor that reuses the
generation refetches it once with the live token and the target on restart.

A progressive remux has no segment layer to wait for the target, so its anchor
probe is bounded by the seek's first-output window (8 s) minus the rebuilt
transport's share (3 s), not by the probe's own 15 s cap. A probe that cannot
answer now returns the retryable transcode_start_failed verdict at the 5 s
probe bound instead of after 15-25 s; segmented HLS keeps its adaptive budget.

The seek path also had no retry affordance: the player only surfaced a replan
error it could attribute to a transport it had torn down. A seek the server
refused with a retryable terminal left the old picture and the target on the
controls. It now shows the same Try again card as a refused start, pauses the
surviving stream, and puts the position back on the seek's origin. A seek
replacement also keeps the play intent sampled at request time, so a pause the
teardown forces cannot hand it shouldAutoPlay=false, and the controls stop
claiming to play until the replacement's own play event.

Tests: a 412 with a pending seek stops the transport and answers exactly one
reanchor request; a reanchored transport autoplays and does not claim to play
before it; a refused seek shows Try again with the position restored; a
progressive anchor that cannot answer fails inside its seek window with one
bounded probe; a fast transient failure still reserves its retry. Existing seek,
Range, and anchor-budget tests pass.
The 09378d9 matrix left five residuals on the seek-fix build.

A rapid run of backward reanchors replaced the transport several times. Each replacement paused the element while it loaded, and the next seek sampled that pause as the viewer's intent, handing the following replacement shouldAutoPlay=false: ds-seek and ta-seek ended loaded but paused with nothing on screen explaining it. The player now carries the viewer's play/pause intent sampled when the seek is issued, and the session uses it instead of the transient element state.

A refused reanchor showed no retry because a queued track_change (a held pick or a no-op inventory refresh) fired as soon as the seek replan settled, clearing the error, and then held the client for 20-30s. While a retryable refused-seek card is up, automatic track, quality and output replans are held, and a default-audio invalidation is acknowledged without replacing the card. A new seek, a real failure, or the card's fresh start releases it.

A 412 on a fenced segment stopped hls.js, but a planRevision effect restarted the stopped instance to refetch its playlist before the asynchronous replacement existed. That second request asked for the same fenced segment and was aborted by the replacement. The restart now requires the same stream URL and transport revision, so a rebuilt generation never re-requests the fence.

An audio switch restarted 10s behind the viewer because a non-seek replan preferred the session's last progress report (up to 10s old) over the client's live position. The client's position now wins when it is at least as far along as the session; a value behind the session is still treated as a stale snapshot.

The pr-seek start latency (6442ms) is the initial watch-detail fetch plus start request, not the seek-anchor probe; the probe bound only affects seek reanchors. The ta-sub first cue at 12.1s is the next dialogue line in a window whose extraction took 27ms, not provider or client latency.

Tests: rapid backward seeks keep carrying play intent; a refused seek keeps its retry card instead of dispatching a queued track change or default-audio reconcile; a reanchor that builds a new generation does not refetch the stopped transport; a fresh client playhead wins over the last progress sample. Existing seek, Range, anchor-budget and audio-replan tests pass.
The tv-seek re-check shows the fenced token requested once (412), then the rebuilt generation requesting the same segment under its own token. Assert that the replacement loads its own playlist, so the allowed direction is covered alongside the existing no-refetch test.

The ta-audio re-check shows the replan carries the click position, not the last progress sample. Assert the audio switch sends that position.
@randrini
randrini force-pushed the fix/seek-after-restart branch from 8c937f9 to 646dc23 Compare November 21, 2026 15:11
A copy-video transport starts at the preceding source keyframe, so an audio switch that rebuilds onto a progressive copy remux presents up to one GOP of earlier content. Record that as a transport invariant with its bound, the client's obligation not to seek it away, the HLS exemption, and why re-encoding the leading GOP was rejected.
@randrini
randrini force-pushed the fix/seek-after-restart branch from 646dc23 to 27275a1 Compare November 21, 2026 15:18
A retryable copy-video seek-anchor refusal offers the viewer one Try again.
The fresh start that button issues was treated as another first attempt: it
got the same 5 s progressive probe window and, when that expired, the same
card a second time. The user took the only affordance offered, waited another
5 s, and landed on the same wall.

- Record the retryable refusal this handler answered, keyed by profile and
  requested file, and treat the next start for that pair as the viewer's
  retry. The mark is cleared by a successful timeline and expires after two
  minutes.
- Grant the retry the probe's full 15 s cap instead of the first attempt's
  5 s window, with the same 3 s transport reserve. The 18 s retry window stays
  inside the 43 s start phase and the 45 s client abort. Log it separately with
  the granted budget.
- If the retry's probe still cannot anchor, start the copy stream from the
  keyframe FFmpeg's input seek resolves instead of refusing again. The
  unanchored plan keeps the requested position as its origin, so the client
  cannot jump forward; the pre-roll is the documented up-to-one-GOP offset.
- The first attempt keeps its fast 5 s refusal and one card. A retry never
  returns the same seek refusal: it either plays or answers a different
  failure.
The retry state-transition test exercises a real timed-out probe, which
records a probe-cost lower bound in the playback package's process-wide tracker.
Use a source identity no other handler test anchors on so that 15 s mark cannot
size a later test's probe budget.
The retry card can stay on screen longer than a couple of minutes. Keep the
refusal mark long enough for the viewer to come back to it, bounded and cleared
by a successful timeline so an old refusal cannot shape a much later start.
The retry round granted a viewer-initiated retry a longer probe window and a
keyframe-origin fallback. On the deployed build it did not converge:

- the extended window and the fallback leaked into non-seek replans, so a
  track_change that replanned in 203 ms spent a 5 s anchor probe, presented no
  frame, and left the element paused for 24.7 s;
- the keyframe fallback was taken but the stream ended 'remux produced no
  output: EOF', so the viewer got no frame;
- when the source could not be resolved at all, the retry showed the same card
  again.

It also lost ground against 8c6cf60 and a8a714a, which are verified: the
silent pause after repeated backward seeks is fixed, the fence is handled once,
the audio switch plays with its documented one-GOP offset, and the position
sampling is correct. This restores that behaviour and drops only the retry
attempt. The retry dead end is a known limitation to address separately, not by
stacking another patch on a branch that is losing ground.

The keyframe-anchor decision stays documented in
docs/architecture/playback-protocol-v3.md section 5.
@randrini
randrini marked this pull request as ready for review November 21, 2026 20:35
@randrini
randrini merged commit 0cfc771 into main Nov 21, 2026
17 checks passed
@randrini
randrini deleted the fix/seek-after-restart branch November 27, 2026 13:05
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.

1 participant