Skip to content

feat(web): direct play reads a file over parallel range connections - #4497

Merged
Quick104 merged 49 commits into
Silo-Server:mainfrom
darthShadow:pr/web-parallel-ranges
Nov 19, 2026
Merged

Quick104 merged 49 commits into
Silo-Server:mainfrom
darthShadow:pr/web-parallel-ranges

Conversation

@darthShadow

@darthShadow darthShadow commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Related issue: #4439
Validation tasks: changes #1177 C2, C3; changes #1178 C2

Other clients: Apple N/A (does not send parallel_range_origin_v1, so its plans do not change; a direct play through a proxy node stays counted on the node for up to 60 s after its last request, on every client); Android N/A (same); Roku N/A (same)

In the web app, a direct-play file is read over one HTTP connection. On a long or lossy link, one connection moves only a fraction of what the link can carry, so playback stalls while the link has spare room. This affects viewers far from the server, and the administrators who serve them. This change reads the file as several byte ranges at once, over separate connections, in the browser's decode engine. The engine plays files the browser's media element cannot take as they are. The proposal is in #4435.

Approach

The reader. A Mediabunny source keeps Mediabunny's read orchestrator, cache and prefetch profile and changes only how bytes arrive. Each read worker sends closed ranges of 2 MiB, with at most 4 in flight per source. The first 16 MiB of each read (the warm head) comes from the plan's own URL while the extra connections warm up. A range that finds the stripe URL busy goes to the plan's URL. The first answer from the stripe URL that is not a readable 206, or the first transport failure there, sends the rest of that range and every later range to the plan's URL, with no retry spent on the stripe URL. A stripe body that runs past its range moves the read to the plan's URL the same way.

The engine stripes only when the plan names a stripe URL in stream.parallel_range_url, and it uses that URL exactly as given. The server names one of three:

  • A proxy node serves the file: the node's own direct-play URL, the one stream.url already carries. With the default routing (playback.routing.direct_play_egress = prefer_proxy) this is the usual case on a deployment with proxy nodes, and it needs no setting.
  • The API serves the file: the plan's own stream, relative to the API root. The engine stripes on it only when the page loaded over HTTP/1.1, where the browser opens several connections to an origin. This needs no setting either.
  • The API serves the file and server.web_media_url is set: the same stream on that media origin, an https address that serves the same API over HTTP/1.1 only. It is for a deployment whose main address speaks HTTP/2.

