You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(playback): keep the latest subtitle in playback history whatever order finalizations arrive in - #4620
Closes#4614
Related issue: N/A
Validation tasks: none
Other clients: N/A (no client-visible change)
Admin playback history, and Tracearr, which reads it, can show a subtitle the viewer had already switched away from. The history row ordered its subtitle by ended_at, and ended_at only moves when a finalization gets further into the play. A finalization that got no further and repeated the row's subtitle was dropped. A delayed earlier finalization with another subtitle could then replace it. For a play that shows A, switches to B and back to A, with finalizations processed in the order A, then the final A, then B, history ended on B. A subtitle change on its own also moved ended_at past the real stop, and a lifecycle sweep that only knew the play's starting subtitle could put it back and stamp the sweep time as the play's end.
This change gives the subtitle its own ordering, the way the end reason already has one, so history keeps the latest subtitle and ended_at stays at the real stop.
Approach
A new subtitle_at column records when the row's subtitle was last known to be showing. The statement that already orders end_reason by end_reason_at now does the same for subtitle. It runs for every finalization, including one that gets no further, so the final A is no longer lost.
The history upsert no longer writes the subtitle and no longer lets a subtitle change move ended_at.
A lifecycle sweep that ends a play whose attempt row is gone only has the subtitle its live or start row last synced. It now orders that subtitle by the row's sync time, or the play's start when the row has none, rather than by sweep time. A subtitle a finalization recorded later is kept, and a live row synced after it still wins.
Rows written before the column existed are ordered by their ended_at as it was before the finalization, as before, so a play in progress during the upgrade keeps its subtitle.
A native play's history entry takes the subtitle its attempt's last replan committed, as the sweep and the detached stop already did. Since history now keeps the subtitle recorded latest, a copy on another server that missed a replan would otherwise replace the real stop's subtitle when it tears down or ends later.
Validation
Database tests for the out-of-order finalizations, a subtitle-only finalization, rows from before the column, and the sweep's start-row, later live-row and empty-start-row cases fail on main (wrong subtitle, or ended_at moved) and pass here.
On a dev deployment, a real play that switched subtitles A → B → A and stopped recorded A in admin playback history, with ended_at at the stop. A play with no switch recorded its subtitle and stop time as before. On main, replaying two delayed copy finalizations of that play through the history store (the final A, then a stale B) left the row on B, with ended_at 3 s past the stop. On this branch the same replay keeps A and the real stop time.
The sweep cases were checked by the database test only. They need an attempt row to expire before the sweep ends the play, which the deployment can't produce on demand.
The live checks ran on 22f9d9b. The review follow-ups only change rows recorded before the column existed, covered by a database test, and split a test.
go test for the handlers, API v2, worker and migrations packages against a migrated database, make lint-changed, and make migrate-validate pass.
Review (after merging main): the three database tests fail on the merge base with main and pass on the head. Replaying a stale copy's teardown that got no further, stamped after a real stop that was written last, kept the stale subtitle on e46fcc0 and the right one on the merge base. TestStaleCopyRecordsTheAttemptsSubtitle covers that copy for a teardown and an expiry; it fails on e46fcc0 and passes here. The handlers, API v2 and worker packages pass against a migrated database, and make lint-changed is clean. The stale-copy case needs two servers that hold copies of one play, so it was not checked live.
A migration adds one nullable column with no backfill, so it is instant on large history tables.
Ordering still uses each API server's clock, as the end reason does. A sweep compares a live row's sync time, which the database stamps, against a finalization's server time, so clock skew larger than the gap between the two writes could still misorder them. On main the sweep always won.
During a rolling deploy, a node still on the old writer can change subtitle without moving subtitle_at, so a play finalized on both versions in that window can still misorder.
A sync row's time is when the row was written, not when its subtitle was committed. A copy that missed a replan can re-sync a stale subtitle with a fresh time; the sweep only uses that time when the attempt row is gone.
Unchanged: a detached finish that fills its subtitle from the live row still stamps it at its own end time.
A stale copy whose attempt read fails, while the real stop's write is delayed, still records its own subtitle at its own end time; the failed read is logged.
One extra row write for a finalization that ends later and carries no end reason (a recoverable teardown); stops already rewrite the end reason in the same statement.
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.
Council review
Plan round: 1, on the unfixed head 4eb4d4a (no scores; plan reviews)
first run ended without a result; retry on b1f15de: 9/10, no findings
—
Adopted: Sol's point that treating every sweep subtitle as start-only would drop a live row synced after the recorded subtitle, so the sweep orders by sync time instead of a flag (Opus's smaller form pointed the same way). Kept: the sweep handling Opus proposed cutting, because the database test shows main moves ended_at to sweep time there. Left open as risks: wall-clock ordering, and a stop that reads its plan before another server's replan commits (both predate this change).
Background review: Sol's S1 (a pre-column row lost its order when a further-reaching finalization moved ended_at first) is fixed in aef736c, with a test. S2 (rolling deploy) and S3 (a stale copy re-syncing with a fresh time) are listed under Risks; Sol still rates S2 open after round 2, and guarding it would break the sweep case this PR fixes. S4 (a flat-counter stop after a teardown keeps the teardown's ended_at) is the existing end-time rule, unchanged here.
Maintainer review: 2 rounds, last reviewed ee018ce
Fixed: a stale copy's teardown beating the real stop's subtitle (Sol, Gemini) and local-copy stops ignoring the committed plan (Gemini), in ee018ce; the admin API doc's missing subtitle rule, in fc4c91f; the attempt read's guards (Gemini), in a6dba23. Left open: a failed attempt read on a stale copy (Sol), a duplicate attempt read in the sweep and detached stop (Opus, Sol), and the rules for a play whose attempt is gone, which predate this change.
AI Disclosure
Harness: Claude Code in T3 Code
Tool(s): GitHub CLI, Go toolchain, PostgreSQL, a disposable Silo dev deployment
Involvement: AI-assisted implementation and verification
Adversarial review: a high-level code-review (three finders) found the empty-start-row and pre-migration-row cases, both fixed with tests; a plan round and a background review by the council are in "Council review" above; a simplify pass ran on the change.
Keep the latest subtitle in playback history regardless of finalization order
Subtitle updates in admin playback history are now ordered by a new subtitle_at timestamp instead of ended_at, so out-of-order finalizations keep the latest subtitle. Adds a nullable subtitle_at column to admin_playback_history via migration.
PlaybackHandler.recordAdminEnd resolves the subtitle from the matching native attempt's committed plan when no earlier subtitle timestamp is supplied; admin stops and lifecycle sweeps go through this shared path. The lifecycle sweep orders the subtitle from the session's last sync or start time (playback.go, playback_lifecycle_sweep.go).
The history upsert and facts update in playback_admin_store.go compare incoming subtitle timestamps against subtitle_at, falling back to ended_at for legacy rows.
Adds database tests for out-of-order finalizations, subtitle-off cases, legacy rows, and lifecycle sweeps (playback_finish_history_test.go), and documents the new ordering rule in admin-api.md.
Behavioral Change: subtitle updates no longer depend on whether a finalization advances ended_at; a subtitle-only change updates the subtitle without moving the end time, and legacy rows get subtitle_at backfilled from ended_at on first upsert.
…order finalizations arrive in
Admin playback history ordered the subtitle by ended_at, which only moves
when a finalization gets further. A finalization that got no further and
repeated the row's subtitle was dropped, so a delayed earlier one with
another subtitle could replace it, and a subtitle change alone moved
ended_at.
The subtitle now has its own subtitle_at, ordered like end_reason and
end_reason_at, and no longer moves ended_at. A lifecycle sweep that only
has the play's live or start row orders that row's subtitle by when it was
synced, so it no longer replaces a later recorded subtitle or stamps the
sweep time as the play's end.
Closes#4614
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
No actionable comments were generated in the recent review.
Walkthrough
Playback history now orders subtitle updates by subtitle_at rather than ended_at. Finalizations can record the committed plan subtitle, and lifecycle sweeps pass subtitle timing derived from session synchronization or start time. Database-backed tests cover out-of-order finalizations, legacy rows, and sweep behavior.
The migration adds subtitle_at. History storage orders subtitle updates by this timestamp, using ended_at as the fallback for older rows. Tests cover out-of-order finalizations and legacy rows.
Finalization resolves the committed plan subtitle when the timestamp is zero. Lifecycle sweeps pass a timestamp based on the session update time or start time; when the current plan supplies the subtitle, the timestamp is cleared. Tests cover sweep behavior and live-row synchronization timestamps. Documentation describes subtitle reporting in playback history.
Playback history now orders subtitles by their own timestamp, which fixes out-of-order finalizations. One rare edge case remains, where an attempt-read failure on a stale copy plus a delayed real stop can leave an outdated subtitle. This is limited in scope and was already possible before this change.
Security architecture risk: Minimal · up to 8ad8f
The change separates subtitle recency from playback end time. The inspected changes establish no expansion of access or authority, or weakening of stop-time cleanup.
Retained concerns
No architecture-level concerns identified.
Security review details
Security Blast Radius
inferred — The inspected changed sink is subtitle metadata in shared playback-history rows keyed by session. Conflict updates do not replace the row's user or profile identity, bounding the observed effect to history contents rather than transferring ownership.
Trust Boundaries and Controls
observed — The new committed-subtitle lookup excludes Jellyfin-compatible sessions and non-UUID identifiers. It requires the retrieved attempt's user and profile to match the session before using its plan, preventing a mismatched attempt from supplying subtitle data through this helper.
Resilience and Maintainability Implications
observed — The new history lookup occurs after the existing stop-authority and transport-cleanup calls. Stream denial, proxy-grant deletion and node-recipe cleanup have not been moved behind the added history work, so the changed ordering does not make those cleanup calls conditional on subtitle lookup success.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
The title names the main change: playback history keeps the latest subtitle regardless of finalization order. The changeset adds a subtitle_at column and orders subtitle updates by it, which matches t…
Description check
The description explains the problem (subtitle ordered by ended_at, dropped same-subtitle finalizations, sweep stamping), the approach (subtitle_at column, upsert changes, sweep ordering by sync time,…
Linked Issues check
[#4614] The issue requires that admin history keep the subtitle of the newest finalization, including a finalization that adds no watch data, without moving ended_at for a subtitle-only change or lett…
Out of Scope Changes check
The changes that go beyond the core ordering fix are tied to it. recordCommittedSubtitle in playback.go supplies the attempt's committed subtitle to a native play's history entry. The PR states that, …
Full details: Title check
Explanation
The title names the main change: playback history keeps the latest subtitle regardless of finalization order. The changeset adds a subtitle_at column and orders subtitle updates by it, which matches the title. The title is 98 characters, which is long, but it is still a single clear sentence about the primary change.
Full details: Description check
Explanation
The description explains the problem (subtitle ordered by ended_at, dropped same-subtitle finalizations, sweep stamping), the approach (subtitle_at column, upsert changes, sweep ordering by sync time, native attempt committed subtitle), validation, and risks. It matches the changeset closely.
Full details: Linked Issues check
Explanation
[#4614] The issue requires that admin history keep the subtitle of the newest finalization, including a finalization that adds no watch data, without moving ended_at for a subtitle-only change or letting a sweep stamp its own time as the end. At the reviewed head, playback_admin_store.go removes the subtitle write and the ended_at-gated subtitle clause from the history upsert. A new subtitle_at column (migration 20261119234416) orders subtitle updates in queueHistoryFacts, which runs for every finalization. The clause is $11::timestamptz >= COALESCE(subtitle_at, ended_at), so the latest subtitle wins. Legacy rows keep their ended_at order: the upsert backfills subtitle_at from the old ended_at before ended_at moves. The sweep path passes the session's sync time (LiveSession now loads last_sync_at into UpdatedAt) or start time, so a later-known subtitle is not overwritten. Database tests for out-of-order finalizations, subtitle-only finalizations, legacy rows and sweep cases are described in the PR. I did not run them; the PASS rests on the diff and the reported test results. The residual risks the PR lists (clock skew, mixed-version rollout, stale-copy attempt-read failure) are outside the issue's stated scope.
Full details: Out of Scope Changes check
Explanation
The changes that go beyond the core ordering fix are tied to it. recordCommittedSubtitle in playback.go supplies the attempt's committed subtitle to a native play's history entry. The PR states that, because history now keeps the latest subtitle, a stale copy on another server could otherwise replace the real stop's subtitle. This connects directly to the issue's goal. The lifecycle sweep change (playback_lifecycle_sweep.go) and the admin API doc update (docs/admin-api.md) document and implement the same subtitle ordering rule. The contract list in scripts/ci/db-contracts.txt and the sweep tests support the new behavior. I found no unrelated functional change in the reviewed code.
Finishing Touches
Generate unit tests (beta)
Commit to this branch
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info
Run configuration
Source mode: Auto
Repository: Unavailable
Branch: Unavailable
File: No configuration file from this repository applied
Commit: Unavailable
Layers: Organization UI
Review profile: CHILL
Plan: Advanced
Run ID: 6252da78-2769-440f-932c-6f4e02a0b1e0
Commits
Reviewing files that changed from the base of the PR and between 891b6f4 and 8ad8f27.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 3 remain after this review.
The reason will be displayed to describe this comment to others. Learn more.
S2 [P2] Keep subtitle ordering valid during rolling deploys
A new replica records A at t1 and sets subtitle_at=t1. A replica running the base writes A at t3 with more progress. Its upsert advances ended_at to t3 and leaves subtitle_at=t1. A delayed new replica write for B at t2 then uses the nonnull t1 as its cutoff and replaces A. Executing the pinned head, base, and head batches in that order produced B with ended_at=t3. The legacy null fallback does not cover previously upgraded rows.
Keep old and new history writers from overlapping during activation, or maintain the subtitle timestamp for legacy upserts at the database boundary. Test a later legacy write of the same subtitle followed by an earlier new write of a different one.
The reason will be displayed to describe this comment to others. Learn more.
Agreed that a node still running the old writer can change subtitle without moving subtitle_at while old and new nodes overlap. That window lasts only for the rollout and affects only plays finalized on both versions during it; afterwards every write orders through subtitle_at. The PR's Risks section now names it. A fix would need the old writer to know the column, which it can't, so I'm leaving it as a disclosed limit.
The reason will be displayed to describe this comment to others. Learn more.
S3 [P2] Order the subtitle observation rather than the replica's sync time
The reconciler copies the local session's subtitle and sets last_sync_at=NOW() on every upsert (internal/worker/reconciler.go:276). One replica can record B during a recoverable teardown while another still holds A and syncs it later. If that replica goes away and the attempt has expired by the time the sweep reads the row, the sweep overwrites B with A. This works with synchronized clocks. I ran the head's live row read and history batch with a snapshot older than the recorded B and a sync timestamp newer than B. History reverted to A.
Carry the subtitle's plan revision through the live snapshot and history, or retain the recorded subtitle when the sweep cannot establish that a snapshot is newer. Test a stale copy that syncs late alongside the existing case where playback really resumed on another subtitle.
The reason will be displayed to describe this comment to others. Learn more.
Right: last_sync_at dates the row write, not the moment the subtitle was observed, so a copy that missed a replan can re-sync a stale subtitle with a fresh time. This only matters when the attempt row is already gone, since the sweep otherwise takes the subtitle from the attempt's committed plan. On main the sweep's subtitle always won in this case, so this narrows the problem without fully closing it. Ordering by observation time would need the sync row to carry when its subtitle was committed; that's a wider change to the live-row contract than this fix, so it's listed as a risk in the PR body.
The reason will be displayed to describe this comment to others. Learn more.
S4 [P2] Keep the real stop time when a prior teardown wrote history
A recoverable teardown records A at t1 with an empty end reason. The same session resumes, switches to B, and then receives a real client stop at t2 with no increase in position or measured counters. The lifecycle records stopped and history takes B, while ended_at remains t1. I reproduced that tuple with the pinned SQL. The base records t2 in this case. A monitor polling ended_after after t1 can miss the row as it becomes final, including when it misses the stop event.
Give the first definitive stop its own timestamp rule when it replaces a recoverable teardown, while keeping later subtitle updates and sweeps from moving that stop time. Cover a terminal stop with the same counters as an existing teardown row.
The reason will be displayed to describe this comment to others. Learn more.
This PR keeps the existing rule that ended_at moves only when a finalization gets further. The issue asked specifically that a subtitle change no longer move it. The case you describe (a later stop with flat counters after a recoverable teardown) behaves the same on main whenever the subtitle doesn't change, so it isn't introduced here. Whether ended_at should follow the latest real stop is a separate decision about the history row's end-time semantics, which the playback-history work for #4615/#4616/#4618 is changing nearby; I've left it out of this subtitle fix.
…oves
A row recorded before subtitle_at existed orders its subtitle by
ended_at. When a finalization that gets further moved ended_at first, the
subtitle comparison that follows used the new end, so a sweep's subtitle
synced after the recorded one lost. The upsert now keeps the old ended_at
as subtitle_at before it moves.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Keeps the history facts test buildable against main, so it still shows
the out-of-order finalizations failing there.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.
The reason will be displayed to describe this comment to others. Learn more.
Major · Maintainability & Code Quality · Quick win
Shorten the new test to restore the lint check.
The supplied ci / Go lint check fails because TestLifecycleSweepKeepsARecordedSubtitleDB exceeds the funlen limit: 114 lines against 100. Extract fixture helpers or split the scenarios into focused tests. Preserve the assertions and database-contract registration.
Tools
GitHub Check: ci / Go lint
[failure] 947-947:
Function 'TestLifecycleSweepKeepsARecordedSubtitleDB' is too long (114 > 100) (funlen)
S2 · P2 · A stale subtitle can be written after a rolling deploy finishes
An upgraded server records subtitle A at t10. A legacy server then records subtitle B at t30. The legacy upsert changes subtitle and ended_at, leaving subtitle_at at t10. If an upgraded server then records a delayed finalization from t20, the facts update compares t20 with t10 and replaces B. This can happen after the last legacy server has stopped, and the wrong subtitle stays in history unless another finalization corrects it. The same sequence on fully upgraded servers keeps B. Legacy upsert · Current facts update
AI disclosure: Reviewed by gpt-6.2-sol using Codex.
On S2 from the round-2 adversarial review: Agreed on the sequence. It needs a legacy server to record a later finalization of the same play during the rollout, followed by a delayed earlier one on an upgraded server, so it is limited to plays finalized on both versions. The cheap guard, also comparing against ended_at, would block a real later finalization after a sweep that recorded an earlier sync time, which this PR fixes. I'm keeping it as the disclosed rollout risk in the PR body rather than trading one case for the other.
The history section described the order rule for every field a
finalization writes except the subtitle, which now has its own order.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The reason will be displayed to describe this comment to others. Learn more.
Review of e46fcc0, which merges main into the branch. The merge was clean; main had changed playback.go and playback_lifecycle_sweep.go (#4611, #4890) but not the subtitle path. The three new database tests fail on the merge base and pass on this head.
Two findings: one inline, and the docs one below. I'm fixing both in commits on this branch, so there's no need to change anything yourself.
Low · the admin API doc doesn't say how history picks its subtitle
The playback history section gives the order rule for each field a finalization writes (device, client, decisions, end reason), but it doesn't mention subtitle. This PR gives the subtitle its own order: the latest finalization decides it, even one that got no further, and a subtitle change no longer moves ended_at. Without a sentence on this, a client author would expect the subtitle to follow ended_at as it used to. AGENTS.md asks that the relevant docs/*-api.md be updated when the contract changes.
I'm fixing this in a commit on this branch, so there's no need to change it yourself.
Other points I checked and am not raising as findings, because they predate this change or the Risks section already covers them:
When the attempt row is gone, a detached finish, or a rebuilt session whose attempt read failed, still takes the live or start row's subtitle and stamps it at its own end time (fillEmptySessionFacts, restoreReconstructedClient). This is the same on main, and the PR lists the detached case as unchanged.
The sweep compares the database-stamped last_sync_at against the API server's own clock. This is disclosed.
After a rolling deploy, a subtitle_at that an old node left behind can still misorder a later sweep. This is the earlier S2, still disclosed as open.
If GetAttempt fails for a reason other than "not found", the sweep falls back to the row's subtitle and stops the lifecycle. This is the same on main.
A stop that reads its attempt before another server's replan commits can record the older plan's subtitle. This is the same on main and already listed as open.
The migration's timestamp is older than migrations already on main. That's fine, because the server runs Goose with out-of-order migrations allowed.
AI disclosure: reviewed with Claude Code (claude-opus-5-5); code-review finders on claude-opus-5-5 and claude-sonnet-5-5; cross-provider round by gpt-6.2-sol, claude-opus-5-5 and gemini-4-neon.
History keeps the subtitle recorded latest, so a copy that missed a
replan on another server could tear down after the real stop was built
and replace its subtitle. A native play's history entry now takes the
subtitle its attempt's last replan committed, as the sweep and the
detached stop already did.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The reason will be displayed to describe this comment to others. Learn more.
Attempt lookup failures permanently record a stale subtitle
A transient GetAttempt failure can overwrite the committed subtitle with a stale value and permanently finalize the lifecycle. Propagate lookup errors through recordAdminEnd so finalization can retry.
Prompt for LLM
File internal/api/handlers/playback.go, lines 1444-1446:
Attempt lookup failures permanently record a stale subtitle
A transient `GetAttempt` failure leaves the stale copy's subtitle in the history entry, which can overwrite the actual committed subtitle and permanently finalize the lifecycle without a retry. Propagate lookup errors through `recordAdminEnd` so finalization can retry rather than recording the stale value.
…on ID
Skip the attempt read for session IDs that can't name an attempt, match
the profile as the other attempt readers do, and log a failed read
instead of dropping it.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Fit: 9/10 · Readiness: 8/10 — conditional (CI green on 8ad8f27)
Fit: this fixes a real correctness bug in admin playback history, which Tracearr and the admin pages read. It reuses the ordering the end reason already has and costs one nullable column with no backfill, plus one indexed read per native play end.
Readiness: the approach holds and every fix has a test that failed on the code before it. What keeps it below 9: a narrow stale-copy case is still open (below), and the stale-copy fix can't be shown on a single test deployment.
Read a6dba23, which no council round covered. Its guards hold: a non-UUID session ID would otherwise fail the ::uuid cast in the Postgres attempt read and log a false warning, a missing attempt maps to ErrSessionNotFound in both plan stores and isn't logged, and the profile check matches the other attempt readers.
Stale copy beating the real stop (fixed, ee018ce). With the subtitle ordered by time alone, a copy that missed a replan could tear down after a real stop had been built but before it was written. The copy's old subtitle then won. A database replay showed the head keeping the stale subtitle where main kept the right one. A native play's history entry now takes the subtitle its attempt's last replan committed, the rule the sweep and the detached stop already used. This also covers a stale copy whose finalization lands after the stop, and a local-copy stop on a copy that missed a replan. Both of those were wrong on main too. TestStaleCopyRecordsTheAttemptsSubtitle fails on e46fcc0 and passes here.
Admin API doc (fixed, fc4c91f). The history section now says how the subtitle is picked.
Attempt read guards (a6dba23). The read is skipped for session IDs that can't name an attempt, checks the profile as the other attempt readers do, and logs a failed read.
Left for the maintainers
A stale copy whose attempt read fails, while the real stop's write is delayed, still records its own subtitle at its own end time. Three conditions have to coincide. It's now logged and listed under Risks.
The sweep and the detached stop read the attempt a second time to get the subtitle. This is correct, and the cost is one indexed read per play end.
Predates this change, follow-up candidates: when the attempt row is gone, a detached finish or a rebuilt session still stamps the live or start row's subtitle at its own end time. The sweep also treats a transient attempt-read error as "attempt gone" and finalizes from the start row. Already listed as open under Risks: wall-clock ordering, the rolling-deploy window, and a stop that reads its plan before another server's replan commits.
Sol's round-2 score rests on the failed-read case above, which this PR introduces but which is narrow, and on the duplicate read. Its third point, that a failed replan rollback can leave a replacement with a newer subtitle live, doesn't hold: that replan returns an error, so the client never receives the replacement plan and keeps the committed one.
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
bugSomething isn't workinggoPull requests that update go codepriority: P2Limited scope, workaround exists, or polishsize/L200–499 added + deleted lines (all files); change volume, not priority.
1 participant
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.
Problem
Closes #4614
Related issue: N/A
Validation tasks: none
Other clients: N/A (no client-visible change)
Admin playback history, and Tracearr, which reads it, can show a subtitle the viewer had already switched away from. The history row ordered its subtitle by
ended_at, andended_atonly moves when a finalization gets further into the play. A finalization that got no further and repeated the row's subtitle was dropped. A delayed earlier finalization with another subtitle could then replace it. For a play that shows A, switches to B and back to A, with finalizations processed in the order A, then the final A, then B, history ended on B. A subtitle change on its own also movedended_atpast the real stop, and a lifecycle sweep that only knew the play's starting subtitle could put it back and stamp the sweep time as the play's end.This change gives the subtitle its own ordering, the way the end reason already has one, so history keeps the latest subtitle and
ended_atstays at the real stop.Approach
subtitle_atcolumn records when the row's subtitle was last known to be showing. The statement that already ordersend_reasonbyend_reason_atnow does the same forsubtitle. It runs for every finalization, including one that gets no further, so the final A is no longer lost.ended_at.ended_atas it was before the finalization, as before, so a play in progress during the upgrade keeps its subtitle.Validation
main(wrong subtitle, orended_atmoved) and pass here.ended_atat the stop. A play with no switch recorded its subtitle and stop time as before. Onmain, replaying two delayed copy finalizations of that play through the history store (the final A, then a stale B) left the row on B, withended_at3 s past the stop. On this branch the same replay keeps A and the real stop time.go testfor the handlers, API v2, worker and migrations packages against a migrated database,make lint-changed, andmake migrate-validatepass.main): the three database tests fail on the merge base withmainand pass on the head. Replaying a stale copy's teardown that got no further, stamped after a real stop that was written last, kept the stale subtitle on e46fcc0 and the right one on the merge base.TestStaleCopyRecordsTheAttemptsSubtitlecovers that copy for a teardown and an expiry; it fails on e46fcc0 and passes here. The handlers, API v2 and worker packages pass against a migrated database, andmake lint-changedis clean. The stale-copy case needs two servers that hold copies of one play, so it was not checked live.Evidence: https://evidence.siloserver.org/r/silo-server/issue-4614/
Risks
mainthe sweep always won.subtitlewithout movingsubtitle_at, so a play finalized on both versions in that window can still misorder.Checklist
Council review
Plan round: 1, on the unfixed head 4eb4d4a (no scores; plan reviews)
Adopted: Sol's point that treating every sweep subtitle as start-only would drop a live row synced after the recorded subtitle, so the sweep orders by sync time instead of a flag (Opus's smaller form pointed the same way). Kept: the sweep handling Opus proposed cutting, because the database test shows
mainmovesended_atto sweep time there. Left open as risks: wall-clock ordering, and a stop that reads its plan before another server's replan commits (both predate this change).Background review: Sol's S1 (a pre-column row lost its order when a further-reaching finalization moved
ended_atfirst) is fixed in aef736c, with a test. S2 (rolling deploy) and S3 (a stale copy re-syncing with a fresh time) are listed under Risks; Sol still rates S2 open after round 2, and guarding it would break the sweep case this PR fixes. S4 (a flat-counter stop after a teardown keeps the teardown'sended_at) is the existing end-time rule, unchanged here.Maintainer review: 2 rounds, last reviewed ee018ce
Fixed: a stale copy's teardown beating the real stop's subtitle (Sol, Gemini) and local-copy stops ignoring the committed plan (Gemini), in ee018ce; the admin API doc's missing subtitle rule, in fc4c91f; the attempt read's guards (Gemini), in a6dba23. Left open: a failed attempt read on a stale copy (Sol), a duplicate attempt read in the sweep and detached stop (Opus, Sol), and the rules for a play whose attempt is gone, which predate this change.
AI Disclosure
🤖 Generated with Claude Code
Note
Keep the latest subtitle in playback history regardless of finalization order
subtitle_attimestamp instead ofended_at, so out-of-order finalizations keep the latest subtitle. Adds a nullablesubtitle_atcolumn toadmin_playback_historyvia migration.PlaybackHandler.recordAdminEndresolves the subtitle from the matching native attempt's committed plan when no earlier subtitle timestamp is supplied; admin stops and lifecycle sweeps go through this shared path. The lifecycle sweep orders the subtitle from the session's last sync or start time (playback.go, playback_lifecycle_sweep.go).subtitle_at, falling back toended_atfor legacy rows.ended_at; a subtitle-only change updates the subtitle without moving the end time, and legacy rows getsubtitle_atbackfilled fromended_aton first upsert.Macroscope summarized 8ad8f27.