Repository navigation
perf(playback): sync sessions on progress only when pause state flips - #1364
Conversation
Every v1 and v2 progress sample called SyncNow, which reconciles the whole node's live-session snapshot: one transaction of N+5 statements for N local sessions, then a sessions.replaced push to every admin socket and a playback-sessions invalidation on every replica. With the web and Android clients reporting progress every 10 seconds, the shared admin view was rewritten and its caches dropped once per heartbeat per stream. Position does not need that. The periodic reconcile tick already carries it, and jellycompat progress never triggered a sync. A progress sample now syncs only when it flips the pause state, so the admin view still shows pause and resume at once. Start, replan, stop and abort keep syncing from their own call sites. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Quick104 has reached the 50-credit limit for trial accounts. To continue receiving code reviews, upgrade your plan.
|
Warning Review limit reachedNext included review available in 1 minute. View limit detailsLimit details: You’ve used all 2 included reviews currently available. You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Review configuration: ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (3)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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. |
Problem
Related issue: N/A
Validation tasks: changes #1207 C1 (the admin Active sessions position now updates on the reconcile tick, not on each client heartbeat); reaches #1206 C1 and #1208 C1, where pause and resume still reach the admin view at once. None of these cases has a recorded result yet.
Each progress sample on
/api/v1and/api/v2called the session syncer (SyncNow) when the API server held the live session. A sync reconciles every live session on that node, not only the one that reported. It runs one transaction of N+5 statements for N sessions. The reconciler treats a position change as a change, so each sync also sendssessions.replacedto every connected admin client and publishesplayback_sessions_changed. That event drops the admin stats, activity, leaderboard and timeseries caches on every replica. The plugin event dispatcher also receives both events on every replica. For each one it queries the enabled plugin installations and their capabilities before forwarding the event to matching plugin event consumers.The web player and the Android client report progress every 10 seconds. A node with 20 streams therefore rewrites all 20 shared rows about twice a second and keeps the admin caches cold. Operators pay that cost in database load, and admins see their dashboards refetch continuously. Jellyfin-compatible progress reports already skip
SyncNow, so native clients paid a cost that compat clients did not.Approach
A progress sample now calls
SyncNowonly when it flips the pause state (wasPaused != IsPaused). Position-only samples still update the in-memory session, the user store and watch-provider scrobbles as before. The shared admin row picks up the new position on the next periodic reconcile tick (every 15 seconds), which already runs on every node.Start (
v3_start), replan (v3_replan), stop and abort sync from their own call sites and are unchanged. The new tests check that stop still syncs on both API versions.Alternatives considered:
Audiobookshelf-compatible progress (beta) also syncs on each update. This PR leaves it alone.
Maintainer PR #1078 edits the same two files, in the progress side-effect lock and the handler struct fields. This diff changes one line in
writeProgressSideEffectsV2and one inHandleUpdateProgress, and adds a small helper next tosyncSessionsNow. It does not touch the lock code.git merge-treeauto-merges these hunks with #1078 in both files. #1078 already conflicts withmaininfinalizeStopV2's stop-lease loop and ininternal/transcodenode/server.go; this PR does not change either conflict.Before and after
TestApplyProgressV2SyncsSessionsOnlyOnPauseFlip, counting syncerTestHandleUpdateProgressSyncsSessionsOnlyOnPauseFlip, counting syncerworker.Reconcileras the syncer (not committed)playback_sessions_changedpublishes per 100 position-only POSTsThe statement counts cover only the reconciler. The handler under test had no user store, and the per-sample user-store write is unchanged. For scale, as an estimate: 20 streams reporting every 10 seconds went from about 52 reconciler statements a second (two heartbeat syncs plus the tick) to one 25-statement sync per 15-second tick, about 1.7 a second.
Validation
All checks below ran on the branch rebased onto current
main.go build ./...,gofmt -l .(no output) andgo vet ./...: pass.make lint-changed: 0 issues.GOFLAGS=-p=6 make test-go(withoutSILO_TEST_DATABASE_URL): pass, 159 packages ok.SILO_TEST_DATABASE_URLset to a freshly migrated database,go test ./internal/api/handlers/ ./internal/worker/ ./internal/apiv2/:workerandapiv2pass.handlersfails onlyTestAdminSubtitleListPageDBandTestCatalogTransferPersistsJobsAndSignedLink, and both fail the same way on currentmain.make verify-settings-bindings-all verify-playback-fixtures verify-route-inventory verify-migration-ledger verify-scenario-catalogs verify-offline-routes verify-apiv2-openapi verify-apiv2-contract verify-apiv2-fixtures verify-local-paths: pass.go test -count=1 -run '^TestCommittedArtifactMatchesRouter$' ./internal/apiv2/: pass.mainwith 100 syncs where 0 are expected. Onmain, a copy of the tests that logs each step shows one sync each for the pause flip, the repeated paused sample, the resume and the stop, as in the Before column. The tests pass on this branch, including under-race -count=30.SyncNowon a realworker.Reconciler: 6 with 1 live session and 25 with 20, matching the pause-flip row.make test-web, the web build andmake migrate-validatedo not apply: the branch changes no files underweb/ormigrations/.Risks
GET /api/v1/profiles/household/sessionsand v2listHouseholdSessions) reads the same shared row. Itsposition_secondsnow also updates on the reconcile tick, and itsis_pausedstill updates at once. The first-party web household panel shows only Playing or Paused, so it looks the same. A third-party client that shows position from this endpoint will see it move every 15 seconds.playback_sessions_changedorsessions.replacednow receive them on the tick and on start, stop, replan and pause changes, not on every heartbeat. No first-party plugin or the plugin SDK consumes these events.last_sync_at, with a 45-second grace for playing sessions. The 15-second tick refreshes it, so dropping heartbeat syncs does not expire live rows.Checklist
AI Disclosure
mainand fix(playback): retain progress side effect lock identity #1078, and the validation tasks. It raised five documentation items and no code issues, and all five are fixed: the Risks section now covers the household-manager session list, which reads the same shared row; Problem and Risks now cover the plugin event dispatcher, which receives the same events; the fix(playback): retain progress side effect lock identity #1078 note now states only whatgit merge-treeshows; this review field replaces a placeholder; and the commit message now gives the 10-second client cadence instead of "every few seconds".🤖 Generated with Claude Code