Repository navigation
fix(playback): record admin history for every way a session ends - #3191
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
Security findingsAdvisory findings (1)ℹ️ 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. |
|
Warning Review limit reachedEnable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
Reviews can continue after your included limit without a manual trigger. An admin must approve usage-based billing. Next included review available in 17 seconds. View limit details
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Detached history and session data internal/playback/session.go, internal/api/handlers/playback.go, internal/api/handlers/playback_admin_store.go, internal/playback/protocol_store_v3.go, internal/playback/planstore/postgres.go, internal/api/handlers/playback_finish_history_test.go |
Finish hooks accept detached snapshots and carry end reasons in context. The history handler fills missing snapshot facts from a shared live row. Attempt records retain their creation time, and the admin store exposes synced session data. Tests cover detached history and snapshot fields. |
Stop and abort finalization internal/api/handlers/playback_service.go, internal/api/handlers/playback_realtime.go, internal/api/handlers/stream.go, internal/api/handlers/playback.go, internal/api/handlers/playback_service_test.go, docs/playback-api.md |
Stop IDs reserved for server endings are rejected from clients. Finalization maps the winning stop ID to an end reason and records history when no live session is available. Aborts record admin history but not watch history. Tests and documentation cover these behaviors. |
Detached finish callers internal/jellycompat/..., internal/audiobooks/..., internal/jellycompat/routing_policy_test.go |
Jellyfin-compatible playback submits detached snapshots when a session is replaced or its local copy is missing. Audiobookshelf close handling can submit a detached snapshot when the native session copy is missing. Tests cover replaced-session snapshots and retrieval of the media-file ID. |
Admin history API contract internal/apiv2/admin_playback_history.go, contracts/api/v2/*, web/src/api/v2/schema.ts, docs/admin-api.md, scripts/ci/db-contracts.txt |
The admin history contract and fixtures include replaced. The approval record, fixture validator, documentation, generated client schema, and database-contract registry are updated. |
Priority:
Estimated code review effort: 4 (Complex) | ~45 minutes
Change: Bug fix
Sequence Diagram(s)
sequenceDiagram
participant ensureUpstreamPlayback
participant SessionManager
participant handleFinishedSession
participant PGPlaybackAdminStore
ensureUpstreamPlayback->>SessionManager: FinishDetached with replaced reason and session snapshot
SessionManager->>handleFinishedSession: Invoke finish hook with detached context
handleFinishedSession->>PGPlaybackAdminStore: Read shared live-session facts
Possibly related PRs
- Silo-Server/silo-server#3184: Adds the admin playback-history model and session metadata extended by this change.
- Silo-Server/silo-server#3192: Coordinates competing stop and end paths that this change updates.
- Silo-Server/silo-server#2965: Changes the Audiobookshelf close flow extended here to support detached finishing.
Suggested labels: impact: playback
Suggested reviewers: rhainland, brady3035
Merge Risk: 
Low · previous review 190a0
-
The change is mergeable with a documentation follow-up: qualify the history-row guarantee so it matches the zero-progress Jellyfin behavior.
Security architecture risk: 
Low · up to 190a0
-
The change affects playback history across replicas and restarts. Ownership checks remain in the inspected stop paths, and no new cross-account access was established. Residual risk centers on best-effort history recording and concurrent finalization rather than expanded privileges.
Retained concerns
No architecture-level concerns identified.Security review details
-
Security Blast Radius
- observed — The new persistent effects concern session-keyed playback history, including account/profile attribution and client, device, and IP metadata recovered from shared live rows. Ordinary detached stops can also enter the existing watch-history persistence path.
Trust Boundaries and Controls
- observed — The v2 stop path validates the authenticated caller and installation, then requires the attempt’s user and profile to match before mutation. Its detached snapshot derives identity from that owned attempt; live-row enrichment rejects another user’s facts.
- observed — Audiobookshelf closes check the stored session’s user/profile principal before closing and constructing a detached snapshot. Jellyfin reports resolve finalizable plays under the authenticated token, and ID-less stop reports do not tear down a play through route-only matching.
Resilience and Maintainability Implications
- inferred — Admin playback history should not be treated as an immutable terminal-event ledger. Repeated detached calls can rerun hooks, and the pre-existing latest-finalization rule can replace a previously recorded reason. The new paths reuse this behavior rather than introducing authoritative terminal ownership.
Hardening Proposals
- proposed — If automated reconciliation requires guaranteed terminal history, consider a durable session-scoped history intent with retryable completion, separate from transport teardown. This would strengthen the existing best-effort design rather than remediate a verified access-control vulnerability.
-
Pre-merge checks: 
4
Finishing Touches: 💡 1
-
🛠️ Fix failing CI checks: 💡
-
- Commit to this branch
- Create a new PR
📝 Generate docstrings
-
- Commit to this branch
- Create a new PR
🧪 Generate unit tests (beta)
-
- Commit to this branch
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Comment @coderabbitai help to get the list of available commands.
|
The admin user's Watch history/Playback History now includes plays that were previously omitted (aborted, replaced, or stopped on a server without the live copy). The linked evidence should show before-and-after captures of the same history screen with these added rows at desktop and phone widths; the description documents sandbox/API checks but does not identify captures of the history UI. Suggested fix: add those captures to the linked evidence page and update the Evidence section to identify the visible change. Automated check: Macroscope check run agent (gpt-6-luna). Evidence was not reviewed for correctness. Posted via Macroscope — Visible change evidence |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1cc67f37d9
ℹ️ 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: 2

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:
57ebc99b-494b-403b-bda9-70e439cc9495
Files selected for processing: 21-
contracts/api/v2/breaking-approvals.jsoncontracts/api/v2/fixtures/get_admin_playback_history_capabilities_ok.jsoncontracts/api/v2/fixtures/index.jsoncontracts/api/v2/openapi.jsondocs/admin-api.mdinternal/api/handlers/playback.gointernal/api/handlers/playback_admin_store.gointernal/api/handlers/playback_finish_history_test.gointernal/api/handlers/playback_service.gointernal/api/handlers/playback_service_test.gointernal/api/handlers/stream.gointernal/apiv2/admin_playback_history.gointernal/audiobooks/abs/native_sessions.gointernal/audiobooks/abs/progress.gointernal/jellycompat/handlers_playback.gointernal/jellycompat/streams.gointernal/playback/planstore/postgres.gointernal/playback/protocol_store_v3.gointernal/playback/session.goscripts/ci/db-contracts.txtweb/src/api/v2/schema.ts
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 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.
🛡️ Codex Security Review · Automatically triggered
Here are some automated security review suggestions for this pull request.
Reviewed commit: 34ca26f432
ℹ️ About Codex security reviews in GitHub
This is an experimental Codex feature. Security reviews are triggered when:
- You comment "@codex security review"
- A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review
Once complete, Codex will leave suggestions, or a comment if no findings are found.
0e933a2 to
190a00e
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:
|
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:
87c4f525-b3cb-42ff-bebe-f75bd1a27731
Files selected for processing: 85-
cmd/silo/session_sync.gocontracts/api/v2/fixtures/admin_account_delete_break_glass_required.jsoncontracts/api/v2/fixtures/admin_download_revoke_mixed.jsoncontracts/api/v2/fixtures/admin_download_storage_delete_invalid_id.jsoncontracts/api/v2/fixtures/admin_login_session_forbidden.jsoncontracts/api/v2/fixtures/admin_network_access_status_not_found.jsoncontracts/api/v2/fixtures/admin_network_access_unknown_host.jsoncontracts/api/v2/fixtures/admin_subtitle_metadata_precondition_required.jsoncontracts/api/v2/fixtures/approve_device_login_api_key_forbidden.jsoncontracts/api/v2/fixtures/cancel_admin_download_preparations_invalid_id.jsoncontracts/api/v2/fixtures/cancel_device_login_not_found.jsoncontracts/api/v2/fixtures/clear_resume_position_not_found.jsoncontracts/api/v2/fixtures/clear_resume_position_not_leaf.jsoncontracts/api/v2/fixtures/collection_order_foreign_id.jsoncontracts/api/v2/fixtures/complete_account_identity_link_invalid_grant.jsoncontracts/api/v2/fixtures/complete_oauth_login_invalid_grant.jsoncontracts/api/v2/fixtures/create_account_identity_link_ticket_wrong_password.jsoncontracts/api/v2/fixtures/create_admin_user_identity_linked_elsewhere.jsoncontracts/api/v2/fixtures/delete_account_identity_last_sign_in_method.jsoncontracts/api/v2/fixtures/get_admin_playback_history_capabilities_ok.jsoncontracts/api/v2/fixtures/get_favorite_membership_not_found.jsoncontracts/api/v2/fixtures/get_home_layout_include_items_out_of_range.jsoncontracts/api/v2/fixtures/get_not_interested_not_found.jsoncontracts/api/v2/fixtures/get_ratings_capability_authentication_required.jsoncontracts/api/v2/fixtures/get_watch_trickplay_not_found.jsoncontracts/api/v2/fixtures/ignore_unmatched_item_not_found.jsoncontracts/api/v2/fixtures/index.jsoncontracts/api/v2/fixtures/link_account_identity_with_credentials_directory_refused.jsoncontracts/api/v2/fixtures/list_admin_playback_history_ok.jsoncontracts/api/v2/fixtures/list_series_seasons_invalid_artwork.jsoncontracts/api/v2/fixtures/login_account_required.jsoncontracts/api/v2/fixtures/login_provider_null.jsoncontracts/api/v2/fixtures/mark_not_interested_episode_rejected.jsoncontracts/api/v2/fixtures/mark_not_interested_not_found.jsoncontracts/api/v2/fixtures/notification_mute_notification_series_not_found.jsoncontracts/api/v2/fixtures/playback_installation_changed.jsoncontracts/api/v2/fixtures/playback_invalid_protocol.jsoncontracts/api/v2/fixtures/playback_progress_conflict.jsoncontracts/api/v2/fixtures/refresh_session_provider_unavailable.jsoncontracts/api/v2/fixtures/regenerate_admin_item_trickplay_disabled.jsoncontracts/api/v2/fixtures/sign_in_with_network_identity_off_overlay.jsoncontracts/api/v2/fixtures/start_account_identity_link_unknown_ticket.jsoncontracts/api/v2/fixtures/start_device_login_temporary_null.jsoncontracts/api/v2/fixtures/theme_songs_playback_not_acceptable.jsoncontracts/api/v2/fixtures/theme_songs_playback_unauthorized.jsoncontracts/api/v2/fixtures/token_refresh_required.jsoncontracts/api/v2/fixtures/unmark_not_interested_locked_profile.jsoncontracts/api/v2/openapi.jsondocs/admin-api.mddocs/playback-api.mdinternal/api/handlers/admin_playback_control.gointernal/api/handlers/admin_playback_history.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_session_recipe.gointernal/api/handlers/playback_session_recipe_test.gointernal/api/handlers/playback_sessions.gointernal/api/handlers/playback_sessions_test.gointernal/api/handlers/playback_test.gointernal/api/handlers/playback_transcode_rehome_test.gointernal/api/handlers/playback_v3.gointernal/api/handlers/playback_v3_node_recipe_test.gointernal/api/handlers/playback_v3_test.gointernal/api/handlers/session_ws.gointernal/api/testdata/media_routes.txtinternal/apiv2/admin_playback_history.gointernal/apiv2/admin_playback_history_test.gointernal/apiv2/admin_sessions.gointernal/jellycompat/handlers_playback.gointernal/jellycompat/playback_client_name_test.gointernal/jellycompat/streams.gointernal/playback/recipecard.gointernal/playback/recipecard_test.gointernal/playback/session.gointernal/playback/transcode_manager.gointernal/worker/reconciler.gomigrations/sql/20261027185055_playback_device_identity_and_end_reason.sqlscripts/ci/db-contracts.txtweb/src/api/v2/operations.tsweb/src/api/v2/schema.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 2 remain after this review.
-
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:
|
1 similar comment
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:
|
Aborts, Jellyfin method switches, and stops, closes or teardowns that reach a replica without the session's live copy now each write one admin history row with their end reason. A detached end takes its start, client and device from the shared live row when one is left. Adds the "replaced" end reason. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
A stop or method switch that finds no local copy now records the play from its identity, completed from the shared live row, and only a position nobody reported is taken from it. An Audiobookshelf close reads the session's file, and aborts get their own stop id, so a replayed abort stays an abort that writes the admin log only. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
The server's stop ids are derived from the session id and say who ended the attempt; a client could send one and record its own play as terminated, expired or aborted. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
An abort for a missing file, or any end after its library was deleted, now records its admin history row without the item and duration only the file gave. Other lookup failures still return the error. Co-Authored-By: Claude Opus 5.5 <[email protected]>
250f88e to
05c801f
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:
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 05c801f66e
ℹ️ 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".
… abort no copy saw A Jellyfin method switch that stopped the old upstream copy now records its end even when the replacement fails to start, so that play is not lost. An abort of a Jellyfin copy that never reported progress records no row, as for every other end. Co-Authored-By: Claude Opus 5.5 <[email protected]>
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: none (the change reaches #1206 C2 and #1246 C1, which have no recorded results yet)
Some ways a playback session ends leave no row in admin playback history, so the play never appears there:
A monitoring tool that reconciles a missed stop against admin history (the plan behind #3184) can't find these plays at all. This change makes each of these ends write one history row with its end reason, and adds a
replacedend reason for the method switch.Builds on #3184, which has merged.
Approach
SessionManager.FinishDetachedruns the finish hooks for a session snapshot this server no longer holds, with the end reason carried in the context. The playback handler's existing finish hook writes the history. Watch history follows the same rules as today. An aborted or replaced play goes to the admin log only: aborts never wrote watch history, and a replaced play continues under the session that replaced it.playback_sessions_sync) when one is left. For a v2 stop it falls back to the attempt row's creation time, whichAttemptRecordV3.CreatedAtnow exposes.aborted.replacedonce the attach CAS has moved the play off it, whether this request or a concurrent one won.FinishSessionfinds no local copy finishes the stop's own snapshot.stopped. Aborts get their own server-minted stop id (they shared expiry's), so a replayed abort staysabortedand writes no watch history.docs/admin-api.mdnow says so.400. They are derived from the visible session id, so a client could otherwise record its own play as terminated, expired or aborted. Clients mint random ids, so none is affected.replacedjoins theend_reasonenum onGET /api/v2/admin/playback-historyand the history capabilities'end_reason_values, anddocs/admin-api.mddescribes it.contracts/api/v2/breaking-approvals.jsonapproves the added enum value pre-lock: the field is new in feat(admin): record device, client, stream decisions and end reason in playback history #3184 and no client reads it yet.Known limit, fixed by the next PR in this stack: a stale Jellyfin copy on another server can still expire later and relabel a stopped play as
expired, becauseend_reasonfollows the latest finalization.Validation
stopped, 480 s, client and device from the live row.404, rowabortedat 200 s.replacedrow at 600 s; the new sessions have none while playing.stopped, 960 s.TestLiveSessionReadsTheSyncedRowDB, is listed inscripts/ci/db-contracts.txt.make lint-changed(0 issues),make lint-router-recovery, everymake verify-*target andTestCommittedArtifactMatchesRouter, web lint, format, build and budget, andmake test-webpass.make verify-apiv2-contractpasses with the approval entry for the addedreplacedenum value.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:TestLogPartitionsMatchPartmanOnNonUTCServerfails for America/New_York. It builds its own database from migrations up to 028 and doesn't reach this change. US daylight saving time ends on November 1, inside the test's eight-day window, so it fails on any branch this week.Evidence
Evidence: https://evidence.siloserver.org/r/silo-server/pr-3191/
No visible change: no screen shows end reasons. The evidence page has the sandbox steps and results, the build and the test results.
Risks
playback_sessions_syncper detached end.Checklist
AI Disclosure
🤖 Generated with Claude Code
Note
Record admin history for every playback session end reason, including
replacedreplacedend reason for Jellyfin method switches and records aborted, replaced, and detached-stopped sessions in the admin history log, without writing watch history for aborts and replacementsSessionManager.FinishDetachedso finish hooks run for snapshots not held on the local replica; detached snapshots are enriched from a shared live session row viaPGPlaybackAdminStore.LiveSessionfinalizeStopV2andendReasonForStop;StopPlaybackV2now rejects client stops that reuse a server stop ID with HTTP 400PlaybackHandler.buildAdminHistoryEntry; entries are recorded without file detailsreplacedenum valueend_reasonenum in AdminPlaybackHistoryEntry gainsreplaced; client stop requests with server stop IDs now return HTTP 400 in playback_service.goMacroscope summarized 2e4806a.