Skip to content

fix(web): keep a seek made while a quality change loads - #3988

Merged
Quick104 merged 2 commits into
Silo-Server:mainfrom
Rhainland:fix/3541-hls-backward-seek-reload
Nov 12, 2026
Merged

Quick104 merged 2 commits into
Silo-Server:mainfrom
Rhainland:fix/3541-hls-backward-seek-reload

Conversation

@Rhainland

@Rhainland Rhainland commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Closes #3541
Related issue: N/A
Validation tasks: changes #199 (in-player controls: seek/scrub); no recorded case results on #199 yet

In the web player on Chrome (hls.js), a seek made right after picking a new quality or audio track was undone. Playback jumped back to where the quality change was made once the new stream started. Safari's native HLS path had the same gap. Since #3508 the seek bar stays usable during that reload, so viewers can reach this.

The window that loses the seek is the replan request itself: the old stream is still playing, completes the seek, and then the new plan starts at its player_start_seconds, which is the position the quality change was asked for. A seek made after the new hls.js instance attaches was already kept, because hls.js moves its start position when the element seeks before the first fragment is buffered.

Approach

VideoPlayer remembers the viewer's newest seek made while a replan of the session is in flight. The first transport of the plan that replaces it starts there instead of at the plan's start position: as the hls.js startPosition, and as the native HLS position at loadedmetadata. A seek still in flight when the new stream starts takes precedence, as before. The same rules as #3508 apply: only on a plan that can seek anywhere, and a watch-party seek request the room has not run yet still waits for the room's command.

A replan that settles without a new stream, a later seek, or a new session (version switch, next episode) drops the remembered seek, so a later quality change starts where it was asked for.

A quality change that lands a direct-play or progressive-remux plan still starts at the plan's position, as before; this change covers the two HLS paths the issue names.

Web only. No API, server, or client app changes.

Validation

  • Reproduced on a local build of main in headless Chromium on the production bundle, with a synthetic 1080p H.264 file playing direct: seek to 150 s, pick 720p, click the seek bar at 60 s while the replan is in flight. The new hls.js stream started at 152 s. On this branch it starts at 60 s. This happened both with the replan response held for 3 s and with no throttling (seek 150 ms after picking the quality).
  • Neighbouring cases on the same build: a quality change with no seek still resumes at the quality-change position (152 s), and a seek made after the new stream attaches is still kept.
  • Component tests cover the hls.js start position and the native HLS position after a seek during a replan, and that a replan settling without a new stream drops the seek.
  • Review fix (347f5fa): the remembered seek becomes the new stream's pending seek, so a second quality or audio change, or a startup recovery, made before the new stream plays also resumes at the seek. Its component test fails on 84856cd and passes on 347f5fa. The recordings below predate this commit.
  • pnpm run lint, pnpm run format:check, pnpm run build, pnpm run budget:check, tsc, and make test-web pass. No Go code changed, so the Go half of the gate was not run.

Evidence

Evidence: https://evidence.siloserver.org/r/silo-server/pr-3988/

Surface and build: web app player at 1440px, recordings of the same steps on a local build of main and of this branch. Position log excerpt (element currentTime in seconds):

before: quality change at 151.8 -> seek bar click at 60.0 -> new stream plays from 152.1
after:  quality change at 151.8 -> seek bar click at 60.0 -> new stream plays from 60.0

Phone width is unaffected: the change is in the player's stream start position, not its layout.

Risks

None identified. A queued second quality or track change still undoes the seek once it lands; that also happens on main and is tracked in #4010.

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: Claude Code (via T3 Code); Codex CLI for code review
  • Tool(s): Claude Code, Codex CLI, GitHub CLI, Playwright (headless Chromium)
  • Model(s): claude-opus-5-5; gpt-6.1-sol (code review)
  • Involvement: Fully AI-generated, human verified
  • Adversarial review: independent reviews by claude-opus-5-5 and gpt-6.1-sol of the full diff (correctness, standards, spec). GPT found nothing. Opus noted one low-severity gap: a seek during a replan that lands a direct-play or progressive-remux plan is still undone, as it was before. It is left out of scope because the issue covers the HLS paths, and the Approach section says so. No code changed after the review.

Note

Preserve seeks made during a quality change in VideoPlayer

  • Records a seek accepted while replanning is in progress (session ID, plan revision, position) in VideoPlayer.tsx, and consumes it as the start position of the replacement stream when the revision changes for the same session
  • Centralizes HLS start-position selection and applies it to both native HLS metadata handling and the hls.js startPosition option
  • A seek held for a room command does not override the plan start position, and a saved replan seek is discarded if replanning settles without a revision change
  • Adds tests in VideoPlayer.test.tsx covering hls.js, native HLS, quality forwarding, and the discard path

