Skip to content

Protocol v3 subtitle sidecars are always served by the API node #625

Open

Description

@Quick104

Summary

Protocol v3 subtitle sidecars are always served by the API node. The URLs published in
playback_plan.subtitle.inventory[].url (and font_bundle_url) are hardcoded to the API-relative
/stream/{session_id}/subtitles/{n}, so in a multi-node deployment every subtitle fetch lands on
the API server even when the media itself is being served by a proxy node.

The proxy already implements the routes (/stream/subtitles/{token}/{track} and
/stream/subtitles/{token}/{track}/fonts), but nothing ever points a client at them.

This is the remaining piece of the same class of problem as #619 (direct play and progressive
remux, fixed in #620) and the closed #326 (direct downloads).

Source

Observed during verification of #620 on a multi-node deployment: media was correctly served by a
proxy node while the .vtt sidecar was still fetched from the API host.

Steps to Reproduce

  1. Deploy an API node plus at least one proxy node.
  2. Play a title whose plan publishes a sidecar subtitle inventory, and enable a subtitle track.
  3. Observe the network trace: the media request goes to the proxy, while
    …/subtitles/{n}.vtt?file_id=… goes to the API host.

Expected Behavior

Subtitle sidecars and ASS font bundles for a proxy-served session are fetched from the proxy node
serving that session, so subtitle egress follows the media.

Actual Behavior

playback.SubtitleStreamURLV3 (internal/playback/subtitle_inventory_v3.go:213) and
SubtitleFontBundleURLV3 (same file, line 226) emit API-relative paths unconditionally. They have
no proxy-node awareness, and are not reached by the transport-layer node planning added in #620.

The blocker: combined ordinals vs container track indices

This is not a URL rewrite. The two handlers do not resolve the same track from the same number,
so naively repointing the URLs would silently serve the wrong subtitle track rather than fail.

BuildSubtitleInventoryV3 (internal/playback/subtitle_inventory_v3.go:110-129) assigns each item
a combined ordinal as len(items) across three consecutive ranges:

  1. file.ExternalSubtitles (sidecar files on disk)
  2. file.SubtitleTracks (embedded container tracks)
  3. downloaded subtitles (DB rows, stored in S3)

The API handler (internal/api/handlers/stream.go:236+) resolves that combined ordinal back
through the same three ranges. The proxy handler (internal/proxy/server.go:430+) does not: it
passes the ordinal straight to ffmpeg as a container track index against claims.MediaPath.

On any file with at least one external subtitle, the ranges are offset — combined ordinal N names
a different track on each side. The failure is silent: the viewer gets a subtitle, just the wrong
one.

Capability comparison:

Source API handler Proxy handler
Embedded container tracks yes (ffmpeg) yes (ffmpeg)
External sidecar files yes — reads ExternalSubtitles[i].Path no knowledge
Downloaded subtitles yes — SubtitleRepo + S3Client no DB, no S3 access
Ordinal meaning combined (externals → embedded → downloaded) raw container track index

Design options

Not decided; needs a call before implementation.

  1. Carry the resolved identity in the stream token. Extend the subtitle token claims with the
    source discriminator and the resolved per-source index (plus the external file path, or the
    downloaded artifact locator) so the proxy never re-resolves an ordinal it cannot interpret.
    Most complete; grows the token and needs care so a path claim does not leak node-local layout.
  2. Route only what the proxy can serve. Point embedded-track URLs at the proxy and keep
    external and downloaded ones on the API. Smaller change, but the inventory then mixes hosts,
    and the ordinal offset problem still has to be solved for the embedded subset.
  3. Relay through the proxy. Have the proxy forward subtitle requests to the API rather than
    resolving locally. Simplest correctness story, but it puts the bytes back on the API node and
    so defeats most of the point.

Option 1 matches how #620 handled direct play and remux (freeze what the executor needs into the
token, since the proxy has no database).

Scope

Owning project: Silo Server. Client-visible only in that plan URLs become absolute, which clients
already tolerate for HLS and — after #620 — for direct play and remux.

Notes on priority

Lower impact than #619: subtitle sidecars are small and fetched once per track (a representative
.vtt in the observed trace was ~58 KB) rather than being a continuous stream. This is about
completing the "no media egress on the API node" property, not about relieving significant load.

Acceptance Criteria

  • For a proxy-served session, sidecar subtitle URLs and ASS font-bundle URLs resolve to the
    proxy node serving that session.
  • A given combined ordinal resolves to the same track whether served by the API or a proxy —
    specifically covering a file that has external subtitles ahead of embedded ones.
  • External and downloaded subtitle sources either work through the proxy or are deliberately
    and explicitly kept on the API, with the choice documented in code.
  • Sessions with no eligible proxy keep the current API-local behavior.
  • PGS/.sup windowed requests (?windowed=1, ?position=, ?duration=) behave identically
    on both paths.
  • Tests cover the ordinal-equivalence case above and the no-proxy fallback.

Activity

  1. added
    bug
    on Aug 13, 2026
  2. added
    triaged
    and removed
    triaged
    on Sep 20, 2026
  3. added theissue type on Sep 20, 2026
  4. removed
    bug
    on Sep 20, 2026
  5. Rhainland commented on Oct 23, 2026

    @Rhainland
    Contributor

    Reproduced on origin/main at 19f59ef: a local API server plus one registered proxy node, and a synthetic MKV with two embedded SRT tracks (eng, ger) and an external French .fr.srt. A v2 playback/start returned a direct-play plan whose media URL points at the proxy (/stream/direct/<token>, 206). Every subtitle URL is API-relative (/api/v2/stream/{session}/subtitles/{0,1,2}.vtt), and the API log shows all three fetches landing on the API server.

    The proxy's own subtitle route accepts the session's stream token, so no token scope change is needed to reach it. But it numbers tracks differently, as the issue warns:

    Number API route serves Proxy route serves
    0 external French embedded English
    1 embedded English embedded German
    2 embedded German 500 (0:s:2 matches no stream)

    Cause: the API route reads the number as a position in one list (external files, then embedded tracks, then downloaded subtitles), while the proxy passes it straight to ffmpeg as an embedded-track index. The proxy also cannot do the API's database and blob-store work: external timing corrections, the auto-sync job, downloaded subtitles, and the VTT position/duration window.

    This needs a maintainer decision:

    1. Put the resolved track in the stream token: its list, its index within that list, and an external path or blob locator. This grows the JWT and puts paths in it. Timing corrections and blob reads would still need a new route the proxy can call.
    2. Send only embedded tracks to the proxy: embedded text, PGS, and font URLs point at the proxy's /stream/subtitles/<token>/<number minus external count>, while external and downloaded subtitles stay on the API. No token change, but one subtitle list then spans two hosts, the proxy route skips the API's embedded-track check, and VTT windowing differs between the two hosts. This is the smallest correct step if a mixed-host subtitle list is acceptable.
    3. Relay subtitles through the proxy back to the API. Correct, but the API still carries the work.

    No PR for now. Open PR #2571 touches the same files.

    AI disclosure: reproduced by Claude Code (claude-opus-5-5) at the maintainer's direction.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions