Skip to content

fix(playback): demux a subtitle window the file's index can't read in time - #4272

Merged
Quick104 merged 1 commit into
mainfrom
fix/issue-4199
Nov 15, 2026
Merged

Quick104 merged 1 commit into
mainfrom
fix/issue-4199

Conversation

@Quick104

@Quick104 Quick104 commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Closes #4199
Related issue: N/A
Validation tasks: none

Other clients: Apple N/A, Android N/A, Roku N/A (server-side fix; a client that requests subtitle windows gets it without a change)

With an embedded PGS subtitle selected, the web player stalls on large files that sit on storage where a random read is slow, such as a FUSE mount of remote storage with a local read cache. Subtitle windows come back empty after 30 seconds, and the video stutters or never starts.

A 600-second subtitle window was read through the file's index: one random read per cue, about 200 cues per window, with nothing written to the response until every read finished. At about a second per read that takes minutes. The web player gives up on a window that sends nothing for 30 seconds. The background warm that followed then read every cue of the whole track the same way, and those random reads starved the playback stream reading the same file.

This change gives a window with a duration 10 seconds to come from the kept track or the index. After that the window is demuxed with FFmpeg, which reads the file in order and streams cues as it goes. A PGS window that gave up this way warms the cached .sup with a demux too, instead of reading the whole track through the index. On storage with fast random reads nothing changes: a window still reads in well under a second.

Approach

  • SubtitleCache.window bounds the read with context.WithTimeoutCause, so only its own 10-second bound counts as slow; a client that leaves is handled as before.
  • serveWindowedSUP warms with demuxAndKeep when the window gave up on that bound, and with sourced otherwise, as before. The demux keeps the track, so later windows come from the kept track and don't touch the source's index.
  • Not bounded: windows open to the end (they read the track whole and keep their existing wait), tracks only the index can read (Matroska S_TEXT/WEBVTT, which have no demux to fall back to), and on-demand HLS rendition windows, which don't go through the subtitle cache.
  • docs/architecture/embedded-subtitle-index.md describes the bound.