Macroscope summarized 347f5fa.

On a seek-anywhere plan, a seek made while a replan of the session was in
flight was undone when the new stream started: the stream began at the
position where the quality change was asked for. The new HLS transport
(hls.js and native) now starts at that seek, or at a seek still in flight,
unless it is a room request the room has not run yet.
@coderabbitai

coderabbitai Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor
Pre-merge checks: Inconclusive 2

Failed Failed checks: 2 inconclusive

Check name Status Explanation Resolution
Title check Pending This assessment has not completed. The check will be retried on the next pre-merge check run.
Description check Pending This assessment has not completed. The check will be retried on the next pre-merge check run.
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@silo-kody

silo-kody Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.

Reviewing changes in Silo
  • Include the related issue, expected behavior, and validation steps in the PR description.
  • For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
  • For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
  • Follow this repository's AGENTS.md and CONTRIBUTING.md.
  • Request another review with @kody start-review in a PR comment.
  • React with 👍 or 👎 to give feedback on individual suggestions.
Review settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌

@silo-triage silo-triage Bot added the size/M 50–199 added + deleted lines (all files); change volume, not priority. label Nov 11, 2026
Comment on lines +2789 to +2791
const seconds = canSeekAnywhereRef.current
? (pendingSeekTimeRef.current ?? seekDuringReplan)
: null;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kody code-review Bug medium

Saved seeks are discarded when the replacement is a copy-remux plan

A seek completed during a replan is lost because copy-remux HLS plans set can_seek_anywhere to false. Reanchor the replacement plan when its timeline cannot represent the saved target.

Prompt for LLM
File web/src/player/components/VideoPlayer.tsx, lines 2789-2791:

Saved seeks are discarded when the replacement is a copy-remux plan

A seek completed during a replan is discarded when the replacement is a copy-remux HLS plan, because those plans set `can_seek_anywhere` to false even if the target is seekable in the old stream. Preserve the target by reanchoring the replacement plan when its timeline cannot represent the saved seek.

Talk to Kody by mentioning @kody

Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.

​

​

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not changing this here. On main, the same seek is also lost when the replacement plan can't seek anywhere. This PR keeps the existing #3508 rule that a saved seek only carries over to seek-anywhere plans, and the PR body names the copy-remux and direct-play case as out of scope. Re-anchoring a copy-remux plan on the seek target would change how those plans are requested.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. The copy-remux case is a pre-existing limitation, and re-anchoring its plan would change request behavior beyond this PR’s stated scope. I’ll withdraw the suggestion for this PR.

The limitation may be worth tracking separately if preserving seeks across non-seek-anywhere replans is a future goal.

