Repository navigation
Conversation
The session hook built `loadSession` from the `versions`, `playbackVariants` and `resumeHints` props, so a new versions array changed its identity. That identity ran through `selectFileId` -> `loadSession` -> `replan` -> `recoverFromFailure` (the player's `onPlanFailure`) into the transport effect's dependency list in VideoPlayer.tsx:3780-3795. Every catalog projection of a title — the version-liveness check's stamped verdicts, an inventory poll's merged rows, a watch-detail refresh — therefore tore the transport down and reassigned `video.src`, restarting playback from the plan's start position. Those three props are file-selection inputs, not transport inputs. Read them through refs so a projection can change what the menus show without changing any callback the transport effect depends on. A start still selects from the list as it stands when the request runs, and the subtitle remap for a version switch still uses the newest rows. Regression test: restamping the version list mid-play leaves the media element, its `src`, and the plan revision untouched, and issues no replan.
A version check resolves the provider per row, and the player was issuing hundreds of them per session: one per liveness chunk for every `versions_updated` event, on every remount, and on every invalidated re-render. Each answer also restamped the version list, which is what tore the transport down (fixed separately). Route the check through one gate per row set (the sorted file_ids a single request names): - one request in flight per row set; a second caller waits on the first; - an answer stands for the 5 min freshness window, or ten times the check's own latency when that was slower than 1 s, capped at 15 min; - a catalog `versions_updated` event may force an earlier check, but not more often than once per row set per 30 s, and the event burst is coalesced into one invalidation (750 ms window, 3 s ceiling) instead of one per row. A row set that actually changed is a new key and is checked at once, so the gate never polls and never delays a genuinely new list. A failed check drops its record so the next caller retries instead of reusing a stale verdict.
Collaborator
Author
|
Superseded by #459, which contains this change plus the rest of the playback reliability bundle. Closing to keep the review surface to one PR. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on
integration/playback-combined(207e14d21, the deployed combined build). Do not merge before the base; this branch only carries the two commits listed below.Related issue: N/A
Validation tasks: none
Problem
A 4K transcode session on the deployed combined build rebuilt its own media pipeline continuously while the server was healthy. Chrome, 2026-11-15 09:05–09:11Z:
getPlaybackSegmentrequests, all 200, p50 250 ms, p90 928 ms, no missing segments, no wait timeouts,restart_count=0;kWebMediaPlayerCreated/ 107kWebMediaPlayerDestroyedin 170 s, 508master.m3u8loads in 300 s,currentTimenever past 19 s, zero decoder errors,paused=false,readyStateoscillating;currentTimestuck at 0;checkCatalogVersionscalls in those 5 minutes, p50 1838 ms, median cadence 74 ms in 12-call bursts;checkCatalogVersionscall; median gap from a reload to the next check was 393 ms.Every version check rewrote the player's transport, so playback restarted from the plan's start position and never advanced.
Approach
The coupling.
usePlaybackSessionbuiltloadSessionfrom theversionsprop, so a new version list changed the callback identity. That identity reached the transport effect:selectFileId(web/src/player/hooks/usePlaybackSession.ts:2407, deps includedversionsandplaybackVariants) →loadSession(:2474, deps includedversions) →replan→recoverFromFailure→onPlanFailure(web/src/player/components/WatchPage.tsx:1691) →reportCurrentPlanFailure(web/src/player/components/VideoPlayer.tsx:1177-1201) → the transport effect's dependency list (VideoPlayer.tsx:3780-3795).That effect is what owns the media element: its cleanup removes
srcand callsvideo.load()(VideoPlayer.tsx:3772-3773), and init reassignsvideo.src(:3705,:3739). One new versions array was therefore one WebMediaPlayer destroy/create pair and one manifest reload, starting again at the plan's start position. The liveness check is one source of new lists (WatchPlaybackChrome.tsx:742-743stamps its verdicts onto the rows); an inventory poll's merged rows or a watch-detail refresh produced the same churn.The fix. The version list and the other file-selection inputs (
playbackVariants,resumeHints) are not transport inputs. They are now read through refs, so a projection changes what the menus show without changing any callback the transport depends on. Starts still select from the list as it stands when the request runs, and a version switch still remaps the subtitle track against the newest rows.A check result no longer reaches the plan at all. If one ever genuinely needs to change the plan, it can do so through an explicit replan (non-playing state); nothing in this path reassigns
video.srcanymore.The check itself. It resolved the provider per row, and the player was asking for it hundreds of times: once per chunk for every
versions_updatedevent, on every remount, and on every invalidated re-render. Checks now go through one gate per row set (the sorted file_ids a single request names):versions_updatedevent may force an earlier check, but not more than once per row set per 30 s, and the event burst is coalesced into one invalidation (750 ms window, 3 s ceiling) instead of one per row.A row set that actually changed is a new key and is checked at once, so nothing here polls and a genuinely new list is never delayed. For the measured title (452 virtual rows, 12 chunks) the steady state is 12 checks per 5 minutes, one per chunk, instead of 452 in 5 minutes; a stamp burst adds at most one more per chunk per 30 s.
Validation
207e14d21— restamping the version list mid-play callsHTMLMediaElement.load()once (the transport teardown) and the plan revision/srcassertions fail with it. After the change the element, itssrc, andplanRevisionare unchanged and no start or replan request is made.npx tsc -b: clean.VideoPlayer.test.tsx,VideoPlayer.reconnect.test.tsx,versionLiveness.test.ts,useStampedVersions.test.ts,WatchPage.test.ts,RealtimeEventsProvider.test.tsx.usePlaybackSession.test.ts(228) and thesrc/playback,src/pages/ItemDetail/*Content,src/hooks/queries/mediaSurfaceRefreshfiles also pass.versions_updatedmarks produce one check, and a thirteenth inside the floor produces none.eslint .reports 0 errors / 88 pre-existing warnings. Prettier--checkon changed files: clean.make verify-local-paths: clean.git push --no-verify: this checkout cannot buildweb/dist(tsrsbinary missing), so the hook'sgo build ./.../go vetsteps fail before reaching anything this branch touches, and the full-tree Prettier pass did not finish on the loaded machine. CI runs both.Risks
versions_updatedstamp that lands within 30 s of the previous check of the same row set now reaches the menu with that check's answer, and the re-probe waits out the floor. The check that ran is still authoritative for the rows it saw; only a second probe is deferred. Before this change the same event re-probed immediately, which is what produced the storm.AI Disclosure
Posted by an AI agent (Muse Spark, OpenCode harness).