Repository navigation
fix(playback): let only the end that wins a session's row record it - #3192
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
Walkthrough
Merge Risk:
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6c8649e402
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
Actionable comments posted: 3

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:
2fedc2d7-9a1a-42c4-a808-e4c1f7cd74c9
Files selected for processing: 12-
contracts/api/v2/breaking-approvals.jsondocs/playback-api.mdinternal/api/handlers/admin_playback_control.gointernal/api/handlers/admin_playback_terminate.gointernal/api/handlers/playback.gointernal/api/handlers/playback_admin_store.gointernal/api/handlers/playback_finish_history_test.gointernal/api/handlers/playback_realtime.gointernal/api/handlers/playback_service.gointernal/api/handlers/playback_service_test.gointernal/api/handlers/playback_test.gointernal/api/handlers/stream.go
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 1 remain after this review.
-
6c8649e to
e98f2ba
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e98f2ba653
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Major revalidation impactUnconfirmed admin stops (C2). The reports for #1206 (Server), #1208 (Web), Silo-Server/silo-apple#330 (iPhone/iPad), Silo-Server/silo-apple#331 (tvOS), Silo-Server/silo-android#340 (phone/tablet), and Silo-Server/silo-android#341 (Android TV) exercise stops the player did not confirm and check for orphaned playback state. This PR replaces that fallback/terminate cleanup path with claim-first finalization. The prior reports use the old end state machine, so these cases need re-validation after merge. Expiry recovery (Audiobooks C5). The reports for Silo-Server/silo-apple#339 (iPhone/iPad) and Silo-Server/silo-android#349 (phone/tablet) and #350 (Android TV) include reconnects after roughly three-minute or at least 70-second outages. Those exceed the 45-second active-session idle grace and reach The PR should explain why these previously reported cleanup and recovery paths are being reworked. The task issue Results tables remain Validation tasks line
Automated check: Macroscope check run agent (gpt-6-luna). No validation was performed. Posted via Macroscope — v1 validation impact |
There was a problem hiding this comment.
Actionable comments posted: 1

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:
65421eb9-a484-4084-8443-2db8bced1320
Files selected for processing: 7-
internal/api/handlers/playback.gointernal/api/handlers/playback_end_claim.gointernal/api/handlers/playback_finish_history_test.gointernal/api/handlers/playback_realtime.gointernal/api/handlers/playback_service.gointernal/api/handlers/playback_service_test.gointernal/api/handlers/stream.go
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.
-
21ba551 to
a8580fe
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b428c2ab16
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
b428c2a to
90c980b
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 90c980bd1c
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 37a2029a9f
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 67610da5f1
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
Actionable comments posted: 1

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:
055141d0-083f-4f18-9ae9-c27044754c51
Files selected for processing: 11-
docs/playback-api.mdinternal/api/handlers/playback.gointernal/api/handlers/playback_admin_store.gointernal/api/handlers/playback_end_claim.gointernal/api/handlers/playback_finish_history_test.gointernal/api/handlers/playback_realtime.gointernal/api/handlers/playback_service.gointernal/api/handlers/playback_service_test.gointernal/api/handlers/session_ws_pause_state_test.gointernal/api/handlers/stream.gointernal/api/router.go
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.
-
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2f61758d04
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d12916bc3a
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c65f57fc64
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
Actionable comments posted: 1

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:
9f4036cc-bc9b-4e58-9473-9c80b9fbb507
Files selected for processing: 6-
docs/playback-api.mdinternal/api/handlers/playback.gointernal/api/handlers/playback_end_claim.gointernal/api/handlers/playback_realtime.gointernal/api/handlers/playback_service.gointernal/api/handlers/playback_service_test.go
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.
-
54eaeee to
47d655c
Compare
f137d34 to
06a7c78
Compare
250f88e to
05c801f
Compare
Expiry, abort and administrator ends now stop the attempt row and claim its finalization before writing watch history, provider events or the admin log, the order a v2 stop already used. An end that loses tears down only its own copy. An administrator end on a replica without the live copy records the play from the attempt row, aborts get their own server-minted stop id, and a stale Jellyfin copy whose play another replica ended no longer records an expiry over that end. Co-Authored-By: Claude Opus 5.5 <[email protected]>
An end that takes over an earlier stop's unfinished receipt now finishes it as that stop, and an expiry or abort writes the final sample its attempt accepted. A terminate whose teardown fails stays reclaimable instead of finalized, a finalization claim whose reply was lost is resolved by reading the lease back, and an end recorded from the attempt row tells watch providers. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…der event Co-Authored-By: Claude Opus 5.5 <[email protected]>
…later copy finish an expiry A player-confirmed administrator stop told providers from both its finalizer and its caller. An earlier Jellyfin copy's expiry is no longer a definite end, so a newer copy can still record its further progress. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… realtime notice another stop sent A realtime confirmed stop no longer tells providers when another stop's finalizer already recorded the end and told them. An administrator end that finishes an abort whose replica died sends the abort's terminal pause. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…own finalization A competing finalizer that holds the lease and finishes while the realtime worker waits told providers itself, so the worker now notifies only when its own finalization recorded the end and left the event to it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… a taken-over abort for providers An expiry that finds the row stopped by an unfinished end now claims it and finishes it as that end once its lease lapses, instead of dropping its copy. An end that takes over an abort with the live copy sends a pause that ends the session, as the abort itself would. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…im it An expiry that saw the row stopped but cannot confirm its claim through the store now drops its copy instead of recording a second end. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…nistrator stop A finalized administrator receipt without a history row no longer gives the realtime worker the provider notice: the finalizer already sent it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…inishes another end The realtime worker no longer writes a terminated admin row over the end its finalizer recorded, and tells providers with the reason of the stop that won the attempt row, such as an abort's ending pause. Co-Authored-By: Claude Opus 5.5 <[email protected]>
06a7c78 to
84fb4ce
Compare
Silo Kody — review completeReview finished. Check the inline comments for findings and verify each suggestion against the code and tests. Reviewing changes in Silo
Review settingsReview OptionsThe following review options are enabled or disabled:
|
Problem
Related issue: N/A
Validation tasks: changes #1206 C2, #1208 C2, Silo-Server/silo-apple#330 C2, Silo-Server/silo-apple#331 C2, Silo-Server/silo-android#340 C2, Silo-Server/silo-android#341 C2, Silo-Server/silo-apple#339 C5, Silo-Server/silo-android#349 C5, Silo-Server/silo-android#350 C5
When two ends of one native playback session race (an expiry, an abort, an administrator's terminate, a client stop), more than one of them can write the play's watch history and admin history. Native watch history mints a new row per write, so the user can see the same play twice. A losing end can also record its reason over the winner's. Separately, an administrator terminate on an API server without the session's live copy revoked the session but recorded nothing in admin history.
This change makes the end that wins the session's attempt row the only one that writes those records, on every path. It also records the play when a terminate lands on a server without the copy.
Builds on #3191, which has merged.
Approach
docs/playback-api.mddescribes the claim. No API contract change. Admin and server internals only: no Apple, Android or web change, and no Jellyfin protocol change.Validation
200, historyterminatedat 300 s with client and device, and progress afterwards410. Before, no history row.200,terminatedat 240 s; a second terminate404, history unchanged.expiredat 120 s, receipt finalized, progress404, a later client stop replays and leaves history as is.404):abortedat 200 s, progress404.make lint-changed(0 issues),make lint-router-recovery, everymake verify-*target,TestCommittedArtifactMatchesRouter, web lint, format, build and budget, andmake test-webpass.make verify-actionlintdidn't run: actionlint 1.7.12 isn't installed on the machine used, and no workflow changed.make test-gopassed every package exceptinternal/database'sTestLogPartitionsMatchPartmanOnNonUTCServer, which fails on fix(playback): record admin history for every way a session ends #3191 too. It builds its own database from migrations up to 028 and fails for America/New_York while US daylight saving time ends inside its window. It doesn't reach this change.Evidence
Evidence: https://evidence.siloserver.org/r/silo-server/pr-3192/
No visible change. The evidence page has the sandbox steps and results, the build and the test results.
Risks
admin_playback_historyfor a Jellyfin copy when it expires: one indexed read per expiry.Checklist
AI Disclosure
🤖 Generated with Claude Code
Note
Fix playback session end so only the winning end records history
Adds a shared end-claim flow in playback_end_claim.go. Every session-ending path (client stop, expiry, abort, admin terminate, stream abort) now claims the attempt row and its finalization lease before writing history, so exactly one admin-history row, provider event, and watch-history entry are written for the winning stop.
endSessionAsAdminandFinishOtherEndtakeovers.PGPlaybackAdminStore.HistoryEndReasonto read a session's recorded end reason; used to keep a stale Jellyfin copy from overwriting a prior non-expiry end.listAdminPlaybackHistoryentry was removed from breaking-approvals.json.SessionEnded; aborted or expiring ends that lose the race no longer write their own history or provider event. Docs in playback-api.md describe the new ordering.Macroscope summarized 84fb4ce.