Validation

  • Reproduced live on an isolated sandbox at 9d432cf09 (current main): direct play of a 7.3 GB, 40 Mbit/s H.264 file with a PGS track, its library on a FUSE mount that models remote storage with a read cache (a cold random read about 0.8 s, sequential reads about 30-40 MB/s, shared bandwidth, fetched blocks cached). A client that behaves like the web player (30-second stall timeout, the player's retry backoff) and reads the media stream ran for 150 seconds from a cold state, alternating builds:

    Build First 600-second window Video received by 120 s (median of 3, range)
    main nothing in 30 s, aborted; the retries got a few kilobytes or nothing 33 s (31–34)
    this change first byte at about 18 s, then the whole window (2.2 MB) 861 s (860–864)

    On main the server log shows the same sequence as the report: the first window answered 200 with 0 bytes after 35 seconds, the warm started at that moment, and 90 seconds later it gave way with keptsub: the track is still being read while the modelled storage had pulled about 4 GB through hundreds of random-read streams. With the fix the warm starts 10 seconds after the window request and the storage settles to one or two sequential streams.

  • A window for a seek, sent 60 seconds in while the warm was still reading the file, sent its first byte 20 seconds after the request with the fix and nothing in 30 seconds on main.

  • A new test fails on main with an empty response at the client's 30-second mark and passes with the fix; it also covers the index-only exemption.

  • Go build, vet, gofmt, go mod tidy -diff, make lint-changed, make lint-router-recovery, make verify-local-paths and make verify-size-ratchet pass. make test-go passes except TestCopyRemuxSubtitleRenditionRealFFmpeg and TestRunStatsWithRealFFmpeg, which fail the same way on main with the test host's FFmpeg 6.1. Database-backed tests were skipped; the change touches no database code. Web and contract checks don't apply; nothing under web/ or contracts/ changed.

  • The browser itself wasn't driven: the measurements come from the API client above and the server log.

Evidence: https://evidence.siloserver.org/r/silo-server/issue-4199/

Risks

  • The 10-second bound is a judgement: long enough for a window on healthy storage, short enough to leave the web player 20 seconds to receive the demux's first cue. A window on storage that is merely slow but under 10 seconds still reads through the index.
  • While the first demux warm runs (minutes on such storage), each seek's window waits the 10 seconds again before it demuxes.
  • A kept track whose local copy takes more than 10 seconds to fetch from blob storage now has its window demuxed and its track kept again by a demux warm, once per node, as every warm did before tracks were read through the index. The warm demux takes no cross-node claim, so on a cluster each node that serves such a window can run one, bounded by its warm slots.

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 how I checked a change nobody sees.

Follow-ups

  • Whole-track reads through the index (sidecar requests without a window, jellycompat track requests and its playback warm, the subtitle prefetch) can still starve playback on such storage. On main a whole-track PGS request on the same setup got nothing for four attempts while the playback stream received 46 seconds of video in 120. This change leaves that path alone; a separate fix follows.
  • User manual: unaffected; it doesn't describe subtitle window timing or storage behaviour.

AI Disclosure

  • Harness: Claude Code in T3 Code
  • Tool(s): Claude Code; Codex (plan review)
  • Model(s): claude-opus-5-5 (implementation, plan review, code review); gpt-6.1-sol (plan review); claude-sonnet-5-5 (code review)
  • Involvement: Fully AI-generated; human review pending
  • Adversarial review: Before implementation, gpt-6.1-sol attacked the plan and claude-opus-5-5 cut it. That dropped a per-file "slow source" memory in keptsub in favour of the demux warm, and added the index-only and open-ended exemptions and the cause-specific bound. A multi-agent code review at high effort checked the diff, its callers, failure modes and conventions; it led to keeping the source's error under the slow-read sentinel, scoping the doc to sidecar windows, and the risks above. A simplify pass ran on the change. A background adversarial review (gpt-6.1-sol) of this head checked cancellation, the warm choice, every caller and the clients, and found nothing.

🤖 Generated with Claude Code

Note

Fix slow embedded-subtitle window reads by falling back to demux after 10s

  • Bounded window reads through the embedded subtitle index now wait at most subtitleWindowIndexWait (10 seconds) before giving up, tracked via a new errSlowWindowRead sentinel in subtitle_source.go
  • When a slow-read sentinel is returned, SubtitleCache.serveWindowedSUP in subtitle_cache.go falls through to extraction and warms the cached track with demuxAndKeep instead of reading the whole track through the index
  • Index-only tracks and windows without a duration keep their existing unbounded read behavior; source errors from serveWindowFromSource now propagate to the caller
  • Updates the architecture doc in embedded-subtitle-index.md and adds a regression test covering slow PGS, slow text, and delayed index-only windows
  • Behavioral Change: SubtitleCache.window now returns a packet-and-error pair instead of packet only; callers must handle the error result

Macroscope summarized 5c31510.

… time

A window with a duration now waits at most 10 seconds for the kept track or
the file's index, then demuxes the source, which streams cues as it goes. On
storage where each random read costs about a second, reading one 600-second
window through the index took minutes, so the web player gave up after 30
seconds with nothing.

A PGS window that gave up this way warms the cached .sup with a demux
instead of reading the whole track through the index, whose random reads
starved the playback stream reading the same file. Windows open to the end
and tracks only the index can read keep waiting as before.

Closes #4199

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@silo-triage silo-triage Bot added the size/M 50–199 added + deleted lines (all files); change volume, not priority. label Nov 15, 2026
@coderabbitai

coderabbitai Bot commented Nov 15, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

  • Ask an admin to enable usage-based reviews

Open in CodeRabbit

Reviews can continue after your included limit without a manual trigger. An admin must approve usage-based billing.

Next included review available in 25 seconds.

Check out review usage here.

View limit details

Limit details: You’ve used all 4 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: ea898198-042b-4028-962c-041b8ee82fdd
Commits

Reviewing files that changed from the base of the PR and between 4126597 and 5c31510.

Files selected for processing: 4

  • docs/architecture/embedded-subtitle-index.md
  • internal/playback/subtitle_cache.go
  • internal/playback/subtitle_source.go
  • internal/playback/subtitle_source_test.go
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-15T03:02:33.116647Z 5c31510 PR opened
🔒 Security Review ✅ Completed 2026-11-15T03:04:05.802100Z 5c31510 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@silo-kody

silo-kody Bot commented Nov 15, 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 bug Something isn't working go Pull requests that update go code impact: playback Can't play, stalls, or wrong media priority: P1 Core-path bug; painful workaround — next after P0 labels Nov 15, 2026
@Quick104
Quick104 merged commit 7115ee7 into main Nov 15, 2026
18 checks passed
@Quick104
Quick104 deleted the fix/issue-4199 branch November 15, 2026 03:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working go Pull requests that update go code impact: playback Can't play, stalls, or wrong media priority: P1 Core-path bug; painful workaround — next after P0 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 stalls with an embedded PGS track on uncached remuxes on network storage

1 participant