Skip to content

fix(playback): keep version rotations from dropping selected tracks - #448

Closed
randrini wants to merge 1 commit into
mainfrom
fix/rotation-respects-selection
Closed

randrini wants to merge 1 commit into
mainfrom
fix/rotation-respects-selection

Conversation

@randrini

@randrini randrini commented Nov 14, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

A deployed build played a different file from the one requested in 8 of 12 measured starts. The same request flipped between versions minutes apart: one pair resolved to the requested row at 14:02 and to a different row at 14:07 and 14:08, and another resolved to a different row twice at 14:12. Each session reported one start, so this is not a client retry loop.

The worst case requested a row with two audio tracks and four PGS tracks and played a row with one E-AC3 track and one SRT track. The action bar had advertised the selected row's tracks.

The acceptance change in #447 (Usable() in internal/scanner/virtual_probe_guard.go:117) lets a candidate whose served size contradicts its declaration reach the plan. The start path then rebinds to the catalog row that owns the concrete candidate URI (resolveVirtualPlaybackSource, playback_virtual.go:3413), so the plan's effective file becomes that row. Probe evidence takes the same path through virtualProbeEvidenceRotateTarget (playback_virtual.go:6106) and logs reason=sibling_owner_rotation (playback_virtual.go:6157). rotateVirtualSourceToOwnerRow (playback_virtual.go:7185) keeps the probed tracks, so a foreign release with fewer tracks replaces the selected row's inventory.

Approach

A rotation may adopt the identity of the row that owns the bytes. It may not change which version the viewer selected, and it may not drop an audio or subtitle track.

  • Same-release duplicate rows share candidate URIs. When the exact-path owner is provably the same release (virtualSiblingOwnerSharesRelease), the plan keeps the requested row and its inventory instead of rebinding to the duplicate.
  • A rotation to a different release is allowed only when the served runtime agrees with the item and the effective row offers at least as many audio and subtitle tracks as the selected row. Otherwise the candidate is rejected and the next listed candidate is tried. A track-poor substitute is worse than an honest failure.
  • A rotation that does happen is reported as a substitution (SubstitutedFromFileID plus version_not_playable) instead of silently naming a different file.
  • Probe-evidence rotation, the same-release size-mismatch fallback, the stale-source fallback, and the late owner-row reanchor apply the same track check, so no catalog write or plan moves the selection onto a poorer row.

Usable() is unchanged: a size-gapped probe still inventories and plays its own row. Only the row-switching decision is constrained.

Validation

  • go build ./... passes after make embed-stub.
  • go vet ./internal/api/handlers ./internal/scanner ./internal/playback passes.
  • go test -count=1 ./internal/api/handlers ./internal/scanner passes. ./internal/playback has two failures on this base (TestOnDemandSubtitleSegmentsDoNotWaitForTheStream, TestServeExtractDiscardsACappedDemuxCopy); both reproduce at 303f3eccc without this change.
  • go test -race -count=1 on the three new tests passes.
  • make verify-playback-fixtures reports the fixtures are current.
  • make lint-changed BASE_REF=kipsilabs/main reports 0 issues.

Fail-before at 303f3eccc: the selected row played as the foreign owner row, the substitution reported substituted_from_file_id=0, and the evidence write landed on the poorer owner row. Pass-after: the effective row is the selected row, a genuine substitute reports the requested row as its source, and the poorer owner receives no write.

Base note: kipsilabs/main is 303f3eccc, and #447 is still an open draft (head 59da4565e). The branch is based on main as requested. The same commit was applied to a throwaway merge with #447 and the new tests pass there. The start-loop conflict is #447's duration exemption, and the rotation guard rejects a contradictory runtime independently of it.

Related issue: N/A

Validation tasks: none

Risks

None identified. The change only refuses a rotation the selected row did not ask for. Ordinary auto selection on a provider-neutral placeholder has no tracks to lose and keeps its existing behavior.

AI Disclosure

  • Harness: OpenCode
  • Tool(s): OpenCode Code Mode
  • Model(s): DeepSeek V4.1 Flash 1017 (deepseek-v4.1-flash:1017, ollama-cloud)
  • Involvement: Fully AI-generated, human verified
  • Adversarial review: The rotation paths were traced against the measured logs; the three new tests fail on the base commit and pass with the change.

Posted by an AI agent (Muse Spark, OpenCode harness).

@randrini
randrini force-pushed the fix/rotation-respects-selection branch 2 times, most recently from db2a2e2 to 9087333 Compare November 14, 2026 15:54
@randrini

Copy link
Copy Markdown
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.

@randrini randrini closed this Nov 15, 2026
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