Repository navigation
feat(admin): record device, client, stream decisions and end reason in playback history - #3184
Conversation
…ack history Carry the declared registry device (X-Silo-Device-Id/-Platform; the MediaBrowser DeviceId on Jellyfin plays) on the playback session, its recovery card, the live sync row and the v2 admin session row. History records device, client, stream decisions (filled once) and end_reason (latest finalization wins), and the v2 history list returns the stored watch measurement, client_ip and these facts, accepts ended_before, and gains a capabilities document. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Carry device identity through sessions internal/playback/*, internal/api/handlers/playback_*, internal/apiv2/admin_sessions.go, internal/worker/reconciler.go, cmd/silo/session_sync.go, internal/jellycompat/*, docs/admin-api.md |
Playback sessions now carry normalized device ID and platform values. These values flow through recovery cards, synchronized snapshots, and admin session responses. |
Record playback facts and end reasons internal/api/handlers/playback*.go, internal/api/handlers/admin_playback_*.go, migrations/sql/20261027185055_playback_device_identity_and_end_reason.sql, internal/api/handlers/*test.go, scripts/ci/db-contracts.txt |
Stop handling now passes typed playback end reasons. History storage records device, client, stream-decision, and end-reason fields, fills missing metadata without replacing known values, and orders end-reason updates by finalization time. |
Query and expose admin playback history internal/apiv2/admin_playback_history.go, internal/apiv2/admin_playback_history_test.go, contracts/api/v2/openapi.json, contracts/api/v2/fixtures/*playback_history*, contracts/api/v2/fixtures/index.json, web/src/api/v2/*, internal/api/testdata/media_routes.txt, docs/admin-api.md |
The history API adds measurement and playback metadata, an exclusive ended_before bound, and a capabilities endpoint. API schemas, fixtures, route data, and documentation describe the new fields and behavior. |
API fixture request identifiers
| Layer / File(s) | Summary |
|---|---|
Refresh problem fixture identifiers contracts/api/v2/fixtures/*.json |
The instance request identifier changes in existing problem-response fixtures. |
Priority:
Estimated code review effort: 4 (Complex) | ~45 minutes
Change: Feature
Sequence Diagram(s)
sequenceDiagram
participant PlaybackFinalization
participant AdminPlaybackHistoryStore
participant PostgreSQL
participant AdminPlaybackHistoryAPI
participant AdminClient
PlaybackFinalization->>AdminPlaybackHistoryStore: Record playback facts and end reason
AdminPlaybackHistoryStore->>PostgreSQL: Upsert history and update missing metadata
AdminPlaybackHistoryAPI->>PostgreSQL: Query history using time bounds
PostgreSQL-->>AdminPlaybackHistoryAPI: Return history rows
AdminPlaybackHistoryAPI-->>AdminClient: Return history entries and capabilities
Possibly related issues
- [bug] v2 OpenAPI rejects null on nullable enum request fields #2980: The PR adds
nullto nullable playback-history enum schemas, but it does not address the request fields listed in the issue. - [bug] Admin activity shows encode targets for a Jellyfin remux after a server restart #3100: The PR preserves device ID during recovery and exposes stream decisions in admin history; the issue’s incorrect encode targets remain separate.
Possibly related PRs
- Silo-Server/silo-server#3108: Both changes affect admin playback history; the duration used by the earlier change affects values exposed here.
- Silo-Server/silo-server#2967: Both changes use the session-stored client address in admin playback history.
- Silo-Server/silo-server#2699: Both changes concern playback device identity and its declared-header source.
Suggested reviewers: tobechukwu-njoku, brady3035
Merge Risk: 
Minimal · up to f9a56
-
The reviewed changes are mergeable with normal checks; the investigated capability concerns were refuted.
Security architecture risk: 
Low · up to f9a56
-
The change retains more playback-identifying information behind existing administrator access controls. No new privilege escalation or unauthorized disclosure was established. Recovery, concurrent finalization, and deployment behavior retain limited uncertainty.
Retained concerns
No architecture-level concerns identified.Security review details
-
Security Blast Radius
- inferred — The expanded exposure is administrator-visible correlation of playback activity across the configured server's accounts and profiles. An authenticated playback client can supply misleading device/client labels for its own play, but the inspected projection does not turn those labels into account, session, or device authority.
Trust Boundaries and Controls
- observed — Both history operations require acting-administrator authorization through the central authentication, viewer/profile, and admin gates. Scoped API keys remain restricted by the route allowlist, which does not include these history routes. Unscoped keys retain their pre-existing behavior but still require administrator authority. Returned identity strings are serialized data in the inspected path.
Resilience and Maintainability Implications
- observed — Stop enforcement is separate from best-effort history recording: lifecycle-locked paths remove live authority and deny stream access before recording history. Realtime termination uses the same authority gate before queued finalization. History-construction or storage failures are logged rather than restoring playback authority, so this history is diagnostic state rather than a transactional security audit.
Hardening Proposals
- proposed — Monitoring integrations should treat device/client fields as unverified attribution labels and tolerate unknown values, rather than using them as device attestation or authorization evidence.
-
Pre-merge checks: 
4 · 
1
-
Failed checks: 1 warning Passed checks: 4 passed-
Full details: Title check
-
Explanation
The title names the main change: the admin playback history now records device, client, stream decisions, and end reason. It matches the changeset, which adds these fields to the migration, handlers, OpenAPI spec, and docs. The title uses a conventional commit prefix and fits in one sentence. It omits the new filter, capabilities route, and session device fields, but it does not need to cover every detail.
Full details: Description check
-
Explanation
The description covers the changeset in detail. It explains device identity fields on start requests, the admin session rows, the migration columns, the typed PlaybackEndReason change, the ended_before filter, the new capabilities route, the docs update, and the validation steps. It also names the related PR and the scope and merge-order notes. The description is directly related to the changes.
-
Full details: Docstring Coverage
-
Explanation
Docstring coverage is 56.25% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 32 functions across 31 files. (2 skipped: 2 unsupported.)
Resolution
Write docstrings for the functions missing them to satisfy the coverage threshold.
-
Finishing Touches: 💡 2
-
📝 Generate docstrings: 💡
-
- Commit to this branch
- Create a new PR
🛠️ Fix failing CI checks: 💡
-
- 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.
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:
|
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. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a37f892571
ℹ️ 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".
A finalization that gets no further leaves ended_at alone, so comparing a reason's end instant to ended_at let a delayed earlier expiry replace a later stop. Record the end instant of the finalization that set the reason in end_reason_at and order against it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
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:
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 42f05e8c5a
ℹ️ 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 change: the build-807 result for #1190 C2 does not cover the new Suggested fix: Automated check: Macroscope check run agent (gpt-6-luna). No validation was performed. Posted via Macroscope — v1 validation impact |
Major validation impactThe API-keys Server task #1190 C2 was recorded passed on build 807 · Suggested line: Automated check: Macroscope check run agent (gpt-6-luna). No validation was performed. Posted via Macroscope — v1 validation impact |
…vice on rebuild The nullable video_decision, audio_decision and end_reason schemas listed only strings in their enum, so the spec refused the null an unknown value takes; the committed fixture now carries one. A Jellyfin direct or remux session rebuilt from a fresh recovery card now takes the play's negotiated DeviceId, as it already took the client name. 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:
|
|
Keeping The allowlist gap is real, and it's a merge-order item: whichever of #3182 and this PR merges second adds |
|
The new playback-history list and capabilities routes add scope-gated API operations. The passed #1190 C2 result (build 807 · Please change the PR's
Suggested fix (no diff): update the PR-body line to the exact text above. 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:
5b474b2e-ecf3-4904-8757-073d93d15ee2
Files selected for processing: 82-
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.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_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/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; 0 remain after this review.
-
Problem
Related issue: N/A
Validation tasks: none
A monitoring tool (the first one is Tracearr) can't tell plays apart from Silo's admin data. A finished play in admin playback history doesn't say which device played it, which app, how the streams were delivered, or why the play ended. The live admin session row doesn't say which device is playing either. The history list also hides values it already stores (the watch measurement and the client address). It can only bound a window from below, so a tool paging history by time can't ask for "everything before T" without overlap.
This change records those facts and returns them on the admin history and session routes under
/api/v2. It is part of the monitoring API plan; lifecycle events for sessions come in a follow-up that stacks on this branch.Approach
Device identity. The device is the one the client declares for the profile device registry:
X-Silo-Device-IdandX-Silo-Device-PlatformonPOST /api/v2/playback/start(or the v1 bridge's start). It is not the playback device the v2X-Device-IDheader names. The platform is only what the client declares; the server never derives it from the user agent. A Jellyfin play records theDeviceIdthat its PlaybackInfo request already parsed, with no platform. An Audiobookshelf play records neither. The device rides onplayback.ClientInfointo the playback session, its server-side recovery card (so a restart rebuild keeps it), the live sync row, and the history row. A session rebuilt from a stream token loses it, as it already loses its client name; claims deliberately carry no client metadata.Admin sessions.
GET /api/v2/admin/sessionsrows gaindevice_idanddevice_platform, advertised bydevice_identityon the sessions capabilities. The frozen v1 row is unchanged.History. A migration adds
device_id,device_platform,client_name,client_version,video_decision,audio_decisionandend_reasontoadmin_playback_history, and the two device columns toplayback_sessions_sync.end_reasonfollows the latest finalization: an expired play that is rebuilt and then stopped ends upstopped. The row also stores the end instant of the finalization that set the reason (end_reason_at, not returned). A delayed earlier finalization can't replace a later reason, even when the later one got no further and so leftended_atalone.End reason. The stop and finalize functions now take a typed
PlaybackEndReasonin place of theuserInitiated/sessionEndedbooleans, and derive both from it. Behavior is the same.stopped: v1 and v2 client stops, and Jellyfin/Audiobookshelf stops throughFinishSession.terminated: admin terminate, the admin stop fallback, and a player-confirmed admin stop or terminate.expired: the liveness reaper.abortedis in the published enum, but abort paths write no history row today, so it doesn't appear yet. The lifecycle-events PR decides whether aborts and the v2 stop on a replica without the live session copy should write history, and completes those paths.History list.
GET /api/v2/admin/playback-historyentries gainmeasured,start_position_seconds,paused_seconds,measured_since,measured_until,client_ip, and the new columns, each null when unknown. A newended_beforefilter is exclusive, whileended_afterstays inclusive, so windows sharing a bound list each attempt once; the cursor binds it. A newGET /api/v2/admin/playback-history/capabilitiesnames the additions.docs/admin-api.mddocuments all of it.API keys: the one new route,
GET /api/v2/admin/playback-history/capabilities, follows the existing scope rule. Unscoped admin keys reach it like every other admin route, and a scoped key is refused unless a scope lists it. The list route already existed and keeps its scope behavior. The validated API-key permission matrix (#1190 C2) is unchanged on main, so the validation line staysnone. The monitor scope that would grant these routes is #3182, which already declareschanges #1190 C2. Whichever of the two merges second adds/admin/playback-history/capabilitiesto theadmin:monitor:readrows.Admin-only surfaces. Apple, Android and the web UI need no change. For jellycompat parity, the Jellyfin protocol has no admin history surface to extend, so no change is needed there. Jellyfin plays do now record their device in Silo's admin data.
Validation
X-Device-ID.stoppedfor a client stop,terminatedfor an admin terminate, andexpiredfor a play left to the reaper. Each row carried device, client, decisions, measurement and client address.ended_after=Tandended_before=Tsplit the log at play 2's exactended_atwith no overlap; with both set to T the list is empty.invalid_cursor, and an unparsableended_beforegot 422.admin:sessions:summary:read403permission_denied, no credentials 401, and a revoked key 401.TestAdminPlaybackHistoryFactsDB, listed inscripts/ci/db-contracts.txt, covers:ended_beforevalidation and cursor binding), the start client-identity test (v1 headers vs the v2 declared device), and the recipe card tests.make lint-changed(0 issues),make lint-router-recovery, everymake verify-*target andTestCommittedArtifactMatchesRouter, web lint, format, build and budget, andmake test-web(6768 tests) pass.make verify-actionlintdidn't run: actionlint 1.7.12 isn't installed on the machine I used, and this branch changes no workflows.make test-goon a freshly migrated database passed every package but two:internal/invitations:TestEmailedInvitationLinkReplacementDBsaw local password sign-in turned off. Another package's test toggles that server-wide setting while packages run in parallel against one database, and the test passes alone.internal/api/handlerstimed out inTestRelayToTranscodeNodeAcknowledgesOnlyFullDownstreamResponse. That test doesn't reach this change: it callsrelayToTranscodeNodeon a bare handler. Under load the relay returned an error, the stub node blocked sending a retried request into a one-slot channel, andnode.Close()then waited forever. It passes alone (three runs), and the rest of the package passed in the focused run.Evidence
Evidence: https://evidence.siloserver.org/r/silo-server/pr-3184/
No visible change: no web or client screen renders the new fields. The evidence page has the trimmed request and response pairs from the sandbox run and the test results.
Risks
RecordHistorynow sends two statements in one batch per finalization. The second is a no-opUPDATEonce the row has every fact.Checklist
AI Disclosure
end_reason_at). The nullable enums refused null in the OpenAPI spec, and a Jellyfin direct or remux session rebuilt from a new recovery card dropped its device (both fixed in f9a560e). The review found the stop-path refactor behavior-equivalent at every call site.🤖 Generated with Claude Code