Repository navigation
fix(jellycompat): sync activity dashboard immediately on compat playback start/stop - #261
Conversation
…ack start/stop Compat (Infuse/Jellyfin) sessions were only reconciled into playback_sessions_sync on the periodic 15s reconciler tick, so stopped streams lingered in the admin activity dashboard and overlapped with newly started ones as ghost sessions. Native playback handlers already trigger an immediate SessionSyncer.SyncNow on start/stop; wire the same syncer into the jellycompat playback handler and flush after teardownPlaySession (Stopped report + ActiveEncodings teardown) and after a new upstream session starts. The stop-path sync detaches from request cancellation (context.WithoutCancel) because clients often drop the connection right after reporting a stop. Also adds the ListProgressSince method to the jellycompat test fake so the package's tests compile again after the downloads-v2 interface change. Part of #205 Co-Authored-By: Claude Opus 4.8 <[email protected]>
…sync Adversarial review follow-ups: SyncNow snapshots could commit out of order when request-path syncs raced the periodic tick (an older snapshot committing last would resurrect stopped sessions or drop fresh ones), and the detached stop-path sync had no deadline, letting a stalled DB pin request goroutines. Serialize snapshot capture + reconcile under one lock and cap request-path syncs at 5s so failures degrade to the periodic tick. Part of #205 Co-Authored-By: Claude Opus 4.8 <[email protected]>
…a lock Review iteration 2: a stop-triggered sync queued on a bare mutex could expire its 5s deadline waiting behind a slow tick and fail before removing the stopped row. Coalesce instead: one owner reconciles at a time, callers that arrive mid-flight return immediately after flagging a follow-up pass, and the owner re-captures a fresh (post-change) snapshot afterwards. Request goroutines never block behind another sync, snapshots still commit in capture order, and an expired-context owner leaves the queued pass for the next tick instead of burning it. Part of #205 Co-Authored-By: Claude Opus 4.8 <[email protected]>
📝 WalkthroughWalkthroughAdds a ChangesImmediate session sync
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant InfuseClient
participant PlaybackHandler
participant teardownPlaySession
participant SessionSyncer
participant Reconciler
InfuseClient->>PlaybackHandler: stop report / DELETE ActiveEncodings
PlaybackHandler->>teardownPlaySession: teardownPlaySession(ctx, session)
teardownPlaySession->>SessionSyncer: syncSessionsNow(detached ctx, timeout)
SessionSyncer->>Reconciler: SyncNow(ctx)
alt sync already running
Reconciler-->>SessionSyncer: mark pending, return immediately
Reconciler->>Reconciler: run follow-up syncOnce after current pass
else no sync in-flight
Reconciler->>Reconciler: syncOnce(ctx) captures snapshot and reconciles
end
Reconciler-->>SessionSyncer: complete or error logged
Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
internal/jellycompat/streams.go (1)
864-930: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick winStart-path sync is not detached from request cancellation, unlike the stop path.
teardownPlaySessionwrapsctxwithcontext.WithoutCancelbefore syncing (Line 753) specifically because "clients often drop the connection right after reporting a stop." The same client behavior applies to the start path: the manifest/PlaybackInfo request context can be canceled by the client shortly afterensureUpstreamPlaybackfinishes committing the new session toh.playbackStore(Lines 917-928), but beforesyncSessionsNowruns at Line 929. SincesyncSessionsNowwraps the passed context withcontext.WithTimeout(ctx, ...), a canceled parentctximmediately cancels the sync too — the freshly-started session is fully committed locally but the immediate dashboard sync silently fails (logged, not surfaced), reintroducing the exact "ghost/stale session" symptom this PR fixes for the stop path, just on session start instead.🐛 Proposed fix for consistency with the stop path
- h.syncSessionsNow(ctx, "compat_start") + // Detach from request cancellation for the same reason as the stop path: + // the client may disconnect immediately after the session is committed. + h.syncSessionsNow(context.WithoutCancel(ctx), "compat_start")🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@internal/jellycompat/streams.go` around lines 864 - 930, The start path in ensureUpstreamPlayback is still tied to the request context, so a client disconnect can cancel the follow-up sync after the session is already committed in playbackStore. Detach the sync from cancellation the same way teardownPlaySession does by using a cancellation-independent context when calling syncSessionsNow, and keep the change localized to ensureUpstreamPlayback/syncSessionsNow so the newly started session is always propagated consistently.
🧹 Nitpick comments (1)
internal/worker/reconciler.go (1)
446-489: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick winFollow-up coalesced pass reuses the original owner's (possibly short-lived) context.
The
forloop always callsr.syncOnce(ctx)using the initial caller's context (Line 485), even for follow-up passes requested by a different, later caller. When the sync "owner" happens to be a compat request-path trigger (syncSessionsNowbounds it to 5s, perinternal/jellycompat/streams.go), a follow-up pass requested near the end of that 5s window will be dropped viactx.Err() != nil(Line 478) and deferred to "the periodic tick at the latest," per the comment. This is a documented, intentional tradeoff, but it means the "immediate" sync guarantee this PR is meant to deliver can silently degrade to periodic-tick latency specifically when the owner is a short-lived compat sync rather than the 15s tick — the exact scenario (rapid stop/start) most likely to trigger coalescing in practice.Consider giving follow-up passes their own independent bounded context (e.g., a fixed internal timeout) instead of inheriting the owner's, so a short caller-supplied deadline doesn't truncate work requested by unrelated callers.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@internal/worker/reconciler.go` around lines 446 - 489, The follow-up coalesced reconciliation in Reconciler.SyncNow is reusing the original caller’s context, so later requested passes can be cut short by a short-lived owner deadline. Update the SyncNow loop to give follow-up syncOnce calls their own independent bounded internal timeout instead of always passing the initial ctx, while keeping the syncPending/syncRunning coalescing behavior intact. Use the Reconciler.SyncNow and syncOnce flow to locate the change, and preserve the existing “only one reconciliation runs at a time” semantics.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@internal/jellycompat/streams.go`:
- Around line 864-930: The start path in ensureUpstreamPlayback is still tied to
the request context, so a client disconnect can cancel the follow-up sync after
the session is already committed in playbackStore. Detach the sync from
cancellation the same way teardownPlaySession does by using a
cancellation-independent context when calling syncSessionsNow, and keep the
change localized to ensureUpstreamPlayback/syncSessionsNow so the newly started
session is always propagated consistently.
---
Nitpick comments:
In `@internal/worker/reconciler.go`:
- Around line 446-489: The follow-up coalesced reconciliation in
Reconciler.SyncNow is reusing the original caller’s context, so later requested
passes can be cut short by a short-lived owner deadline. Update the SyncNow loop
to give follow-up syncOnce calls their own independent bounded internal timeout
instead of always passing the initial ctx, while keeping the
syncPending/syncRunning coalescing behavior intact. Use the Reconciler.SyncNow
and syncOnce flow to locate the change, and preserve the existing “only one
reconciliation runs at a time” semantics.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 0e6ba26d-e923-4dbd-9d62-92f7b63913dc
📒 Files selected for processing (9)
cmd/silo/main.gointernal/jellycompat/content_direct_test.gointernal/jellycompat/handlers_playback.gointernal/jellycompat/router.gointernal/jellycompat/server.gointernal/jellycompat/streams.gointernal/jellycompat/streams_test.gointernal/worker/reconciler.gointernal/worker/reconciler_test.go
Resolves overlap with #261 (immediate activity-dashboard sync on compat start/stop): the Stopped-report teardown keeps this branch's route-ambiguity gate and adopts #261's context-taking teardownPlaySession; ensureUpstreamPlayback keeps the CAS attach and fires syncSessionsNow only on a successful attach (the CAS loser adopts a winner that already synced). Both branches' identical ListProgressSince test-fake fixes converged. Co-Authored-By: Claude Fable 5 <[email protected]>
…ack start/stop (Silo-Server#261) * fix(jellycompat): sync activity dashboard immediately on compat playback start/stop Compat (Infuse/Jellyfin) sessions were only reconciled into playback_sessions_sync on the periodic 15s reconciler tick, so stopped streams lingered in the admin activity dashboard and overlapped with newly started ones as ghost sessions. Native playback handlers already trigger an immediate SessionSyncer.SyncNow on start/stop; wire the same syncer into the jellycompat playback handler and flush after teardownPlaySession (Stopped report + ActiveEncodings teardown) and after a new upstream session starts. The stop-path sync detaches from request cancellation (context.WithoutCancel) because clients often drop the connection right after reporting a stop. Also adds the ListProgressSince method to the jellycompat test fake so the package's tests compile again after the downloads-v2 interface change. Part of Silo-Server#205 Co-Authored-By: Claude Opus 4.8 <[email protected]> * fix(worker): serialize SyncNow and bound compat request-path session sync Adversarial review follow-ups: SyncNow snapshots could commit out of order when request-path syncs raced the periodic tick (an older snapshot committing last would resurrect stopped sessions or drop fresh ones), and the detached stop-path sync had no deadline, letting a stalled DB pin request goroutines. Serialize snapshot capture + reconcile under one lock and cap request-path syncs at 5s so failures degrade to the periodic tick. Part of Silo-Server#205 Co-Authored-By: Claude Opus 4.8 <[email protected]> * fix(worker): coalesce immediate session syncs instead of queueing on a lock Review iteration 2: a stop-triggered sync queued on a bare mutex could expire its 5s deadline waiting behind a slow tick and fail before removing the stopped row. Coalesce instead: one owner reconciles at a time, callers that arrive mid-flight return immediately after flagging a follow-up pass, and the owner re-captures a fresh (post-change) snapshot afterwards. Request goroutines never block behind another sync, snapshots still commit in capture order, and an expired-context owner leaves the queued pass for the next tick instead of burning it. Part of Silo-Server#205 Co-Authored-By: Claude Opus 4.8 <[email protected]> --------- Co-authored-by: Claude Opus 4.8 <[email protected]>
Problem
Issue #205 reports two activity-dashboard accuracy bugs:
SessionManager, but the sharedplayback_sessions_synctable the dashboard reads is only reconciled on the 15-second reconciler tick. Native playback handlers trigger an immediateSessionSyncer.SyncNowon start/stop; the jellycompat handler never did. So a stopped Infuse stream stayed in the dashboard until the next tick, and starting a new item during that window showed two "simultaneous" playbacks (one being the ghost of the stopped session) — exactly the reported behavior.mainby [codex] Mirror ABS playback into live sessions #203 (merged 2026-06-26, one day after the issue's code-verification note), which mirrors ABS playback into native sessions with immediate syncs. Not re-fixed here.Reproduced (1) by code-path analysis:
teardownPlaySession(internal/jellycompat/streams.go) stops the in-memory session but nothing flushesplayback_sessions_sync, whose rows for a node are replaced only byReconcileron its 15 s ticker — while the native handlers (internal/api/handlers/playback.go) callsyncSessionsNowon every start/stop. Regression tests instreams_test.gofail without the fix.Approach
Extend the existing native-handler pattern to jellycompat rather than inventing a new mechanism:
PlaybackSessionSyncerdependency to the jellycompatPlaybackHandler(wired to the sameworker.Reconcilerthe native handlers use).teardownPlaySession(both the/Sessions/Playing/Stoppedreport andDELETE /Videos/ActiveEncodings) and after a new upstream session starts inensureUpstreamPlayback. Progress reports intentionally do not sync (the periodic tick covers position updates; syncing every ~10 s report per client would add DB churn for no dashboard-accuracy gain).context.WithoutCancel+ a 5 s deadline: clients often drop the connection right after reporting a stop, and a stalled DB must degrade to the periodic tick instead of pinning request goroutines.Reconciler.SyncNow(pre-existing exposure, made more visible by adding call sites): syncs are now coalesced — one owner reconciles at a time, callers arriving mid-flight return immediately after flagging a follow-up pass, and the owner re-captures a fresh snapshot afterwards. This guarantees snapshots commit in capture order (no resurrected stopped sessions / dropped fresh ones) and that request goroutines never queue behind a slow sync.Also adds the
ListProgressSincemethod to theprogressCountingStoretest fake ininternal/jellycompat/content_direct_test.go— the downloads-v2 interface change (#258) left the package's tests uncompilable, which blocked verifying this change. The same break exists ininternal/access/resolver_test.go; left out of scope (flagged separately).Verification
GOWORK=off go build ./...— clean (with stubbedweb/dist).GOWORK=off go test ./internal/jellycompat/— all pass exceptTestBeginWebOperationRecoversDeadProcessLock/TestBeginWebOperationRejectsLiveProcessLock, which are pre-existing environment-specific failures (process-lock pid probing, unrelated to this diff; the package didn't even compile onmainbecause of the feat(downloads): offline sync for mobile — downloads v2 #258 fake break).GOWORK=off go test ./internal/worker/ -race— pass, including newTestSyncNowSerializesSnapshotCaptureandTestSyncNowCoalescesPendingPass.golangci-lint(v2,--new-from-rev origin/main): 0 new issues (the one reported typecheck hit is the pre-existing feat(downloads): offline sync for mobile — downloads v2 #258 fake break ininternal/access, untouched here).make verify-local-paths— clean.Adversarial review
Codex adversarial review, 3 iterations, final verdict approve — no material findings:
SyncNowcalls could commit stale full-node snapshots out of order → fixed via serialization, then (iter 2, high) queueing on a bare mutex could let a stop-sync expire waiting behind a slow tick → fixed via the coalescing owner/pending design above, with race-enabled regression tests.context.WithoutCancelsync was unbounded → fixed with a 5 s deadline on request-path syncs.Risks & follow-up
internal/access/resolver_test.gostill stands (separate task flagged).Closes #205
AI-use disclosure
Implemented by Claude Code (issue-to-pr skill) with human oversight.
🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Bug Fixes