Repository navigation
fix(playback): keep subtitle rendition cues when a session is rebuilt - #2690
Conversation
Silo Kody — review completeReview finished. Check the inline comments for findings and verify each suggestion against the code and tests. Reviewing changes in Silo
Review settingsReview OptionsThe following review options are enabled or disabled:
|
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 26 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
The rebuilt playback now shows subtitle cues for earlier video segments, but the Evidence section has no captures or recording; add before-and-after playback evidence from a client that requests subtitle renditions, and identify the surface and builds. Automated check: Macroscope check run agent (gpt-6-luna). Evidence was not reviewed for correctness. Posted via Macroscope — Visible change evidence |
| opts := s.opts | ||
| record := subtitleSpanRecord{Track: opts.SubtitleTrackIndex, SegmentDuration: renditionSegmentDuration(opts)} | ||
| for _, span := range s.subtitleSpans { | ||
| row := subtitleSpanRecordRow{File: span.file, Start: span.start, End: span.end} |
There was a problem hiding this comment.
Timestamp mapping loss in internal/playback/subtitle_rendition.go occurs because subtitleSpanRecordRow discards cached origin/originKnown, so reconstruction loses an earlier generation’s mapping when a later span causes subtitleSpanOrigin to reject both probe candidates via subtitleSegmentRewrittenLocked. After an observed span covering 0–100 and a later span starting at 50, requesting preserved segment 80 after reconstruction falls back to the zero-clock grid and selects incorrect or empty cues for a nonzero-clock source; persist and restore known origins with each span.
Prompt for LLM
File internal/playback/subtitle_rendition.go:
Line 275:
Timestamp mapping loss in internal/playback/subtitle_rendition.go occurs because subtitleSpanRecordRow discards cached origin/originKnown, so reconstruction loses an earlier generation’s mapping when a later span causes subtitleSpanOrigin to reject both probe candidates via subtitleSegmentRewrittenLocked. After an observed span covering 0–100 and a later span starting at 50, requesting preserved segment 80 after reconstruction falls back to the zero-clock grid and selects incorrect or empty cues for a nonzero-clock source; persist and restore known origins with each span.
Talk to Kody by mentioning @kody
Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.
There was a problem hiding this comment.
Confirmed and fixed in 917b886. A rebuilt session could not observe an earlier span's origin again once a later generation had started at or before that span's start. For example, segments 50–100 are encoded, the user seeks back to 40, and the node dies at 60. Each span's observed origin is now stored in the span record and restored on rebuild, and a regression test covers that sequence. 1c3c13a also makes Close wait for a late record write before it removes the output directory.
There was a problem hiding this comment.
Thanks for confirming. Persisting and restoring each span’s observed origin addresses the reported mapping loss when later generations prevent re-observation, and the regression test covers that sequence. The additional Close synchronization addresses the late-write cleanup race.
Based on your description, this finding is addressed by 917b88618, with the cleanup fix in 1c3c13a7a. I haven’t independently reviewed those commits.
Silo Kody — review completeReview finished. Check the inline comments for findings and verify each suggestion against the code and tests. Reviewing changes in Silo
Review settingsReview OptionsThe following review options are enabled or disabled:
|
A transcode session rebuilt from its recipe on the same output directory (after the server that ran it exited without removing it) serves the earlier process's video segments from disk, but only knew its own subtitle span, so those segments' subtitle rendition segments came back as empty WebVTT. The rebuilt process also numbered cue files from 0 and overwrote the earlier process's subtitles_0.vtt. Record each generation's cue file and finished segments in subtitle_spans.json when a generation starts and closes, read it back in StartTranscode before FFmpeg starts, and number the rebuilt session's cue files after the recorded ones. Spans whose cue file is gone, or whose live generation never wrote its own playlist, are dropped. Closes Silo-Server#2650
A rebuilt session could not observe the origin of an earlier span again when a later generation started at or before that span's start, so its cues fell back to the zero-clock grid on a source whose clock does not start at zero. Record each observed origin with its span and restore it on rebuild.
…irectory An origin probe can save the span record after the request that started it, so the save could land in the output directory while Close was removing it. Close now holds the record lock while it removes the directory, and the save skips once the directory is gone.
A rebuilt session read any stream.m3u8 that didn't match the recorded inherited playlist as the live generation's progress. After a failed record write, a later generation's playlist was credited to the stale live row, and its cue segments were served as ready. A generation's own playlist starts at its -start_number, so require the first listed segment to equal the row's start. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1c3c13a to
1c7a2ce
Compare
Review summary (reviewed 1c7a2ce)The approach holds. Recording each generation's cue file and finished range in the output directory is the right place: that directory already holds the video segments a rebuilt session serves from disk. The integrated server and transcode nodes both load the record through Branch rewritten. I rebased the branch onto main (ed9c902) and force-pushed it with a lease. Main's #2817 had moved the subtitle test helpers next to Addressed
Tests
Left for maintainers
Cross-provider review: one round with GPT-6.1-Sol (xhigh). It raised the two items above. The second led to the fix, and the first is the older problem listed above. Validated features: no passed case on the v1.0 board covers subtitles, transcode, or seek restarts. #2650 and #2620 aren't tied to a validation task. User manual: unaffected. The change adds no setting, label, or step. Apple/Android: no client change. The subtitle playlist and segment shapes are unchanged. Evidence: the published page still matches. The fix only drops a recorded live span whose playlist starts at another segment, and the recorded scenario doesn't produce one. Fit: 8/10 · Readiness: 9/10 — conditional (assuming CI is green)
|
Silo Kody — review completeReview finished. Check the inline comments for findings and verify each suggestion against the code and tests. Reviewing changes in Silo
Review settingsReview OptionsThe following review options are enabled or disabled:
|
Main's Silo-Server#2690 starts a TranscodeSession with its subtitle rendition spans and cue base, beside this branch's group assembler and plan seek anchor. Set all of them; neither depends on the other. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Problem
Closes #2650
Related issue: #2620
Validation tasks: none
A transcode that carries an embedded text subtitle as an HLS subtitle rendition loses its subtitles for earlier parts of the video after the session is rebuilt from its recipe. This affects iOS, tvOS, macOS and Android clients that send
hls_subtitle_renditions_v1. A rebuild reuses the output directory when the server or node running the transcode went away without removing it: a crash, an OOM kill, or a SIGKILL after the shutdown grace period. A backward seek then plays the earlier process's video segments from disk, but every subtitle segment for that range comes back as an empty WebVTT document, which the player keeps. Each one is also answered only after the wait timeout of a few seconds.Two things caused it. The record of which cue file covers which segments (
subtitleSpans) lived only in memory, so the rebuilt session knew only its own range. The rebuilt process also numbered its cue files from 0 again and overwrote the earlier process'ssubtitles_0.vtt.This change records the ranges in the output directory and reads them back when a rebuilt session starts. The rebuilt session then serves the earlier cues for every segment it serves from disk.
Approach
The session writes
subtitle_spans.jsonto the output directory whenever a generation starts or closes.StartTranscodereads it before FFmpeg starts, while the playlist on disk still belongs to the earlier process. For the generation that was still running when the session went away, that playlist gives the last segment it finished. An entry is dropped when its cue file is gone, when that last generation never wrote a playlist of its own, or when the record was written for a different subtitle track or segment duration. The rebuilt session numbers its cue files after every recorded name, so earlier cues are never overwritten.Seek restarts within one session work as before. They now also update the record, which is what lets a second rebuild keep the cues of both earlier processes. The change applies to the integrated server and to transcode nodes, which share
StartTranscode. The API, jellycompat and the clients are unaffected.Validation
main.go test ./internal/playback/... ./internal/transcodenode/...passes, including the real-FFmpeg cue alignment test. The race detector passes on the subtitle and restart tests, andmake lint-changedreports no issues./api/v2withhls_subtitle_renditions_v1. The script played segments 0–320, SIGKILLed the server's process group, restarted it and requested segment 330, which rebuilt the session starting at 330. Onmain, subtitle segments 50–55 and 160–161 were empty and each took 3.5 s. With this change they carried their cues at once.Evidence
Evidence: https://evidence.siloserver.org/r/silo-server/pr-2690/
Surface: hls.js 1.6.15 in headless Google Chrome, playing the multivariant playlist from
/api/v2/playback/startwithhls_subtitle_renditions_v1, since the web player does not request subtitle renditions. Before ismainat 365e3d4, after is this branch at 1c3c13a. The server was SIGKILLed mid-transcode, restarted, and the session rebuilt at 400 s; the player then opened at 1:41 on segments the first FFmpeg process wrote. Screens at 1:42.5 and 1:52.5: before shows no cue, after shows "CUE at 100s" and "CUE at 110s". Not recorded on the Apple and Android apps; they need no change.Risks
One small JSON file is written to the transcode directory per generation start and close. If that write fails, it is logged and only a later rebuild loses the earlier cues, as before this change. A session rebuilt by an older server ignores the record and keeps the old behavior.
Checklist
AI Disclosure
Note
Keep subtitle rendition cues when a transcode session is rebuilt
subtitle_spans.jsonin the output directory, so a rebuilt session can serve cues from earlier video segments instead of losing them. Spans are saved at generation start/close and when an origin is observed.loadSubtitleSpansrestores only spans with a matching track and segment duration, drops missing cue files, and keeps only live spans that the current playlist proves the session produced. Cue-file generation numbers are parsed from existing file names so new spans never reuse a recorded name.writeFileAtomicfor temp-file-and-rename writes, andshutdownnow waits for in-flight record writes before deleting output, preventing writes into a removed directory.restartadds the loaded generation base to the segment-generation counter.Macroscope summarized 1c7a2ce.