Skip to content

feat(playback): one playback and subtitle reliability bundle (replaces #444, #446–#458) - #459

Merged
randrini merged 114 commits into
mainfrom
integration/playback-combined2
Nov 20, 2026
Merged

randrini merged 114 commits into
mainfrom
integration/playback-combined2

Conversation

@randrini

Copy link
Copy Markdown
Collaborator

Problem

This replaces fourteen stacked pull requests with one reviewable change. They accumulated over two weeks of production testing on virtual-library playback, and reviewing them individually had become the problem rather than the fix: each PR was verified in isolation, but several only made sense together, and two of them (the size-mismatch tolerance and the identity guard) composed into a behaviour neither described alone.

The underlying symptoms, all observed on a live deployment:

  • A selected version was replaced before playback in 8 of 12 starts, sometimes across resolution and dynamic range, with no explanation to the client.
  • A 4K HEVC session rebuilt its media pipeline 107 times in 170 s (508 manifest loads in 300 s) while the server served every segment at 200 and p50 250 ms. 477 of those reloads fell within 400 ms of a catalog version check.
  • PGS and ASS subtitles frequently never rendered: bitmap pages re-read the container prefix per page, and text windows ran for 40–60 s before the client gave up.
  • The same 69 GB object was served for three different declared releases, and 538 catalog rows carried a 1080p release name with a probed 2160p resolution.
  • A single failed play attempt left an item with the Play button disabled.
  • Retryable start timeouts surfaced as 500 internal_error; a client cancel surfaced as 502.

What this change does

Selection and identity

  • An explicit pick is sent as explicit on the wire, is honoured by the planner, and is never silently replaced by a different release.
  • A plan's effective row must be one of the item's selectable version rows. An unlisted row is refused, that candidate is excluded, and exhaustion answers a retryable terminal naming the version list.
  • A size gap between what a provider advertises and what is served no longer blocks probing or playback of that row's own bytes — but unverified bytes may not establish a release's inventory and may not move a plan onto another release. A foreign plan is refused and the row reports source_mismatch instead of a generic "unavailable".
  • Rotations may adopt an identity but never change the selected version or drop audio/subtitle tracks.
  • A client abort or an unverified row no longer marks a version failed, so one bad attempt cannot disable an item.

Subtitles

  • Bitmap pages are served from one progressive demux per source behind a coverage watermark, with a read budget that refuses an expensive page before reading it and answers retryable 503 with Retry-After and X-Subtitle-Coverage.
  • A windowed text extract carries an elapsed budget; a breach answers retryably and warms the breached range so the retry is served from the artifact rather than repeating the read.
  • A cue-less or header-only response is never served as content and never cached as last-good.
  • A committed .sup artifact is not invalidated by a seek, and a subtitle track change keeps the playback position.

Player and client

  • Catalog version checks no longer restart the media pipeline: the version list is read through refs, so a projection changes menus only. Polling is coalesced per row set and backed off (12 checks per 5 minutes on a 452-row title, down from 452).
  • Segment retries are bounded per index and per streak with backoff, and exhaustion surfaces a failure instead of re-fetching the same segment hundreds of times.
  • A blocked autoplay offers a tap-to-play overlay instead of an indefinite "Loading video".
  • The substitution notice names the release, stays quiet for a same-release mirror, and the item page resolves a playable version when the remembered one left the list.
  • Version liveness uses the v2 operation; the retired /api/v1 route was returning 410 for every call.

Diagnostics

  • Retryable start failures answer 503 with Retry-After instead of 500; client cancels answer 408.
  • Substitution cause is published on the plan and on replans.
  • A prefetch logs why it ran or skipped.

Verification

  • CI green on the integration head; the branch is the composition of the individual PRs, each of which was verified separately before merging here.
  • Integration gates: go build, go vet, scanner/apiv2/catalog suites, focused playback and handler suites, -race on the new tests, playback fixtures, v2 OpenAPI and web types, fork invariants, tsc, and the focused web suites.
  • The only Go failures are two pre-existing ones that reproduce on main (TestOnDemandSubtitleSegmentsDoNotWaitForTheStream, TestServeExtractDiscardsACappedDemuxCopy) plus a load-sensitive timing test that passes in isolation.
  • Production verification runs are recorded in the individual PRs being superseded.

Known open, tracked separately

  • The provider returns the same object for several distinct release rows, which is why a row's declared size and the streamed bytes can disagree. The server now refuses and explains rather than mislabelling; the mapping itself is upstream.
  • A 4K H.264 transcode is still planned for clients that cannot decode it in real time (33 % dropped frames in testing).
  • Bitmap page cost is measured as elapsed time, not bytes: ffmpeg reads HTTP with recv(2), which /proc/PID/io does not count.
  • Native clients need follow-up for the new retryable subtitle-page answers.

AI disclosure: implemented with DeepSeek V4.1 Flash 1017 (ollama-cloud/deepseek-v4.1-flash:1017) in the OpenCode agent harness, with build, test and lint gates run in the project's libvips Go image.

randrini and others added 30 commits November 13, 2026 17:02
A windowed PGS extract cannot seek a non-seekable relay, so ffmpeg demuxes
the container from byte 0 and discards the prefix: a page at offset S costs
(S + W) x bitrate, not W x bitrate. A 120 s page of an 18.25 GB / 35 Mbps
source is ~525 MB, which is also the two-minute extraction timeout, so such
pages were killed at the timeout and answered with a partial .sup that held
no complete display set.

The extract now watches the process's own read count and kills it once a
page has read more than 256 MB, the same order as the largest source a page
read is still worth attempting. The page answers the retryable 503 the
client already backs off from, with a distinct additive problem code
(subtitle_page_too_costly), a counter, and the existing per-identity
extraction backoff so a retry does not pay the same read again.

Only a bounded bitmap page read from a remote source is capped: a
whole-track extract must read everything by design, an artifact-backed
window reads a local file, and a local source's prefix read is a disk read
that finishes in seconds.
…ce demux

A windowed PGS extract cannot seek a non-seekable relay, so every page paid
for the whole container prefix again: on an 18.25 GB / 35 Mbps source a
120 s page reads ~525 MB, which is the window extract timeout, so pages
returned partial .sup bytes with no complete display set and were never
cached.

One unbounded .sup demux now runs per source identity, track and format
generation, single-flighted through the cache's warm slot and detached
relay budget. It writes the track's artifact and indexes the display sets
as bytes land, so the cache knows how far the track is covered:

- a page inside the coverage is served by copying those display sets out
  of the artifact, with no source read and no ffmpeg;
- a page beyond it answers the retryable shape with X-Subtitle-Coverage
  describing what is actually covered, never a truncated run;
- on end of file the artifact flips into the committed whole-track entry.

The watermark only advances at a complete display set (PCS through END) and
is derived from bytes already written to the artifact, so a page is never
served ahead of what has been parsed. A page refused for its read cost also
starts the fill, since the artifact is what will serve it; the API handler
owns that fill because its relay registration outlives the request.

Text windows, local files, and a remote container whose size is unknown
keep their existing paths.
…ably

The progressive bitmap fill never ran in production, so every page still cost a
fresh source extract. A page miss is served by the handler's detached warm, and
that warm admitted a bitmap track only while paused; a playing session dropped
it with "bitmap full-track warm stays paused-only". Five page misses, five
skips, no artifact, no watermark, no coverage-gated answer: 100.2 s for the first
page and 70.6/75.7/88.1 s for later distinct pages, with only an exact repeat
fast from last-good.

A bounded bitmap page is the one bitmap request whose fill is the page path, so
it now routes to the waiting-page admission: the fill starts while playing,
single-flighted per (source identity, track, format) through the cache's warm
slot and detached relay budget, and it replaces the bounded window prefetch,
which would read the same source again for pages the fill publishes. Every other
bitmap request keeps the paused-only full-track warm.

The read cap measured the wrong cost. A page at 3600 s returned 200 after 88 s
with its read count under the cap because the relay answers the seek with range
reads, so the page is now priced before the extract: the container prefix it
would discard, `start x rate`, from the row's size and runtime or bitrate, and
in wall-clock terms from the read rate this identity's own extracts measured.
A page beyond 256 MB of prefix, or whose prefix would take more than 45 s at the
measured rate, is refused before any source read with the retryable 503, its
Retry-After and X-Subtitle-Coverage, and that refusal starts the fill. An opening
page has no prefix and extracts exactly as before. The runtime 256 MB cap stays
for pages that are still attempted.

An extraction that ran out the window extract deadline answered a non-retryable
500 while the client had four attempts to spend. A page that times out now
answers the same retryable page-cost shape as the read cap; a windowed text
extract that fails or is canceled no longer commits a 200 carrying a header and
half a cue, because the slice is held until its extract completes and dropped
otherwise. The handler classifies both through one mapping: deadline, upstream
5xx and a lapsed relay token are retryable, everything else stays a loud 500.

A `.sup` muxer that refuses the mapped stream's codec after a release rotation
("sup muxer supports only codec hdmv_pgs_subtitle", exit 234) is a mapping the
drift probe missed, so it now reads as a stream-map error and takes the existing
re-probe and remap path — a remapped track or a retryable 409 — instead of a 500.
Verifying a bitmap request's live layout before every spawn is left out: that
probe costs a provider round trip per page and needs a design decision.

Serving rules for the new page path are in docs/architecture/playback-protocol-v3.md
and docs/architecture/web-pgs-subtitles.md. The web client is unchanged: it
retries with backoff and honours Retry-After.
serveProgressiveSUPPage set Content-Type and Cache-Control after
serveWindow had copied the page, and the first Write commits the status
and headers. Every non-empty page therefore went out with neither, so an
intermediary could cache a per-window subtitle slice. Set both headers
before the copy on every path through it, including the empty window.

The existing page test only read the recorder's live header map, which a
late Set still updates; the new test reads the committed response.
pagePrefixEstimate priced a page's discarded container prefix as
start x byte rate, which can exceed a known source size: a seek past the
end, or a size and bitrate that disagree, priced the page above the whole
container and refused a page the source can serve. Clamp the prefix to
SourceSizeBytes when it is known.
Only probe evidence counted as published inventory, so the item page sat on
"Discovering…" and ended at "Unavailable" whenever the pre-play probe did not
land, even though the selected version's row already carried audio and
subtitle tracks.

Render the selected row's own declared rows immediately and label them as
coming from the release listing. Probe evidence replaces them, and a probed
list never regresses to a declared one. A row with no declaration and no
evidence keeps the bounded discovery-then-retry path. The player overlay
follows the same rule for the playing version, and a plan's inventory is still
published only under the rows it describes, so a substituted release cannot
leak onto the selected version.
… parsed

A page request at a playhead inside the progressive artifact's watermark was
answered with 503 subtitle_source_unavailable. The serve gate required the whole
page range to be parsed (end <= coveredUntil), so a request for 10-130 s against
an artifact that had parsed 0-120 s was refused although every display set that
shows in its first 110 s was complete on disk.

Production showed it plainly: the artifact's watermark reached 126.543 s while
page requests at 10, 20, 40 and 60 s answered 503 with X-Subtitle-Coverage:
0.000-126.543 and no page was ever served; "subtitle page served from the
progressive artifact" never appeared in the log because the copy was never
reached. Each of those requests is snapped onto the source-zero page grid, so
the page under test ends at 240 s even though the requested range ends at 130 s,
and the old gate asked for the whole 0-240 s.

Serve the parsed prefix instead: the cut stops at the watermark, the response is
a 200, and X-Subtitle-Coverage reports the range it really produced. The cut
comes from the display-set index and its first complete display set is checked
before a byte is written (supHasDisplaySet), so a partial run or a cut that
cannot draw is never served. A page that starts at or past the watermark is
still retryable, now as 503 subtitle_page_not_ready with Retry-After and the
covered range, because the source was never read and the page is only waiting
for the artifact that will answer it.
A subtitle response's X-Subtitle-Coverage is the range it really produced, and
a bitmap page answered from a partly parsed track is shorter than the page it
asked for. The window fetcher committed the whole requested range whenever the
body streamed in, so the unparsed tail of such a page was marked as covered and
never requested again: playback would draw the prefix and then nothing until the
next page boundary.

Commit the advertised end when the response carries one, and on the page grid
request the page that contains the committed end rather than the page after it.
A partly produced page is therefore asked for again as the artifact catches up,
and a page that arrived whole is unaffected because its advertised end is the
page end.
Separate release identity from usability in the virtual probe gate. A
served-vs-declared size gap no longer rejects a candidate: the probe's
measured inventory is written metadata-only, planned and played, while
the verdict stays Unverified and never stamps the row or pins the
candidate. Duration or track-layout contradictions still reject as a
different file, and every acceptance path now uses one classification
entry point so the fresh-probe, cache, and persist seams agree.
An explicit version pick reached `/playback/start` as `file_selection:
"auto"` whenever playback began from an item detail page. The action bar
passed the flag, but `buildWatchLocationState` dropped it on the way to
the watch route, and `WatchRoute` rebuilt the request from the URL, which
names a file but not why it was chosen. The player therefore treated
every detail-page start as the server's choice: it sent `auto`, showed
Auto checked in the version menu, and armed cross-version fallback.

Carry the flag through the location state and the route, and include it
in the request key so a route sync cannot fold a pinned start into an
Auto one.

A reload keeps only the remembered row in `silo-requested-version`, so
the store now records whether the viewer named that row. The detail page
and the watch page pin a remembered row only when they can still tell it
is the viewer's; a row an Auto start played stays a hint and stays
substitutable. The player reports the standing of a row it commits, and
its Auto entry reports the row being played as no longer pinned.
…erequisite

#448 (fix/rotation-respects-selection) is open, not merged. This change
extends the same guard to the resolve-timeout fallback, so it must reuse
virtualRotationWouldDropTracks/virtualRequestedRowIsSelection instead of
growing a second policy. Whichever of the two lands first, the other's
call sites keep working.
The item page and both version menus posted to /api/v1/catalog/versions/check, which the upstream sync retired: every request answered 410, so every row stayed at its snapshot availability.

Call checkCatalogVersions at POST /api/v2/catalog/versions/check. The v2 contract renders file ids as opaque strings, so the request sends strings and the response adapter restores the numeric ids the menus key on (dropping a value that names no row). Treat the call as the read it is, so a stalled check still hits the read deadline.
The version-swap notice treated any effective row id different from the requested one as a substitution. A sibling mirror of the same release has its own row, so every virtual play of such a release claimed the chosen version was not playable on the device while the same release played fine.

Decide the notice from release identity rather than the row id: the plan's substituted_from_file_id is the server's substitution signal, and without it two rows are compared by release name, then declared size plus encode fingerprint. Same-release movement stays quiet, a provably different release still speaks, and an unidentifiable pair makes no claim instead of guessing.
Bound the implicit text page to 120 s so a cold ASS extract reads a page of container instead of ten minutes of it. Skip the drift probe when a committed .sup artifact already pins the identity, and warm the track after a failed probe so the retry reads a committed artifact instead of repeating the probe.
A virtual resolve attempt took its bound from a nested WithTimeout on a
deadline an earlier stage had already spent. The derived context expired
before the wait began, the resolver logged a negative bound
(bound_ms=-34/-65/-95/-126 on four consecutive attempts), and every attempt
failed immediately with context deadline exceeded. Callers read that as a
provider listing failure: the failover loop ran on a spent budget, the version
fallback used it to justify a release substitution, and the transport reported
the last attempt as a non-retryable transcode_start_failed.

Derive each attempt's budget from the request's remaining time under an
explicit cap (virtualResolveAttemptBudget), refuse an attempt when nothing is
left, and stop the cold-path candidate loop once its single deadline is spent.
Logs report 0 ms left with an explicit bound_exhausted flag instead of a
negative wait. A transport startup with no budget left answers the retryable
provider_unavailable instead of a fabricated transcode verdict.

The cold-path and stale-pin tests now pin the new truth: a spent budget is
refused, and the recovery listing is identified by its own sub-budget rather
than by a global call ordinal.
The cold-start version fallback walked alternate releases on any provider
listing failure, including a resolve timeout, and served the first that
resolved. Production: a 3-audio/4-subtitle selection played as a
1-audio/0-subtitle sibling.

Apply the rotation guard #448 introduced to the fallback: a substitute that
contradicts the item's runtime (duration_contradiction) or offers fewer audio
or subtitle tracks than the selected row (track_loss) is refused, and when every
substitute would lose the selection the start answers a retryable terminal that
names the version list instead of serving a poorer menu.

A walk whose own budget is spent does not run at all: a timeout is not evidence
that the selected release cannot serve, and every alternate would be resolved
on the same expired deadline.
The plan's substituted_from_file_id and substitution_reason were set in the
domain type, but the v2 projection rebuilt the plan field by field and dropped
both. Across 35 production plan/replan decisions with 14 effective-id changes
the client saw them zero times, so it could only guess which release it got.

Project both fields into the v2 plan and publish them on every replan that
commits a row other than the requested one, not only the explicit version-pick
hunt. The cause comes from a reason the plan already carries, a decode
rotation, or the replan's failure class.

Additive: two optional plan fields, regenerated OpenAPI and web types, and a
short playback API section naming the substitution vocabulary. Tests pin the
serialized body, the omitted-when-unsubstituted case, and a replan rotation.
Conflict in internal/api/handlers/playback_virtual.go: #447 had folded its
size-gap exemption into the duration guard while #448 carried the untouched
guard plus its rotation guard. Kept a single duration guard carrying the
size-gap exemption, then #448's rotation guard and substitution marking.
Conflict in internal/api/handlers/stream.go: #451 added a force admission
and #444 a page-waiting admission to the detached warm. Unified the warm
signature to (pageWaiting, force): the window-miss and probe-failure callers
pass bitmapPageWaitingForFill(opts), the waiting-page caller passes true, the
param-less bypass stays force-only, and the bitmap playing gate now admits
either exception. #444's refactor of the extract-failure block into
writeSubtitleExtractFailure keeps #451's upstream/relay-token handling.
- A rotated PGS layout had no verdict. The warm's drift probe is the only probe
  on that path, and its positive "the live release has no same-class track"
  result was thrown away with the fill, so every page was refused, started the
  same warm, and abandoned again. Record it for the identity with a 60 s TTL,
  cleared by a later successful match, and answer the next serve with the
  existing 409 subtitle_source_changed so the client replans onto the rotated
  inventory. A probe error records nothing.
- Name the muxer class in the no-match diagnostic: how many live tracks carried
  it and in which languages, so "no PGS" and "PGS in another language" stop
  logging identically.
- The subtitle resolve 502 carries the same Retry-After the remux start failure
  does, so a client backs off instead of retrying on its own cadence.
- A remux that produced no byte writes the standard v1 error envelope with
  remux_start_failed. A plain-text body left the byte-delivery adapter logging
  code=internal_error for a provider or relay refusal. Status, Retry-After and
  the dependency_unavailable problem type are unchanged.
…lection

The trust window keys on the row's own updated_at plus candidate_store_hours
(720 h), not on presence in the listing, so a candidate dropped today stayed
"trusted" for up to thirty days and every replan refused. After the bounded
forced relist has also failed and the row has no usable stored URL, an
automatic selection now degrades the pin to rotatable: the retry clears the
trust (WithoutPersistedCandidateTrust, which also stops the per-candidate seam
from re-establishing it) and accepts the live sibling.

An explicit pick keeps today's invariant: no forced relist, no trust clear, no
sibling, the same refusal. The plan's candidate loop follows the same rule.
collapseDuplicateVirtualVersionFiles preferred the probed duplicate over the
unprobed one without consulting failed_at, so a candidate with one failed-probed
row and one live-unprobed row listed as the failed row and the compat filter
then omitted it entirely. One predicate, virtualRowFailed, now rules both places
the liveness was missing: the survivor choice between two rows of one candidate,
and the probed-copy index an unprobed row may be hidden behind. Between two live
rows the existing probe-evidence preference stands.
…data

A failed probe fell back to the candidate's declared inventory with no log, so
one client reporting fewer streams than another looked like a race instead of a
degraded provider. The probe seam now says why it failed (resolve failed, probe
failed, probe timed out) and the fallback logs it at WARN. A dropped evidence
persist is a WARN too, not debug detail. The request still does not wait for the
probe any longer than it already did.
The liveness cases pushed the duplicate switch over the nesting threshold. Move
the decision into virtualKeptDuplicateAction so the loop reads as the four
outcomes the collapse actually has (replace, drop, fold, fall through), with the
liveness-before-probe-evidence rule stated once.

No behavior change; TestBuildPlaybackInfoPrefersALiveDuplicateOverAFailedCopy
covers all four outcomes.
Three dead ends on the 4K subtitle path, all of which ended in a 503 the
client could not repair.

A text window killed at its elapsed budget after writing bytes was reported
as the extract's raw deadline error, because "bytes written" was read from
the counting writer that feeds the response hold. A held slice never reached
the client, so that check also skipped the retryable budget shape and the
covering recovery warm the handler starts from it: every retry paid the same
source read, and the French switch ended on "Subtitles couldn't load". The
breach now always answers the retryable budget reason (the caller still
aborts a slice that spilled onto the wire), and the budget itself is derived
from the client's 30 s fetch stall less a 4 s answer reserve instead of the
fixed 20 s that sat below a 120 s window of a 75 GB / 81 Mbps release
(~1.2 GB, ~20 s at the rate the relay served it).

A page-driven PGS fill can leave without committing on several paths (yields
exhausted, a re-key loss, a budget spent, a caller cancel) and none of them
recorded a terminal state; the production fill ran 114 s and vanished with
the session, while pages answered `page_not_ready` until the client gave up.
Every fill now ends committed, failed, or abandoned with a reason, and the
reason is recorded for the page ledger. The fill a page waits on is bounded
by that wait, so it cannot outlive it, and the page answers finally once the
fill has spent the budget instead of after another stall window. A transient
fill failure still leaves the page retrying inside its own budget.

A subtitle URL minted for a release the plan substituted away names an
ordinal (and a container stream index) only the original release had. The
effective sibling answered 404, which no retry can repair; it is a rotation
verdict, so it now answers the existing retryable 409 that makes the client
replan and re-select from the effective inventory. A stable file keeps its
404.
A virtual release that rotates under a plan makes the server answer the
plan's subtitle window with 409 `subtitle_source_changed`. The player
replans, but the fresh plan keeps the selection the server carried, which is
the now-dead ordinal, and the ordinal only means anything inside one
inventory: production re-selected ordinal 0 three times and ended on
"Subtitles couldn't load".

The refresh now re-selects from the inventory the replan returns. The track
the viewer was watching is identified by language, delivery class and flags;
if the new plan's ordinal no longer names it, the replacement is the same
track by identity first, then any track of the same delivery class, and only
when the class itself is gone does it stop and leave the player's own
failure on screen. The delivery class mirrors the server's muxer
preservation, so a text track never stands in for a PGS one.
The startup guard belongs to the session and fired at 60 s, but every
adopted transport asked for a fresh window and got one, so under
`quality:auto` the route ladder spent three more windows and the viewer saw
"No playable version found" only at 186 s.

Only a transport that has already played now gets a fresh window (a real
reconnect is a new start). A transport that replaces a failed start keeps
whatever is left of the deadline it began with, and one adopted after it has
passed is not loaded at all: the transport effect surfaces the retryable
error instead. A missed deadline on the session's own start is terminal for
the same reason — no lowering, no failure-recovery replan — and its Try
again starts a fresh session with a fresh budget. A missed deadline on a
replacement after playback started still lowers, because that stream was
working and its start is a new one.
A provider re-list churns a virtual row's ?result= token. When the new id's
path is already owned by a duplicate row of the same release, the required
adoption can never match: the SQL fence refuses it, the saver counts it, and
at the bound it stamps the requested row's terminal failed verdict. Production
logged 80 such refusals in 25 minutes for one 4K row, and the probed inventory
never landed.

Land the measured inventory on the requested row, metadata-only, when the
candidate path is owned by a sibling the catalog groups with it as one release
(the version list's own rule). The pin does not move; only the tracks are
stored. A genuinely different release still rotates to its owner row, and an
unverified foreign candidate is still refused.

Two adjacent holes kept the row empty after that:

- the pre-play probe chain treated a probe stamp as probed even when the stamp
  carried empty track arrays, so a row whose write had been refused (or whose
  evidence had been invalidated) was never re-probed (40 skipped chains for the
  played 4K row);
- a resolver-certified same-release rematch that could not adopt its new id
  counted as a stale-pin refusal, so a duplicate owning the id marched a
  healthy row to a terminal failed verdict. It is now logged with its reason
  and not counted.
After a window budget refusal the server starts a covering extraction so the
retry is a cache hit instead of another 26 s relay read. That extraction was
admitted like any opportunistic prefetch: it skipped whenever the request path
was saturated or a client read had been shed, and it drew from the single
detached slot a 4K session's own PGS fill holds for a minute and a half. In
production the warm was shed 1.6 ms after the 503 and the retry re-extracted
26 s and failed again.

A read a refused request is waiting on is not opportunistic. It gets a
reserved per-source admission class (one slot, bounded wait) that neither a
client window nor a background fill can hold, skips the opportunistic shedding
gates, and logs a warning instead of a debug line when it is still refused.
Opportunistic prefetches keep their old behavior.
…s final

The page recovery ledger was keyed by the page position. A client re-anchors a
few seconds forward on every bitmap-page retry, so each retry opened a fresh
wait with a fresh budget: the fill spent its 90 s, the next page never
inherited that, and the overlay stayed on "Loading subtitles..." instead of
reaching the final subtitle_page_unavailable answer the path already defines.

The progressive artifact is a per-track object, so its wait budget is too. A
page at any position of the same track inherits the wait the first refused page
opened, which makes the bounded final answer reachable; a page the artifact did
serve still clears the wait.
A subtitle window refused for its budget answers 503 with Retry-After and
promises the retry is served from the server's recovery extraction. When that
promise does not hold, the client kept the retryable ladder running for twelve
attempts at ~26 s plus Retry-After each, showing "Loading subtitles..." with no
cues and no affordance for a quarter of an hour.

After the second consecutive retryable refusal with nothing on screen, the
fetchers now report a stalled track while they keep retrying in the background.
The player shows a card with Retry and Turn off, and a window that finally
streams in clears the state. The terminal budgets are unchanged, so a
retryable answer still retries and a spent ladder still ends the track.
…very pool

A guard built as a struct literal rather than through the constructor carries a
zero recovery limit, which makes its recovery channel unbuffered and turns every
waiting read into a 20 s shed. Fall back to the per-source constant, the same
way the other pools already do.
…h its reason

A breach's recovery warm led by one 30 s grid cell, so it reached exactly the
next request. On the measured 4K source the warm took 64.5 s to build 150 s,
the client walked a full 120 s window meanwhile, and the retries the 503
promised (1740-1860 and 1800-1920) ended 30 s past the artifact's 1830 end.
The covering lookup correctly rejected them and each paid the full 26 s relay
read again.

The warm now leads by one full client window, so those retries are inside it.

The retry that did land inside the warm's range arrived while the warm was
still running, joined its in-flight window, timed out of the 5 s wait and
answered a generic subtitle_source_unavailable. The in-flight window now
carries the reason that started it, and the backoff a breach arms records its
own code, so the retry keeps the budget answer and its Retry-After. A waiter
never starts a second warm.
The measured deep page fails because the fill cannot reach it, not because the
90 s wait is short: the page-driven fill parsed 1.0-2.3 MB of .sup in 95 s
(~1x real time) toward a page 1320 s into the track, about 20 minutes away,
while the client's retry ladder is roughly 5 minutes. Covering that cost would
only hold the spinner past the point the client gives up.

The wait now ends with the bounded final answer as soon as the fill's own
measured advance proves the page unreachable inside the wait that is left (the
media seconds it parsed over the wall seconds between refusals). A 2x margin
keeps a merely tight estimate retryable, since a fill speeds up when the
competing transcode pauses. The 90 s outer bound is unchanged, the final
answer still carries the coverage it reached, and it now logs the start,
watermark, wait and measured rate.
The progressive remux never read Range, so bytes=0-1500000 received the whole
title (920 MB measured). Its body is generated from a media position, not read
from a seekable file, so only a prefix is addressable:

- bytes=0-N answers 206 with Content-Range: bytes 0-N/* and ends after N+1
  bytes, which is the prefix the client asked for;
- a range that starts past zero, a suffix range, or a multi-range set answers
  416 with Content-Range: bytes */* before any FFmpeg work. Restarting the
  generation at a byte offset has no media position behind it, and streaming
  from zero is the behavior being fixed;
- no Range, bytes=0-, and an unparseable Range keep the previous 200 chunked
  response byte for byte.

The v2 handler returns on the unsatisfiable range without indicting the
candidate, rotating a release, or writing a second status.
A bitmap page whose fill advanced but could not cross the page inside the
client's own retry ladder kept answering retryable until the client gave up
(1074011 at 1080 s: page_too_costly + 3x page_not_ready over 36 s, no paint).
The reach check projected against the server's 90 s window only, so a fill that
was moving never looked too slow. The projection now uses the shorter of the
two windows, floored at the client's first retry step so a page the fill is
about to reach stays retryable. Once a page is answered finally, its fill is
canceled unless another page of the track is still waiting: production's
answered page read to 95 s and 3.1 MB for nobody.

Also repair a stamped row with no inventory on selection (the gate the web
pre-play bar uses) and on the single-file versions check, and pin the paused
window the lifecycle sweep reaps abandoned rows in.
…ctor

A laptop-width player put its only audio control inside "More player options",
so the validation run reported no in-player audio menu on the 4K transcode; the
menu it opened was the plan's, but nothing on the bar led to it. The minimised
(background) bar had no audio control at all. Both now render the same selector
the in-player menu uses: the compact bar beside captions, the minimised bar in
its button cluster. The minimised bar's pick applies to the live session at the
position the bar shows, so it cannot start a new playback at the stored resume
position, and the control stops pointer/click propagation away from the seek
surface underneath.
… fixture honest

The reach check moved into pageReachVerdict so the changed-lines lint pass
(nestif) accepts it. The selection-gate test's "fresh inventory" fixture carried
a stamp with no tracks, which the new gate correctly re-probes; it now carries
the audio row the stamp is supposed to describe.
… slow seek anchor

A spent page wait outlived the session that opened it: the ledger was keyed by
track alone and never expired, so production carried waited=9m54 into a new
session and answered its first page in 1 ms with covered=0, making every later
page of that track terminal on arrival. A seek inside a session inherited the
same spent total. The ledger is now keyed by track and playback session, and a
seek (a page behind the wait's page, or more than one page ahead, which a 75 s
retry ladder cannot reach) opens a new wait for the page it lands on. Each wait
still ends bounded, by its own measurement.

The reach projection also only looked at the watermark delta between two
refusals. A jump in that interval looked fast while the fill was still ~20 s
from the page, so 1074011 at 1200 s spent the whole client ladder on
page_not_ready. The rate is now measured from the page's own first refusal,
alongside that page's remaining client ladder, so a page projected past the
ladder answers at the second or third retry. A page the fill is about to cross
still stays retryable.

Answering a page finally now clears every other position its session had
waiting before the fill-cancel check. Production kept a fill running to
00:52:29 because an abandoned 1200 position was still inside the 75 s window;
another session's waiting page still keeps the fill, as before.

A copy-video seek anchor whose keyframe index cannot be read inside the start
budget no longer fails the start. It begins the copied stream from the requested
position with the non-anchored timeline (copy_seek_anchor_resolved=false) and
logs the degradation; a probe that answers still anchors. The start budget is
unchanged.

Tests: a new session and a seek start a fresh wait and still end bounded; a
page projected past the ladder answers by the third retry while a near page
stays retryable; an answered page leaves the waiting set and stops the fill;
another session's page keeps it; an anchor-index timeout starts without the
anchor and a normal index still anchors.
…s a seek

A 75 s retry ladder can advance up to two 120 s pages at double playback speed,
so only a jump beyond that is the viewer seeking. A tighter threshold would
restart a healthy wait on a fast-playing client.
The ledger is per playback session and track now, and the wait belongs to the
viewer's session, not to a page or the artifact. Comment-only.
A seek on a progressive remux closed the player. 0f1278a read Range on the
remux and answered 416 for anything but a bytes=0-N prefix, so the byte-offset
range a media element sends when it resumes its own read became fatal: the
element reports a media error, the failure is classified as a decoder verdict,
and the route is failed until the session ends at the media page.

A remux body is one forward-only generation anchored at the plan's start, so a
start offset has no media position to resume at — but it is still not an error.
Answer it the way the transport answered before it read Range: the whole
stream from the generation's start. The prefix answer (206 with
Content-Range: bytes 0-N/* and a truncated body) and the no-range 200 are
unchanged, and a seekable file keeps 416 with bytes */total through
http.ServeContent because the remux output length is never known.

Client: a progressive remux no longer trusts the plan's can_seek_anywhere
claim — only the element's own seekable range is seeked natively, everything
else reanchors so the server is asked for a stream that starts at the position.
A media error on a played progressive remux is routed to the reconnect at the
playhead unless it is a decode error, so a refused offset can no longer fail
the route and leave the watch page.
A copy-video seek anchor probe pays a provider open plus a byte seek into the
release plus a frame read, but its first attempt was sized from the link's
provider-listing latency. On a link that listed in 3.6s and needed 11.65s to
anchor a deep position in a 4K remux, attempt 1 expired at 7.28s, the retry
laddered to 14.57s, and the start answered in 19s.

Record what the probe itself cost per source and keep it for the anchor cache's
TTL, so the next start's first attempt is sized from evidence instead of from
the floor, which the two-minute link window had already let lapse between
seeks. A budget expiry records that budget as a lower bound, a success records
the measured cost, and the hint is twice the slowest recent observation,
bounded by the per-probe cap.

Log the two facts a log could not show before: a resolved anchor with its cost,
and a proven cache hit, so a release reads as known good and a zero-probe seek
is visible. A degraded start records its session, source, reason and probe
budget hint once instead of leaving one bare WARN per seek.

The detached probe's own budget expiry logs at DEBUG rather than WARN: it is
reaped milliseconds after the caller that owned the budget already returned,
which made a draining first attempt read as a retry that never opened the
provider. The classification itself is unchanged: our own budget is still not a
provider verdict, and an external kill and an upstream 5xx stay transient.
…past

A windowed bitmap page carries its own position and the extract seeks to it,
but the pre-extract gate priced the container prefix in front of it. Production
answered a properly bounded page with 503 subtitle_page_too_costly in 6-12 ms,
27 times, without a byte read, and the fill that refusal started was cancelled
by its waiter and restarted from zero.

Measured with the production argument shape against a Range-honoring source: a
120 s page at 3000 s of a 3600 s / 101 MB cued MKV reads 13.0 MB, where the same
page without Range reads 93.9 MB and the whole file 102 MB. An MKV without cues
scans even over Range (114 MB), and every container scans over a source that
answers 200, so the runtime read cap and the extract deadline remain the bound
for the case the seek cannot help.

- price the page's own window; refuse only a window that cannot be read inside
  one page extract at the measured read rate
- size the read cap from the window (48 MB opening cost plus twice the window,
  floor 64 MB, ceiling 3 GB), keeping the 256 MB cap when nothing can price it
- do not price a window from the link's throughput when the container's byte
  rate is unknown
- let a page-driven fill outlive the page's wait and survive the page's final
  answer: its parsed prefix is the next request's head start, and cancelling it
  is what restarted the same read from zero

Text tracks: a live layout that differs from the plan only in metadata (a
container with no language tag) is no longer called a rotation, so a successful
extract is not withheld from the next request. A background fill's layout
verdict answers 503 with Retry-After and subtitle_source_unavailable instead of
the 409 that tells the client to replan; the serve path's own probe keeps 409
for a real rotation.

Tests: the measured boundary (the page is not refused and the emitted args carry
-ss with -copyts), the cost refusal keeping its fill and progress across a
second refused request, a metadata-only drift served to the next request, and
the remaining refusal answering 503 with Retry-After rather than 409.
@randrini
randrini marked this pull request as ready for review November 20, 2026 16:44
@randrini
randrini merged commit b9ee2f3 into main Nov 20, 2026
17 checks passed
@randrini
randrini deleted the integration/playback-combined2 branch November 27, 2026 13:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants