Repository navigation
feat(admin): announce playback session starts, pauses, resumes and ends - #3194
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:
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Lifecycle storage and progress sequencing migrations/sql/*, internal/playback/protocol_store_v3.go, internal/playback/planstore/postgres.go, internal/playback/planstore/progress_lifecycle_db_test.go |
A migration adds lifecycle state and history sequence storage. Accepted progress updates can record pause-state transitions and return their sequence and timestamp. |
Transition capture and event publication internal/playback/session.go, internal/api/handlers/playback*.go, internal/api/handlers/playback_lifecycle*.go, internal/audiobooks/abs/native_sessions.go, internal/jellycompat/*, internal/api/router.go, internal/apiv2/admin_playback_lifecycle.go |
Playback entry points report starts and pause changes. The handler records transitions and publishes sequenced admin events with session and history data when available. |
Inactive-session expiry and finalization internal/api/handlers/playback_lifecycle_sweep.go, internal/playback/session_activity.go, internal/playback/planstore/postgres.go |
A periodic sweep selects inactive sessions and processes native, Jellyfin, and Audiobookshelf expiry and end-recording paths. |
Admin session and history read models internal/api/handlers/admin_playback_history.go, internal/api/handlers/playback_admin_store.go, internal/api/handlers/playback_sessions.go, internal/apiv2/admin_playback*.go, internal/apiv2/admin_sessions.go, internal/apiv2/router.go |
Admin session and history reads include lifecycle sequence data. Session reads use lifecycle state and can include eligible native sessions absent from the live sync table. |
Contracts, documentation, and supporting validation contracts/api/v2/*, docs/admin-api.md, docs/architecture/playback-lifecycle.md, docs/realtime-api.md, web/src/api/v2/schema.ts, scripts/ci/db-contracts.txt, internal/api/handlers/*test.go, internal/worker/*test.go, cmd/silo/main.go |
API contracts and documentation describe lifecycle capabilities, events, sequence fields, and history behavior. Tests cover transitions, expiry selection, missing media files, and sync-row rendering. |
Priority:
Estimated code review effort: 4 (Complex) | ~60 minutes
Change: Feature
Sequence Diagram(s)
sequenceDiagram
participant SessionManager
participant PlaybackHandler
participant PlaybackAdminStore
participant EventsHub
SessionManager->>PlaybackHandler: Report start or pause change
PlaybackHandler->>PlaybackAdminStore: Record lifecycle transition
PlaybackAdminStore-->>PlaybackHandler: Return transition sequence and state
PlaybackHandler->>EventsHub: Publish sequenced admin session event
Possibly related PRs
- Silo-Server/silo-server#3191: Both changes record playback history when a session ends.
- Silo-Server/silo-server#3184: This change extends the playback-history contract with lifecycle sequencing and uses history data in stopped events.
- Silo-Server/silo-server#3192: Both changes depend on which operation wins the session-end race.
Suggested labels: javascript, impact: playback
Suggested reviewers: rhainland
Merge Risk: 
Minimal · previous review eaa54
-
The test now checks that expired-stop history has no file-derived duration when the media file is unavailable. No issue in this change needs resolution before merging.
Security architecture risk: 
Moderate · up to 1cfdc
-
Administrative access controls remain in place, and native progress updates have transactional ordering protections. However, automatic expiry can stop an active legacy session and revoke its playback access when server synchronization is delayed and recent media delivery is not visible. Deployment and recovery behavior also retain some uncertainty.
Retained concerns
- Medium · reliability · inferred: The new cross-server sweep can durably expire an active v1 bridge session using an activity clock that bridge progress does not refresh. Bridge starts create an attempt, so the sweep routes them through ExpireIdleAttempt, but bridge progress updates in-memory activity and changes the lifecycle timestamp only on pause-state transitions. If the holder's synchronization is stale for more than 45 seconds, the attempt and lifecycle clocks exceed their idle grace, and no recent delivery activity protects the session, another server can stop the attempt, deny its stream tokens, and finalize it despite continuing progress reports. Local-holder checks, fresh synchronization, and recent delivery observations protect normal operation; the concern is failure containment when synchronization stalls, not an established cross-user attack.
Security review details
-
Security Blast Radius
- inferred — Lifecycle recovery has cross-server authority over eligible sessions in the shared database, including stopping attempts and denying playback tokens. Its failure scope can span sessions belonging to multiple users on a stalled holder, rather than only the request that initiated a transition.
Trust Boundaries and Controls
- observed — Bridge progress checks both authenticated account and profile ownership before invoking lifecycle reporting. Jellyfin reporting checks the compatibility token on direct lookup and passes that token through fallback lookups before announcing pause state. The new callbacks remain downstream of those existing controls.
- observed — The existing event boundary admits the sessions channel only for administrative connections and rejects AdminOnly envelopes for non-admin claims. Acting-profile checks can demote an administrator account's connection, and remote-playback credentials do not receive the sessions channel.
Resilience and Maintainability Implications
- inferred — The bridge expiry concern is a control-plane failure-containment issue: missing synchronization can become a durable terminal decision and token revocation even while the owning server accepts progress. This differs from native progress, whose accepted samples refresh the attempt clock checked by expiry.
Hardening Proposals
- proposed — Give each frontend an authoritative activity signal that its progress reports refresh, and revalidate that signal together with ownership before committing expiry and denying tokens. This would reduce dependence on synchronization freshness for bridge sessions.
Pre-merge checks: 
4 · 
1
-
Failed checks: 1 warning Passed checks: 4 passed-
Full details: Title check
-
Explanation
The title names the main change: admin-only announcements of playback session starts, pauses, resumes and ends. The changeset adds the four session.* lifecycle events on the admin sessions channel, so the title matches the primary change. It is short and specific, and it uses a conventional feat(admin) prefix.
-
Full details: Docstring Coverage
-
Explanation
Docstring coverage is 76.19% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 21 functions across 27 files.
Resolution
Write docstrings for the functions missing them to satisfy the coverage threshold.
-
Finishing Touches: 💡 1
-
📝 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.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 75e509fe07
ℹ️ 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".
75e509f to
b702614
Compare
There was a problem hiding this comment.
Actionable comments posted: 5
Caution
Some comments are outside the diff and can’t be posted inline due to GitHub limitations.

Minor · Allocate the stop sequence after locking the lifecycle row. · openapi.json:174
contracts/api/v2/openapi.json:174
🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick winAllocate the stop sequence after locking the lifecycle row.
RecordEndallocatesEXCLUDED.seqbefore it detects the conflict. A concurrent pause can commit a higher sequence before this update runs. The stop event and history row then have a lower sequence, so a monitor can discard the stop and retain the session as live. PostgreSQL documents this allocation order. (postgresql.org)Call
nextvalin the conflict-update assignment instead of copyingEXCLUDED.seq.

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:
9e22ccd5-f37e-4956-8b25-94d4a3688d05
Files selected for processing: 36-
cmd/silo/main.gocontracts/api/v2/fixtures/get_admin_playback_history_capabilities_ok.jsoncontracts/api/v2/fixtures/index.jsoncontracts/api/v2/fixtures/list_admin_playback_history_ok.jsoncontracts/api/v2/openapi.jsondocs/admin-api.mddocs/architecture/playback-lifecycle.mddocs/realtime-api.mdinternal/api/handlers/admin_playback_history.gointernal/api/handlers/playback.gointernal/api/handlers/playback_admin_store.gointernal/api/handlers/playback_lifecycle.gointernal/api/handlers/playback_lifecycle_db_test.gointernal/api/handlers/playback_lifecycle_sweep.gointernal/api/handlers/playback_lifecycle_test.gointernal/api/handlers/playback_service.gointernal/api/handlers/playback_sessions.gointernal/api/handlers/playback_v3.gointernal/api/router.gointernal/apiv2/admin_playback_history.gointernal/apiv2/admin_playback_lifecycle.gointernal/apiv2/admin_sessions.gointernal/apiv2/router.gointernal/audiobooks/abs/native_sessions.gointernal/jellycompat/handlers_playback.gointernal/jellycompat/streams.gointernal/playback/planstore/postgres.gointernal/playback/planstore/progress_lifecycle_db_test.gointernal/playback/protocol_store_v3.gointernal/playback/session.gointernal/playback/session_activity.gointernal/worker/reconciler.gointernal/worker/session_sync_row_db_test.gomigrations/sql/20261027235549_add_playback_session_lifecycle.sqlscripts/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; 0 remain after this review.
-
21ba551 to
a8580fe
Compare
36c5047 to
6e8d9d0
Compare
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:
ae35ad0b-f66f-4346-b8a8-128227149c9e
Files selected for processing: 10-
docs/architecture/playback-lifecycle.mdinternal/api/handlers/playback.gointernal/api/handlers/playback_admin_store.gointernal/api/handlers/playback_finish_history_test.gointernal/api/handlers/playback_lifecycle.gointernal/api/handlers/playback_lifecycle_db_test.gointernal/api/handlers/playback_lifecycle_sweep.gointernal/api/handlers/playback_sessions.gomigrations/sql/20261027235549_add_playback_session_lifecycle.sqlscripts/ci/db-contracts.txt
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 outside-diff point in CodeRabbit's review of 75e509f (allocate the stop's sequence after locking the lifecycle row) was fixed in 556e909: the conflict update now calls nextval itself. TestPlaybackLifecycleOrderAndStartStateDB holds a pause on the row while the end waits and checks the end's number comes out higher; it fails on the old assignment. |
02e9aa6 to
13c6e52
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 13c6e521c7
ℹ️ 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".
| // An end goes through the session's lifecycle, which announces it; | ||
| // a teardown the client can recover from records its stretch only. | ||
| if reason != "" && h.recordEnd(ctx, session, *entry) { |
There was a problem hiding this comment.
Finalize announced Jellyfin sessions even without progress
When a Jellyfin session starts at position zero and stops or switches playback method before reporting positive progress, recordStopHistory returns early through compatCopyWithoutProgress, so this lifecycle finalization never runs. The session has already emitted session.started, but its lifecycle remains playing until the sweep eventually emits a stop with end_reason: expired, losing the actual stopped or replaced reason. Keep the existing protection against stale copies writing watch history, but ensure an authoritative end still finalizes an announced lifecycle.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Keeping the guard; documented the trade-off in 9088942. A Jellyfin copy without progress cannot tell whether it is the play's only copy: with several API servers it is often the one that only served media while another server's copy took the reports. If its end recorded history and stopped the lifecycle, the copy with the real progress would later be dropped as ended elsewhere and the play's history lost. Ending through the sweep as expired is late and has the wrong reason, but loses nothing. I tried the change; TestFinishedSessionWithoutPositionRecordsNothing and the stale-copy tests fail on exactly this. The architecture doc now says a Jellyfin play that ends before reporting progress is ended by the sweep.
b428c2a to
90c980b
Compare
9088942 to
e4ee6e9
Compare
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:
ecd48a38-28dd-46f6-b37e-82f6cec1f249
Files selected for processing: 8-
docs/architecture/playback-lifecycle.mddocs/realtime-api.mdinternal/api/handlers/playback.gointernal/api/handlers/playback_admin_store.gointernal/api/handlers/playback_finish_history_test.gointernal/api/handlers/playback_lifecycle.gointernal/api/router.gointernal/apiv2/admin_playback_lifecycle.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.
-
49bfd8c to
1cfdc53
Compare
The admin sessions channel now carries session.started, session.paused, session.resumed and session.stopped. A lifecycle row per session holds its announced state and the number of its last transition, from one sequence the database advances with each transition, so events order correctly across API servers. Native pauses commit with the accepted progress sample; an end and its admin history row commit together, and only the first end is announced, with the history entry as stored. A sweep on every API server ends sessions no server holds through the same durable claims the reaper uses. The native session and history lists carry lifecycle_seq, and the sessions capabilities report lifecycle_events. Co-Authored-By: Claude Opus 5.5 <[email protected]>
An end takes its number under the row lock, so it stays above a pause it waited for. A start begins at the attempt's accepted pause state. The sweep selects only sessions it can end now, so active ones never fill its batch, and revokes tokens only after its claim succeeds. A play whose file left the catalog is still recorded, and a one-session read filters before rendering. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…omise Co-Authored-By: Claude Opus 5.5 <[email protected]>
…inline Co-Authored-By: Claude Opus 5.5 <[email protected]>
A lookup that failed for another reason returns the error, so a retry can record the full row. The docs now say a sweep backlog over 100 sessions drains over several sweeps. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…andler Co-Authored-By: Claude Opus 5.5 <[email protected]>
f8d8785 to
53434bd
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:
|
A Jellyfin play the expiry claim refuses records that it reported after the cutoff, so live plays no longer fill every sweep batch. Node delivery is read once per sweep, and an end recorded from facts takes the attempt's last accepted position, including a seek back. 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 #1205–#1208 and #1246 C1, which have no recorded results yet)
A monitoring tool watching Silo (the first one is Tracearr) can't tell when a playback session starts, pauses, resumes or ends. The admin
sessionschannel only says "something changed" (sessions.replaced) and sends the frozen v1 row list, capped at 200 rows. The tool has to diff whole lists to infer transitions, and it misses any session that ends between two reads.This change announces those transitions as events on the admin
sessionschannel, with the numbers and history a monitor needs to stay correct across API servers, missed events and server restarts.Builds on #3191 and #3192, which have merged.
Approach
session.started,session.paused,session.resumedandsession.stoppedon the admin-onlysessionschannel.session_id,seq,atandstate.GET /api/v2/admin/sessionsreturns it.end_reasonand the history entry the end recorded, as stored.sessions.replacedis unchanged.GET /api/v2/admin/sessions/capabilitiesreportslifecycle_events.playback_session_lifecyclerow per session holds its announced state. Every transition takes the next number of one global sequence in the statement that makes it, so a session's numbers rise in the order the database accepted its transitions, whichever server publishes them.lifecycle_seq, and only it is announced. With fix(playback): let only the end that wins a session's row record it #3192 and fix(playback): record admin history for every way a session ends #3191, every way a session ends goes through it.lifecycle_seq. A row'sis_pausedcomes from the same transition, so a row and an event with the same number agree. Ended sessions are left out of the list. A native session whose media a node keeps serving after its API server restarted is now listed from the row recorded at its start. History entries carrylifecycle_seq. The frozen v1 snapshot is unchanged.sessionis the in-memory session rendered exactly as a sync stores its row (worker.SessionSyncRowJSON, which shares its column list with the sync upsert) and read through the list's own query. A DB test pins that the rendered and synced rows match.realtime-api.mdsection covers the event contract and how a monitor reconciles.admin-api.mdcovers the new fields; with this change, the first end sets a history row's reason.docs/architecture/playback-lifecycle.mdcovers the invariants and the guarantee./api/v2. Admin-only, so Apple, Android and the web UI need no change. For jellycompat parity: Jellyfin clients don't consume admin session events; Jellyfin plays are announced through their upstream sessions.Validation
lifecycle_seqandis_pausedmatched the resume.end_reason: stoppedand the history entry. The history list returned the samelifecycle_seq.sessionsrejected (forbidden) and received no lifecycle events.expiredat 500 s with client and device, and progress afterwards404.scripts/ci/db-contracts.txt, cover:A unit test covers that events are admin-only, with their ids and stop history.
make lint-changed(0 issues),make lint-router-recovery,make test-go, everymake verify-*target andTestCommittedArtifactMatchesRouter, web lint, format, build and budget pass.make test-webfailed one test under load:pgs.test.ts"drops objects past 16 MiB" timed out. It passes alone, and this change touches no web code except the generated API types.make verify-actionlintdidn't run: actionlint 1.7.12 isn't installed on the machine used, and no workflow changed.Evidence
Evidence: https://evidence.siloserver.org/r/silo-server/pr-3194/
No visible change: the web admin still refreshes on
sessions.replacedand ignores the new events. The evidence page has the event transcripts, the build and the test results.Risks
Checklist
AI Disclosure
🤖 Generated with Claude Code
Note
Add playback session lifecycle tracking with admin start/pause/resume/end events
playback_session_lifecycletable storing per-session state, a global sequence number, and start facts; admin playback history rows gain a nullablelifecycle_seq(migration)sessionschannel: starts are announced by the native, Jellyfin, and Audiobookshelf frontends; pauses and resumes are recorded when accepted progress commits its lifecycle state alongside the attempt update (playback.go, playback_service.go, postgres.go)ApplyProgresswraps sample acceptance in a transaction and applies pause-state updates to lifecycle rows;LiveSessionfalls back to lifecycle start facts when no sync row exists; capability responses gainlifecycle_seqandlifecycle_eventsfieldsMacroscope summarized 3439956.