Comment on lines +2788 to +2790
const hlsStartPosition = () => {
const seconds = canSeekAnywhereRef.current
? (pendingSeekTimeRef.current ?? seekDuringReplan)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kody code-review Bug medium

A newer seek can be overwritten by the captured replan seek

A newer seek can clear pendingSeekTimeRef before native HLS metadata loads, causing the handler to jump back to the older seekDuringReplan target. Invalidate or update seekDuringReplan when a newer seek occurs.

Prompt for LLM
File web/src/player/components/VideoPlayer.tsx, lines 2788-2790:

A newer seek can be overwritten by the captured replan seek

A second seek made after the replacement is adopted but before native HLS metadata loads can settle and clear `pendingSeekTimeRef`, leaving `seekDuringReplan` holding the older target. The metadata handler then jumps back to that older target, so invalidate or update the captured replan target when a newer seek occurs.

Talk to Kody by mentioning @kody

Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.

​

​

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't happen. On native HLS, a seek made after the new src is set and before loadedmetadata can't finish: with no metadata the element has nothing to seek in, so it fires no seeked and pendingSeekTimeRef still holds the newer target when the handler runs. Only a viewer seek or the planRevision reset writes that ref in that window, and the reset runs in the commit that attaches the stream, before any later seek. Since 347f5fa the remembered seek is itself the pending seek, and any later seek replaces it, so the handler has no older value to fall back to.

🤖 Claude Code (claude-opus-5-5)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You’re right; I withdraw the suggestion. The current PR diff no longer captures seekDuringReplan as a fallback for the native HLS metadata handler. It transfers the remembered seek into pendingSeekTimeRef, and hlsStartPosition() reads that ref when metadata loads. A later seek can therefore replace the remembered target without the handler falling back to the older value.

I reviewed the current diff; I did not independently verify Safari’s event timing.

…g seek

The replanned stream started at the seek, but until it played the player
still reported the plan's start as its position. A second quality or
audio change, or a recovery replan, made in that window resumed there and
undid the seek again. The remembered seek is now the new transport's
pending seek, the same state a seek made while the stream loads uses, so
the start position and the replan position agree.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@Quick104 Quick104 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One finding on the head, which I'm fixing in a commit on this branch, so there's no need to change it yourself. The approach holds: the seek is lost while the replan request is in flight, and starting the replacement stream there is the right place to fix it. Summary and scores follow in a separate comment.

🤖 Claude Code (claude-opus-5-5)

@silo-kody

silo-kody Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.

Reviewing changes in Silo
  • Include the related issue, expected behavior, and validation steps in the PR description.
  • For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
  • For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
  • Follow this repository's AGENTS.md and CONTRIBUTING.md.
  • Request another review with @kody start-review in a PR comment.
  • React with 👍 or 👎 to give feedback on individual suggestions.
Review settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌

@Quick104

Copy link
Copy Markdown
Contributor

Review summary

Reviewed head: 347f5fa (the contributor's 84856cd plus one review fix).

Fit: 9/10 · Readiness: 8/10 — conditional

The seek is lost while the replan request is in flight, and the fix belongs in the web player, where the new stream's start position is chosen. It is small, adds no settings or API surface, and fixes a core playback control that #3508 made reachable. Readiness is 8 because the review fix hasn't been checked in a browser yet. Its component test failed on the previous head and passes now, but the live recording on the evidence page predates it. A rerun of the same hls.js steps on this head would make it ready.

Addressed

  • The player still reported the plan's start as its position until the new stream played. A second quality or audio change, or a startup recovery replan, in that window resumed at the plan's start and undid the seek again. Fixed in 347f5fa: the remembered seek becomes the new transport's pending seek, the same state a seek made while the stream loads already uses.

Tests

  • starts the hls.js stream at the seek and starts the native HLS stream at the seek fail on main (the stream starts at 120 instead of 30) and pass here.
  • forgets the seek when the replan settles without a new stream passes on main too. It guards the refusal path rather than proving the fix.
  • resumes another quality change at the seek before the new stream plays (added in review) fails on 84856cd (sent 120 instead of 30) and passes on 347f5fa.
  • All 253 tests in VideoPlayer.test.tsx and the full src/player suite pass. eslint, prettier and the app typecheck are clean.

Left for the maintainers

  • Queued replans: if a second quality or track change is queued behind the first, the queued request keeps the position it was made at and undoes the seek once it lands. This happens on main as well, and the fix belongs in the session's replan queue, so it is tracked in [bug] Web player: a queued second quality or track change undoes a seek made during the first #4010 rather than here.
  • Direct-play and progressive-remux replacement plans still start at the plan's position, as the PR body says. This is unchanged from main.
  • Kody's comment about a newer native-HLS seek being overwritten doesn't hold up. The reply in that thread has the trace.

Validated features

Unavailable: the 1.0 validation board couldn't be read from this review, so the PR body's Validation tasks: line (changes #199) is unverified.

User manual

No change needed. The manual's Quality section doesn't describe what happens to a seek during a quality change, and this makes the player do what a viewer expects.

Apple and Android

This is a web-only fix to the web player. Whether the Apple and Android players lose a seek during a quality change wasn't checked in this review.

Review method

claude-opus-5-5 traced the code, ran a multi-pass code review, and checked the PR's tests against main. gpt-6.1-sol ran an independent adversarial review of 84856cd. Both found the replan-position gap fixed here and the queued-replan case filed as #4010.

🤖 Claude Code (claude-opus-5-5)

canSeekAnywhereRef.current &&
seconds !== roomHeldSeekRef.current
) {
rememberPendingSeek(seconds);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kody code-review Bug high

Promoted seek remains pending when the replacement uses the browser engine

Revises an earlier Kody suggestion on web/src/player/components/VideoPlayer.tsx:2789 (2026-11-11 17:49 UTC).

Playback starts at the wrong position while the pending seek and displayed position remain stuck at the old target. Apply the promoted target after attachBrowserEngine completes, or restrict promotion to transports that consume it.

Prompt for LLM
File web/src/player/components/VideoPlayer.tsx, line 2790:

**Revises an earlier Kody suggestion** on `web/src/player/components/VideoPlayer.tsx:2789` (2026-11-11 17:49 UTC).

Promoted seek remains pending when the replacement uses the browser engine

When the replacement uses the browser decode engine, the promoted target is never passed to `attachBrowserEngine`, so playback starts elsewhere while the pending seek and displayed position remain stuck at the old target. Apply the promoted target to the engine after attachment or restrict this promotion to transports that actually consume it.

Talk to Kody by mentioning @kody

Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.

​

​

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

Labels

size/M 50–199 added + deleted lines (all files); change volume, not priority.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] Web player on hls.js undoes a backward seek made while a quality change reloads the stream

2 participants