HTTP/2 and HTTP/3 put every request to an origin on one connection, so parallel ranges there add requests and no connections. After a completed range the reader asks the browser which protocol the striped URL answered over, and returns to Mediabunny's stock UrlSource when it was HTTP/2 or HTTP/3. A browser that does not say leaves it striping. When the stripe URL is the plan's own URL (a node, or the page's origin) there is one URL: every range uses it, up to 4 at once, and a transport failure is retried there like any read's. Without a stripe URL the engine reads the plan's URL through the stock UrlSource, over one connection, as before. A plan URL that ignores Range and answers the open with the whole file also plays through the stock reader, in order. The reader wraps the prefetch profile it finds and takes the larger of its own read-ahead end and the inner profile's end, so a read-ahead change on the plain UrlSource path composes with it in either order. Mediabunny is pinned to 1.62.1 instead of ^1.62.1, because the source reads UrlSource and orchestrator internals.

The server.

  • New admin setting server.web_media_url: an https origin that serves the same API over HTTP/1.1 only. Empty names no media origin, and a change applies without a restart. It is named only for a client that arrived by the default access path; one that came through a network access provider gets the plan's own stream.

  • New client feature parallel_range_origin_v1: the client's promise to use stream.parallel_range_url exactly as given, adding no account token to it, when the plan has one, and to read stream.url otherwise. The server sets the field on an original_http plan as listed above. The two API forms carry st, which authorizes only an attempt a login session started, so only such an attempt gets them. stream.url stays valid either way.

  • GET, HEAD and OPTIONS on /api/v2/stream/{session_id} answer with Access-Control-Allow-Origin: *, allow the Range header and expose Content-Range, with no credentials. GET and HEAD carry these headers on every answer, refusals included, so the page can read a refusal. The preflight is answered before authentication. It carries Access-Control-Max-Age: 600 and writes no activity-log row. Authorization stays in the URL's token and st. No other route gains CORS. The API's and a node's stream answers carry Timing-Allow-Origin: *, so the reader can learn the connection's protocol.

  • On the native stream routes, a request from byte 0 or with no Range header writes an activity-log row, as before. A range that continues a play (it starts past byte 0) writes a row only when it fails; one that succeeds, or that the client abandons (499), writes none. A GET answered 200 keeps its row whatever its range: a progressive remux started again from its origin is a new stream. The Jellyfin stream routes still write one row per request; matching them is a possible follow-up.

  • On a proxy node, a direct-play session stays counted between range requests: the last request to end keeps it for the 60 s session TTL when it delivered media. A HEAD, a refusal or an unsatisfiable range adds no such hold and ends none that is running, and the session's record expires with its count. A plain hold for the session, as a remux after a replan takes, ends a running linger; while holds of both kinds overlap, the latest one decides. Without this a striped play dropped out of the node's capacity count and the admin's node-session list in every gap between ranges.

Credentials. The stripe URL always authorizes itself: st on the API forms, the token in the path of a node's URL. The player uses it as given and adds no account token, header or cookie; an earlier revision had it append the access token to a URL without st, which would have sent a login token to a node. The server never names a node's header-authorized route, and an attempt that negotiated header_authenticated_media_v1 gets no stripe URL. An attempt with no login session, such as one an API key started, gets none on the API routes. It reads stream.url, which keeps st and the token and can still rebuild an evicted session. Every other playback URL keeps the token it carries today.

The contract change is one optional field (a URL reference) and one feature name. docs/playback-api.md, docs/architecture/playback-protocol-v3.md and docs/architecture/api-contract.md describe them, and the OpenAPI document, the web types and the playback fixtures are regenerated.

The meter. The engine's throughput meter now counts the time each response was receiving, from its first body chunk to its latest, and counts overlapping time once. Bytes from parallel ranges are divided by that union, not by the sum of each range's time. The striped source counts all its ranges into one request and keeps that union as merged stretches, so a long play does not grow the list by one entry per range. A stock read stays a request of its own, so the meter's 1,000 ms rule applies to it as before.

Seeks. A seek that finds both read workers busy no longer waits for their read-ahead. At the seek, each queued read is cut to the bytes Mediabunny still waits for. When the seek's first read then finds both workers running, each older worker is cut to the bytes its waiting reads need, and its ranges that hold none of those bytes are cancelled. The older worker that owes the fewest bytes stops at once, its unmet bytes go back on the queue, and the seek's read takes its place and the first free connection. In a Node run of four seek patterns on two Matroska files over a 2 MiB/s throttled link, the wait from the last seek to its first request fell from 5.27-7.84 s to at most 0.01 s, and the first video packet came 1.04-2.72 s after the seek instead of 7.31-10.97 s. A read the replaced playback makes after the seek still counts as new. A seek whose first read asks for the same hole as a read queued before it (near the end of the file) retires a worker like any other, and the new worker takes the queued reads it covers.

HTTP/2 multiplexing was not an option, since it puts every request on the one connection this change needs to get away from. Adaptive range sizes and four fixes for faults found in a real-browser test follow in the next pull request.

The web changes add no user-visible text, and the setting has no settings-page label, so there are no silo-translations keys.

Validation

  • Contributor gate, Linux container, Go 1.27.4: the full chain exits 0 at e775bf9, including the database pins and the Prometheus rules test. The last commit changes only comments; its focused tests, lint, size and local-path checks pass.
  • The new tests drive the real Mediabunny orchestrator against a fake range server. They cover slot limits, the warm head, the fallback to the plan's URL, retries and the credential rule. On the server, they cover the plan-field gate, the setting's validation, the CORS answers and the activity-log rows per play. The meter tests cover overlapping and back-to-back responses. They do not cover a lossy link; the lab measurement on the evidence page covers one.
  • Seeks: the tests asked for in review hold both read workers busy on regions they still owe. "sends the seek's first range at once when each old read still waits for a cluster" checks that the seek's first request leaves within 1 s while neither old region has drained. "sends the seek's first range at once and starts no read-ahead for reads queued before it" checks the same within 100 ms after the queued reads are cut. Five more tests cover the slot a retired worker frees, cancelled ranges, a read from the replaced playback, a worker a new read waits on, and bytes after a trim. Removing any one of eleven parts of the fix, one at a time, fails a named test. Four parts have no such test: the sort and the merge of the requeued bytes, the record of the queued reads waiting at a seek, and the trim when Mediabunny restarts a queued read.
  • The API contract diff reports two additive changes, both on the new optional field.
  • Real browser: a Silo image built from the branch, Chromium, a test clip, and a media origin over HTTP/1.1. Range requests reached the media origin over three connections, each carried st and no token, and each 206 allowed the origin and exposed Content-Range. Playback reached 30 s with no alert. A seek to 70 s and then back to 50 s played on from 50 s. The play left one activity-log row on the stream route, a 206.
  • Maintainer review fixes at eff92e0d2a (fd99395415, 0647945ded): each new or changed test fails on d8f12d469c. On a dev deployment built from that head, Chrome on the engine route sent 148 ranges to an HTTP/1.1 media origin (up to 3 at once, each with st and no token) and 24 to the plan's URL, three seeks sent their first range within about 100 ms, a seek into the last 20 s played on, the credits Skip control worked, the play left one activity-log row, and an explicit preflight answered 204 with Access-Control-Max-Age: 600 and left no row. The maintainer's summary comment links that run's evidence page.
  • Maintainer rework at 83deb583f2 (afd2ef25df, 9dfa390083, a53a9bea38, faea666732, 9c10b806a6, 4b0c0693f5, b179fb9d16, a9b35d052f, bfc766b3a6, 83deb583f2): restores striping on a proxy node's URL and on the page's own origin, which round 1 had asked to remove. Each new or changed test fails on the earlier head. On a dev deployment with proxy nodes, in Chrome on the engine route (the node runs on a build of 83deb583f2, the API-served runs on 9c10b806a6): through a node over HTTP/2 the reader sent a few ranges and returned to the stock reader (19 requests); through a node over HTTP/1.1 it striped for the whole play (164 closed ranges, up to 4 in flight, no account token), and the node listed the session during play and 30 s after the browser closed, and not at 75 s; API-served over HTTP/1.1 it striped on the page's origin (164 ranges, one activity-log row); API-served over HTTP/2 it used the stock reader (19 requests); with a media origin it striped there (132 ranges with st and no token). Three seeks worked in every run. The maintainer's summary comment links that run's evidence page.

Evidence

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

Surface and build: web player, browser engine route. The page names the build of each result. It holds the first round's gate, Chromium request lists and a lab measurement of startup, stalls and throughput against the single-connection reader on a 350 ms, 1% loss link; its h1 cell measured the same-origin rule this round removes. Its last section holds this round's gate, the browser request list with the seek check, and the Node seek table.

Risks

  • More requests. Ranges are 2 MiB here, so a long play makes many requests. The next pull request makes them larger.
  • CORS. The stream route answers with a wildcard origin and no credentials. Authorization is unchanged: the token and st in the URL.
  • On by default. A node-served play and an API-served play on an HTTP/1.1 page stripe with no setting. An API-served range runs the full stream path (authorization lookups and two log lines); a node's token route does not. The HTTP/2 check keeps the extra requests off connections that would not gain from them, in browsers that report the protocol.
  • Node capacity. A stopped direct play through a proxy node counts against the node's max_jobs, and shows in the admin's node-session list, for up to 60 s after its last request. That is the reason for the Validation tasks: line: Distributed transcode nodes — Server #1177 C2 and C3 and Distributed transcode nodes — Web admin #1178 C2 should be walked again. The planner's own admission has older gaps this does not close (it drops a reservation when a newer health report arrives, and reservations are per API server).
  • Media origin down or misrouted. The first refusal (any answer that is not a readable 206) or transport failure sends the read to the plan's URL, so playback continues at single-connection speed.
  • Backup and restore. server.web_media_url is classed as a server-specific setting, so a restore onto another server does not carry it.
  • Seek costs. A cancelled range can close its HTTP/1.1 connection, so the next range pays a new handshake. During rapid seeks a retired worker's unmet bytes can be read twice: 2.38 MiB and 8.75 MiB in the two rapid-seek runs. A worker that serves the new playback counts as older between its reads, so a later read can retire it and its read-ahead is fetched again. Keeping it instead delayed the next new read from 0.1 s to 3.1 s in a fake-clock test.
  • Dependency pin. Mediabunny cannot float to a newer minor version without a check of the internals the source reads.

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.

AI Disclosure

  • Harness: Claude Code, run in T3 Code; Codex CLI
  • Tool(s): Claude Code, Codex CLI
  • Model(s): claude-opus-5-5, claude-sonnet-5-5 (Claude Code); gpt-6.1-sol (Codex CLI)
  • Involvement: Fully AI-generated, human verified
  • Adversarial review: Two reviewers on different models (claude-opus-5-5 in Claude Code, gpt-6.1-sol in Codex CLI) read the change twice, on the rebased branch and on the finished stack, and a claude-sonnet-5-5 seat merged each pair's findings. They ran mutation checks on the tests they relied on. The first round found two High defects in the lingering session hold, and both were fixed and re-run. The second found a Medium defect, a failing media origin failed the read instead of falling back to the plan's URL, and a few documentation and comment errors. All were fixed and checked by a separate claude-sonnet-5-5 seat. For the maintainers' second round, a gpt-6.1-sol seat reviewed the plan before any code was written, the same two-model pair reviewed the result (one Low finding, fixed), and a separate claude-sonnet-5-5 seat checked each change against the code. The seek fix went through the same steps: the pair compared designs and reviewed the plan, then reviewed the result (three Low comment findings, fixed), and a separate seat checked the change against the plan. The maintainer's review fixes and rework (fd99395415, 0647945ded, 3c4b1edc2b, and the commits from afd2ef25df to 83deb583f2) were written in Claude Code with claude-fable-5-2. gpt-6.2-sol and claude-opus-5-5 reviewed the fix plan first; gpt-6.2-astra, gemini-4-neon and an independent claude-fable-5-2 reviewed the design of the proxy-node rework before it was written, and each changed it.

Note

Add parallel range connections for direct play of original files

  • Adds the parallel_range_origin_v1 playback feature and optional stream.parallel_range_url. The server publishes it for eligible original-HTTP deliveries (playback_v3.go), and the web player reads the file through a new ParallelRangeSource that stripes requests over the plan URL and optional stripe URL (parallelRangeSource.ts).
  • Adds CORS and Timing-Allow-Origin handling for the original-file stream route, including unauthenticated OPTIONS preflights (playback_delivery.go).
  • Adds nodesessions.Tracker.HoldLingering, which keeps a direct-play session alive across the gaps between striped range requests when at least one request delivered media (tracker.go).
  • Reworks media-data metering: createMeteredFetch reports merged receiving-time spans, and throughput now uses unioned receiving time instead of each request's full first-to-last interval (mediaFetch.ts, media-data-meter.ts).
  • Adds the server.web_media_url admin setting (bare HTTPS origin) and a new stream-path filter that omits range-continuation and preflight requests from activity logging.
  • Behavioral Change: mediabunny is now pinned to exactly 1.62.1 because ParallelRangeSource depends on Mediabunny internals (mediabunnyInternals.ts); upgrading requires re-checking that internal surface. MediaDataMeter.throughputKbps changes how throughput is computed for striped reads.

Macroscope summarized 83deb58.

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

Labels

enhancement New feature or request impact: playback Can't play, stalls, or wrong media priority: P2 Limited scope, workaround exists, or polish size/XXXL 3000+ added + deleted lines (all files); change volume, not priority.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants