You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(playback): free the stream slot of a player closed while paused - #4147
Related issue: N/A
Validation tasks: changes #1196 C1 (stream limits still enforced; a paused session that has gone quiet stops counting toward max streams after 2 minutes instead of 30)
Other clients: Apple N/A, Android N/A, Roku N/A (each already reports progress every 10 seconds while paused, which is what the new server rule relies on; nothing to change)
When someone pauses a movie in the web app and then closes the tab, reloads, or quits the browser, the stream keeps counting against the account's stream limit for 30 minutes. On an account limited to one or two streams, the rest of the household gets "Streaming limit reached" until it expires. Admins see the closed stream as a live paused session.
Two things combine. The web player only sends its stop when the player is closed inside the app; a page unload never runs that path. The server then keeps a paused session for the 30-minute paused grace, which exists so a player that comes back after a long pause can still resume (#243), and the session counts toward the limits for that whole time.
This change makes the web player send its stop when the page goes away, and stops a paused session that has gone quiet from holding a stream slot after 2 minutes, while still keeping the session for 30 minutes.
Approach
Web player: on pagehide it sends the session stop with keepalive, sharing the code path of the existing unmount stop. Unlike the unmount stop, it doesn't wait for a progress report still in flight, because the page may be gone before that report settles. The stop carries the newest sequence, so the server refuses the older report if it lands later. A page that enters the back-forward cache keeps its session, since it can come back playing.
Server: every native client (web, Apple, Android, Roku) reports progress every 10 seconds while paused, so a paused session with no activity for 2 minutes has lost its player (a crashed browser, a killed app, a sleeping laptop). The stream count now ignores such a session. Two minutes rather than 45 seconds, because browsers throttle a hidden tab's timers to about once a minute. Session cleanup still uses the 30-minute paused grace, so a returning player resumes as before. The transcode count is unchanged: the encoder stays allocated until cleanup, so its slot does too.
Jellyfin-compatibility sessions keep their existing expiry rules.
Protocol doc §2.5 describes the new slot rule.
Validation
Go: the new session-manager test covers a paused session that still reports (keeps its slot, including at once a minute), one quiet for 2 minutes (slot freed, session kept, transcode slot kept); it fails on the base commit.
Web: the new hook test covers a real unload (one keepalive stop) and a back-forward-cache hide (no stop); it fails without the pagehide listener. A session-mutations test covers an unload stop sent while a progress report is still in flight; it fails on eb92010, before that path stopped waiting for progress.
End to end in desktop Chrome against a local server, account limited to 1 stream: closing a paused tab freed the slot at once on this branch and left it held on the base commit; after killing the browser on a paused movie, a new stream was refused at 60 seconds and admitted at 135 seconds on this branch, and still refused at 135 seconds on the base commit. The killed sessions stayed listed as paused.
Pre-PR gate from CONTRIBUTING.md: Go build, vet, gofmt, go mod tidy, make lint-changed, router recovery lint, web lint, format, build, and budget, make test-web, playback fixtures, API v2 contract, local paths, size ratchet, bidi, and make test-go pass. The Prometheus rules, actionlint, and shellcheck checks were not run; this branch touches none of their inputs.
Not covered: a hidden but open tab in a real desktop browser (headless Chrome does not throttle it; the 2-minute window is pinned by the unit test), and Safari, Firefox, and mobile browsers.
Surface and build: web app, desktop Chrome; before on base 1a99f7b, after on this branch. The change has no layout effect, so mobile web shows the same dialog and player as before.
Risks
A paused player that stops reporting for more than 2 minutes but later resumes (an app suspended in the background) still resumes, but if the account started another stream meanwhile, both will be playing. Limits are checked when a stream starts, as they are today.
The household and admin session lists still show a crashed paused session for up to 30 minutes; a normal tab close removes it at once.
Checklist
I read and can explain the complete diff.
This pull request addresses one concern.
Each test this pull request adds meets "Decide what to test" in CONTRIBUTING.md.
The Evidence section shows every change a user can see, or how I checked a change nobody sees.
Adversarial review: two independent reviews of the full branch (Claude Opus 5.5 and GPT 6.1 Sol via Codex, correctness, standards, and spec), reconciled and checked against the code. They found a 45-second slot window that freed throttled background tabs, proxy-served sessions waiting 5 minutes, and transcode slots released while the encoder still ran; all three were fixed. A second pass over the follow-up commits found no correctness issues.
Note
Free the stream slot of a player closed while paused
A paused session now releases its stream slot after 2 minutes without activity, while keeping its 30-minute paused grace and transcode slot. countsTowardLimitsLocked in session.go accepts a paused-slot grace that caps the inactivity window for counting; transcode counting passes a zero value to keep the full grace.
The web player now stops the session on page exit. A pagehide listener in usePlaybackSession.ts sends a keepalive DELETE for real page exits and does nothing when the page enters the back-forward cache.
stopSequencedSession in session-mutations.ts gains an immediate flag that skips waiting for an in-flight progress POST while still including the next sequence in the stop body.
Behavioral Change: after a paused session's slot is released, a later progress report from that session does not reclaim the slot; another stream may already hold it.
A web player closed or reloaded while paused never sent its stop, and the
server kept counting the paused session toward the account's stream limit
for the full 30-minute paused grace.
Clients report progress every 10 seconds while paused, so a paused session
now counts toward the stream and transcode limits only inside the active
window. It keeps the paused grace for resuming (Silo-Server#243). The web player also
sends its stop with keepalive on pagehide, unless the page enters the
back-forward cache.
…eam slot frees
A browser throttles a hidden tab's timers to about once a minute, so the
45-second window could free the slot of a paused tab that was still open.
The stream slot now frees after two minutes without activity, also for
proxy-served sessions, and the transcode slot stays held until the session
ends because its encoder does.
It 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 reviews.auto_review.auto_pause_after_reviewed_commits setting.
No actionable comments were generated in the recent review.
Walkthrough
Paused sessions release their stream-limit slot after two minutes without activity while retaining their transcode allocation during the paused grace period. The playback hook stops active sessions on page exit, except when the page enters the back-forward cache.
Stream-limit counting for paused sessions uses a two-minute cap. Transcode-limit counting retains the full paused grace. The test and documentation describe these windows and the session’s continued presence during its paused grace.
Page-unload session stopping
Layer / File(s)
Summary
Immediate sequenced stop and page-unload handling web/src/player/session-mutations.ts, web/src/player/session-mutations.test.ts, web/src/player/hooks/usePlaybackSession.ts, web/src/player/hooks/usePlaybackSession.test.ts
The stop function can skip waiting for queued progress when called for page exit. The hook sends a keepalive stop request for a non-persisted pagehide event and uses the same helper during unmount cleanup. A persisted event does not stop the session. Tests cover both pagehide behavior and request sequencing.
Paused players that are closed or go quiet now free their stream slot, and closing a web player stops its session. No actionable merge-blocking risk remains. The documented tradeoff is that a player that resumes after another stream starts can exceed the limit.
Architecture risk: Low · up to a00c6
The change affects 3 systems.
Changed systems:web, internal, docs
Architecture concerns
No architecture-level concerns identified.
Review details
Systems and components
observed — web (service) was modified; 4 changed files map to changed impact.
observed — internal (service) was modified; 2 changed files map to changed impact.
observed — docs (service) was modified; 1 changed file maps to changed impact.
Before / after behavior
observed — Modified behavior in internal/playback/session.go: Adds the exported PausedStreamSlotGrace constant set to two minutes, with comments describing its stream-slot limit and cleanup behavior.
observed — Modified behavior in internal/playback/session.go: Adds the private noPausedSlotCap constant, set to zero to indicate no separate paused-slot cap.
observed — Modified behavior in internal/playback/session.go: Active stream counts now pass PausedStreamSlotGrace to countsTowardLimitsLocked; previously they used the session’s full paused grace.
observed — Modified behavior in internal/playback/session.go: Transcode counts now pass noPausedSlotCap, preserving the full paused grace for transcode-slot counting instead of applying a shorter cap.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
The title names the main change: a paused web player that closes now frees its stream slot. The changeset adds a server-side 2-minute paused-slot cap, a web pagehide stop with keepalive, and a stopSeq…
Description check
The description states the problem (paused streams counting against limits after a tab close), the approach (pagehide stop, 2-minute paused-slot rule, protocol doc update), validation steps, and risks…
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Full details: Title check
Explanation
The title names the main change: a paused web player that closes now frees its stream slot. The changeset adds a server-side 2-minute paused-slot cap, a web pagehide stop with keepalive, and a stopSequencedSession immediate flag. The title is specific and concise, and it is 67 characters long.
Full details: Description check
Explanation
The description states the problem (paused streams counting against limits after a tab close), the approach (pagehide stop, 2-minute paused-slot rule, protocol doc update), validation steps, and risks. It relates directly to the changeset.
Finishing Touches
Generate unit tests (beta)
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent 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: e6d6c9b3-4d70-4b39-b6d0-5146e28b5b39
Commits
Reviewing files that changed from the base of the PR and between 8701ae4 and a00c6fd.
Files selected for processing: 1
web/src/player/session-mutations.test.ts
Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 0 remain after this review.
The reason will be displayed to describe this comment to others. Learn more.
Resuming a retained paused session bypasses stream admission
A paused session can resume through UpdateProgressSample after its slot has been reassigned, allowing streams to exceed the account's stream or transcode limit. Atomically recheck and reserve capacity before allowing a retained session to resume.
Prompt for LLM
File internal/playback/session.go, lines 2109-2110:
Resuming a retained paused session bypasses stream admission
A quiet paused session can resume through `UpdateProgressSample` after its slot has been given to another session, without passing admission again, so both streams can play despite the account's stream or transcode limit. Recheck and reserve capacity atomically before allowing a retained session to resume.
The reason will be displayed to describe this comment to others. Learn more.
This is a deliberate trade-off, listed under Risks in the description. The transcode half no longer applies: since 0720bbb a quiet paused transcode keeps its transcode slot until cleanup.
For the stream slot: a session is quiet for over 2 minutes only when its client stopped reporting progress, which every native client does every 10 seconds while paused. That is almost always a closed tab, a killed app, or a crash, and freeing that slot is the point of this PR. The rare client that comes back after a longer silence resumes the stream it was already admitted for. Limits are checked when a stream starts, as they are today. Refusing or cutting off that resume would stop a viewer mid-film, which #243 set out to avoid. Rechecking admission on resume would be a separate policy change.
The reason will be displayed to describe this comment to others. Learn more.
That clarification makes sense. I withdraw the suggestion: the stream-limit overage on resume is an explicitly documented trade-off to preserve playback continuity, and the transcode-limit concern no longer applies because quiet paused transcodes retain their slots until cleanup.
Rechecking admission on resume would be a separate policy change, not a necessary fix for this PR.
The reason will be displayed to describe this comment to others. Learn more.
An in-flight progress report delays the unload stop until after page destruction
An in-flight progress request can keep stopSequencedSession from sending the keepalive DELETE before the document is destroyed. Add an unload-specific stop path that starts the request during pagehide while preserving sequence ordering.
Prompt for LLM
File web/src/player/hooks/usePlaybackSession.ts, lines 1273-1275:
An in-flight progress report delays the unload stop until after page destruction
If a progress request is in flight when `pagehide` fires, `stopSequencedSession` waits for it before starting the DELETE, so the document can be destroyed before any keepalive stop request is sent. Provide an unload-specific stop path that initiates the keepalive request during the pagehide event while preserving sequence ordering.
The reason will be displayed to describe this comment to others. Learn more.
Not changing this. The window is real but narrow: a progress report is in flight for a few milliseconds every 10 seconds, so pagehide rarely lands inside it. When it does, the server-side rule in this PR is the fallback: the paused session stops holding its stream slot 2 minutes after its last report. In end-to-end runs in desktop Chrome, closing a paused tab sent the stop every time. A separate unload path would have to duplicate the sequencing that stopSequencedSession owns, which is more risk than this case justifies.
The reason will be displayed to describe this comment to others. Learn more.
Understood. The in-flight request window is a known, accepted tradeoff for this PR. If the unload stop is delayed, the server-side rule releases the quiet paused session’s stream slot after two minutes. No change is needed.
The reason will be displayed to describe this comment to others. Learn more.
Reopening this one. The window is narrow, but when it hits, the server fallback covers only the stream slot, not the transcode slot.
Severity: medium. Trigger: a paused web player that is transcoding is closed or reloaded while its 10-second progress report is still in flight. That can last up to about 15 seconds when the request is slow or retrying: three attempts with a 5-second timeout each. Impact:stopSequencedSession sends the DELETE only after waitForProgress(state.tail) settles. The page is gone by then, so the keepalive DELETE never goes out. The stream slot frees after 2 minutes, but transcodeCountExcludingLocked passes noPausedSlotCap, so the transcode slot stays held for the whole 30-minute paused grace. An account with MaxTranscodes of 1 can't start another transcode for half an hour.
Repair: the page-exit stop doesn't need to wait for that report. The stop body already carries the next sequence and the latest sample. Once the stop lands, the server rejects the older report: StopAttempt only advances last_sequence forward, and progress acceptance requires stopped_at IS NULL AND last_sequence < $2. So the pagehide path can send its stop at once. The in-app unmount stop keeps waiting, because its page stays alive. This adds a flag; it doesn't duplicate the sequencing logic.
I'm fixing this in a commit on this branch, so there's no need to change it yourself.
The reason will be displayed to describe this comment to others. Learn more.
Agreed—the retained transcode slot makes this more consequential than the earlier assessment suggested. Sending the page-exit stop immediately, while retaining the wait for in-app unmounts, sounds like a targeted fix, provided the server’s sequence checks behave as described.
Thanks for handling the commit. I won’t make any changes.
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 8701ae4. The pagehide stop now passes immediate to stopSequencedSession, which skips waitForProgress, so the keepalive DELETE goes out while the page is still alive. The in-app unmount stop still waits for queued progress. The new test sends an unloading page's stop without waiting for progress in flight in session-mutations.test.ts holds a progress request open and checks that the DELETE goes out within microtasks, with keepalive set and a higher sequence than the pending report. It fails on eb92010 and passes here. The session-mutations and usePlaybackSession suites pass (101 tests), and so do tsc, ESLint, and Prettier.
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the update. The reported fix addresses the unload race while preserving the existing sequencing for in-app unmounts. The new test also covers the key failure case: an in-flight progress request must not delay the keepalive stop.
I haven’t independently verified the commit or test results.
The reason will be displayed to describe this comment to others. Learn more.
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: 9f135443-7f0e-4547-962b-fafedbb60c43
Commits
Reviewing files that changed from the base of the PR and between 1a99f7b and 98af19a.
Files selected for processing: 5
docs/architecture/playback-protocol-v3.md
internal/playback/session.go
internal/playback/session_paused_grace_test.go
web/src/player/hooks/usePlaybackSession.test.ts
web/src/player/hooks/usePlaybackSession.ts
Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.
The reason will be displayed to describe this comment to others. Learn more.
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: 2eae4dd1-e2b8-453b-b8ba-f17e8b1ee7be
Commits
Reviewing files that changed from the base of the PR and between 98af19a and 795a046.
Files selected for processing: 5
docs/architecture/playback-protocol-v3.md
internal/playback/session.go
internal/playback/session_paused_grace_test.go
web/src/player/hooks/usePlaybackSession.test.ts
web/src/player/hooks/usePlaybackSession.ts
Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 2 remain after this review.
Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.
Reviewing changes in Silo
Include the related issue, expected behavior, and validation steps in the PR description.
For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
Follow this repository's AGENTS.md and CONTRIBUTING.md.
Request another review with @kody start-review in a PR comment.
React with 👍 or 👎 to give feedback on individual suggestions.
Review settingsReview Options
The following review options are enabled or disabled:
Options
Enabled
Bug
✅
Performance
✅
Security
✅
Business Logic
❌
⚠️ 4 Kody Rule(s) were not evaluated
These rules declare that they need repository context beyond this diff, and the review could not retrieve it, so they were not judged on this pull request:
Preserve optional store capabilities through production wrappers
Detach mandatory cleanup from request cancellation and bound its lifetime
Preserve durable media identity and share identity-evidence precedence
Bound decoder throughput trades and share direct-play eligibility
A tab closed while its 10-second progress report was still in flight
queued the keepalive stop behind that report, and the page was gone
before it went out. The stream slot then freed after 2 minutes, but a
transcode kept its slot for the 30-minute paused grace. The pagehide
stop now goes out at once; it carries the newest sequence, so the
server refuses the older report if it lands later. The in-app unmount
stop still waits, since its page stays alive.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Reviewed head: a00c6fd510 (eb9201073a plus a fix commit, 8701ae4451, and a test fix, a00c6fd510, from this review).
The fix holds. All four native clients already report progress every 10 seconds while paused: web useWatchProgress, Android PROGRESS_REPORT_INTERVAL_MS, Apple startProgressReporting, and the Roku progressTimer. Each report refreshes LastActivityAt through touchSessionLocked, so a paused session that has been quiet for 2 minutes has, in almost every case, lost its player. Admission is the only caller of the count helpers. Jellyfin-compatibility sessions return before the new cap, because the compat expiry claimer is installed whenever Postgres is present. The transcode count behaves exactly as before.
Addressed
The unload stop could wait behind a progress report in flight (the earlier thread on usePlaybackSession.ts, reopened). When it did, the page was gone before the DELETE went out. The 2-minute rule then freed the stream slot, but a transcoding session kept its transcode slot for the full 30-minute paused grace. Fixed in 8701ae4451: the pagehide stop no longer waits for queued progress. The stop carries the newest sequence, and the server refuses older progress once a stop lands (stopped_at IS NULL AND last_sequence < $2), so the order stays correct. The in-app unmount stop still waits.
Checked and not changed
A session on one replica while its progress goes to another. The protocol doc already requires session affinity for v2 progress (§2.5, "v2 progress needs the same affinity"). Without affinity, a playing session is already dropped after 45 seconds, so the 2-minute cap adds no new failure.
Compat sessions on a single node. The claimer is installed whenever a database pool exists, so compat sessions never reach the cap.
Resume after another stream took the slot. Already discussed in the threads and documented in §2.5 and Risks.
Left for the maintainers
Maintainer decision: a paused player that legitimately goes quiet for more than 2 minutes loses its stream slot. Examples are a Cast receiver whose sender phone went to sleep (§2.5 names that case) and a phone app suspended in the background. If another device starts meanwhile, both play once the first resumes. This is the Risks item, and Cast makes it more common than "a lost player" suggests. Accepting it keeps the fix simple. Checking admission again on resume would be a separate policy change.
Tests
TestQuietPausedSessionReleasesStreamSlot fails on the base commit (a quiet paused session still held the stream slot) and passes on the head.
The usePlaybackSession page unload test fails on the base commit (no DELETE sent) and passes on the head.
The new session-mutations test for an unload stop with progress in flight fails on eb9201073a and passes on a00c6fd510. Following CodeRabbit's note, it now holds a progress request that has really started before it stops.
The session-mutations and usePlaybackSession suites (101 tests), go test ./internal/playback/, tsc, ESLint, and Prettier pass.
CI on eb9201073a failed only TestBeforeMigrateBackupOnAnOldSchemaDB in cmd/silo: a backup restore found "1 other clients connected". That test is unrelated to this change. CI is running again on the new head.
Validated features
User management / access groups / invites — Server #1196 C1 (passed on 7cc2c1f2): minor change. Stream and transcode limits are still enforced at start. A paused session that has been quiet for 2 minutes now stops counting toward max streams, where before it counted for 30 minutes. The PR's Validation tasks: line is correct.
The board query couldn't run for this review, so these cases were read from the validation issues directly.
Other checks
User manual: unaffected. running-a-server/access.md says only that Max streams limits simultaneous playback, and no page says how long a paused or closed player holds a slot.
Other clients: Apple, Android, and Roku need no change. Each already reports while paused, so N/A is correct.
Jellyfin compatibility: unchanged on purpose.
Second review: one cross-provider round (Codex, gpt-6.1-sol) raised two findings. The unload-stop finding is fixed above, and the cross-replica finding is answered above.
Fit: 8/10 · Readiness: 9/10 — conditional (assuming CI is green)
Fit: this fixes a real stream-limit problem at the boundary that owns it, with no new setting or API surface. It stops short of 9 because stream limits now apply only at start for a paused device that goes quiet, which is the maintainer decision above.
Readiness: the approach is sound, and every new test failed before its fix.
The reason will be displayed to describe this comment to others. Learn more.
Immediate stop can overwrite the final playback position with stale progress
Revises an earlier Kody suggestion on web/src/player/hooks/usePlaybackSession.ts:1273 (2026-11-14 16:26 UTC).
Serialize stop finalization against progress side effects on the server while retaining the immediate unload request.
Prompt for LLM
File web/src/player/session-mutations.ts, lines 199-200:
**Revises an earlier Kody suggestion** on `web/src/player/hooks/usePlaybackSession.ts:1273` (2026-11-14 16:26 UTC).
Immediate stop can overwrite the final playback position with stale progress
Skipping the progress drain allows an already accepted progress request to finish its side effects after the stop has persisted its newer final sample, overwriting the viewer's final playback position with stale progress. Serialize stop finalization against in-flight progress side effects on the server while retaining the immediate unload request; this revises the earlier unload-stop suggestion because issuing the request immediately exposes this separate persistence race.
The reason will be displayed to describe this comment to others. Learn more.
The race is real, but it can't make things worse than before, so I'm not changing this in this PR.
Mechanism (confirmed):persistProgressV2 holds progressSideEffectLock, while StopPlaybackV2 → finalizeStopV2 → finishStop doesn't. A progress report that the row accepted just before the stop can therefore finish its user-store write after the stop wrote the final sample. Its recheck then finds the attempt stopped and returns without repairing the write, so the older position stays.
Impact: this happens only when the tab closes while a progress report is in flight and that report's side effects are still running when the stop lands.
If the player was paused, which is the case this PR targets, both samples carry the same position, so nothing changes.
If it was playing, the resume point can land up to about 10 seconds early. That's the same position the account kept when the stop never went out, which is what happened in this window before 8701ae4, and always on the base branch, which sent no unload stop.
So the change is never worse than its alternative. In every other case it delivers the stop and the newer final sample.
Serializing stop finalization against progress side effects on the server would close the window for every caller. That's a separate change to the stop path, with lock-ordering risk (setConfirmedPauseState takes the same lock), so it doesn't belong in this PR.
The reason will be displayed to describe this comment to others. Learn more.
That sounds reasonable to defer: the race is real, but fixing it would broaden this PR into the shared server stop path and introduce lock-ordering risk.
I would qualify the claim that it can never be worse than before. The comparison depends on what progress would otherwise have been persisted and on the timing of the writes; likewise, a 10-second bound assumes reports and their side effects are not delayed longer than the normal reporting interval. The two paused samples also need not always match—for example, if a seek occurred between them.
The race is worth tracking as a separate follow-up to serialize or otherwise order stop and progress persistence. Would you like me to create an issue?
The reason will be displayed to describe this comment to others. Learn more.
Fair point on the seek: two paused samples can differ, so "same position" isn't guaranteed. The comparison still holds, though. In that window, without the immediate stop, the older in-flight sample is also the last one written, because no stop goes out. Delayed reports widen the gap the same way on both paths. Please don't open an issue; the maintainers will decide whether to track the server-side ordering.
The reason will be displayed to describe this comment to others. Learn more.
Agreed. Given that comparison, deferring the server-side ordering fix is reasonable. The paused samples may differ, but in the described race, the older in-flight sample would also be the last one written without the immediate stop.
I won’t open an issue; I’ll leave tracking the follow-up to the maintainers.
Start the progress request before the unloading stop.
The test's pending mock lands on the DELETE, not the progress POST. sendSessionProgress queues its fetch through catch().then(), so the immediate stop's DELETE reaches the first mock call before the POST. The test therefore does not cover a stop sent while progress is still in flight.
Wait until the POST has started. Make that POST the unresolved request. Return a stop receipt for the DELETE. Then assert the call order:
Suggested test change
- const fetcher = vi
- .fn()
- .mockImplementationOnce(() => new Promise<Response>(() => {}))
- .mockImplementation(async () => stopped());
+ let progressStarted!: () => void;
+ const progressCalled = new Promise<void>((resolve) => (progressStarted = resolve));
+ const fetcher = vi
+ .fn()
+ .mockImplementationOnce(() => {
+ progressStarted();
+ return new Promise<Response>(() => {});
+ })
+ .mockImplementation(async () => stopped());
vi.stubGlobal("fetch", fetcher);
registerSessionMutations("stop-unload", "install");
void sendSessionProgress(config, "stop-unload", sample).catch(() => {});
+ await progressCalled;
void stopSequencedSession(config, "stop-unload", true, true);
// A page in pagehide gets only microtasks before teardown, no timers.
for (let i = 0; i < 10; i++) await Promise.resolve();
+ expect(fetcher.mock.calls.map((call) => call[1].method)).toEqual(["POST", "DELETE"]);
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: 22643072-5132-4bb1-9a5e-e067f088e298
Commits
Reviewing files that changed from the base of the PR and between eb92010 and 8701ae4.
Files selected for processing: 3
web/src/player/hooks/usePlaybackSession.ts
web/src/player/session-mutations.test.ts
web/src/player/session-mutations.ts
Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 0 remain after this review.
The test started the stop before the progress fetch, so the DELETE could
take the request that never answers and the case of a stop sent while
progress is in flight went untested. It now waits until the progress
POST is pending, then checks that the DELETE follows it.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
CodeRabbit's nitpick on the unload test (review 5906675849): Fixed in a00c6fd. The test now waits until the progress POST has started, keeps that request pending, and checks that the calls run POST then DELETE, with keepalive set and a higher sequence on the DELETE. It fails on eb92010 (['POST', undefined]) and passes on this head.
Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.
Reviewing changes in Silo
Include the related issue, expected behavior, and validation steps in the PR description.
For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
Follow this repository's AGENTS.md and CONTRIBUTING.md.
Request another review with @kody start-review in a PR comment.
React with 👍 or 👎 to give feedback on individual suggestions.
Review settingsReview Options
The following review options are enabled or disabled:
Options
Enabled
Bug
✅
Performance
✅
Security
✅
Business Logic
❌
⚠️ 4 Kody Rule(s) were not evaluated
These rules declare that they need repository context beyond this diff, and the review could not retrieve it, so they were not judged on this pull request:
Preserve optional store capabilities through production wrappers
Detach mandatory cleanup from request cancellation and bound its lifetime
Preserve durable media identity and share identity-evidence precedence
Bound decoder throughput trades and share direct-play eligibility
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bugSomething isn't workinggoPull requests that update go codeimpact: playbackCan't play, stalls, or wrong mediajavascriptPull requests that update javascript codepriority: P1Core-path bug; painful workaround — next after P0size/M50–199 added + deleted lines (all files); change volume, not priority.
2 participants
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Related issue: N/A
Validation tasks: changes #1196 C1 (stream limits still enforced; a paused session that has gone quiet stops counting toward max streams after 2 minutes instead of 30)
Other clients: Apple N/A, Android N/A, Roku N/A (each already reports progress every 10 seconds while paused, which is what the new server rule relies on; nothing to change)
When someone pauses a movie in the web app and then closes the tab, reloads, or quits the browser, the stream keeps counting against the account's stream limit for 30 minutes. On an account limited to one or two streams, the rest of the household gets "Streaming limit reached" until it expires. Admins see the closed stream as a live paused session.
Two things combine. The web player only sends its stop when the player is closed inside the app; a page unload never runs that path. The server then keeps a paused session for the 30-minute paused grace, which exists so a player that comes back after a long pause can still resume (#243), and the session counts toward the limits for that whole time.
This change makes the web player send its stop when the page goes away, and stops a paused session that has gone quiet from holding a stream slot after 2 minutes, while still keeping the session for 30 minutes.
Approach
pagehideit sends the session stop withkeepalive, sharing the code path of the existing unmount stop. Unlike the unmount stop, it doesn't wait for a progress report still in flight, because the page may be gone before that report settles. The stop carries the newest sequence, so the server refuses the older report if it lands later. A page that enters the back-forward cache keeps its session, since it can come back playing.Protocol doc §2.5 describes the new slot rule.
Validation
pagehidelistener. A session-mutations test covers an unload stop sent while a progress report is still in flight; it fails on eb92010, before that path stopped waiting for progress.gofmt,go mod tidy,make lint-changed, router recovery lint, web lint, format, build, and budget,make test-web, playback fixtures, API v2 contract, local paths, size ratchet, bidi, andmake test-gopass. The Prometheus rules, actionlint, and shellcheck checks were not run; this branch touches none of their inputs.Not covered: a hidden but open tab in a real desktop browser (headless Chrome does not throttle it; the 2-minute window is pinned by the unit test), and Safari, Firefox, and mobile browsers.
Evidence
Evidence: https://evidence.siloserver.org/r/silo-server/pr-4147/
Surface and build: web app, desktop Chrome; before on base 1a99f7b, after on this branch. The change has no layout effect, so mobile web shows the same dialog and player as before.
Risks
Checklist
AI Disclosure
Note
Free the stream slot of a player closed while paused
countsTowardLimitsLockedin session.go accepts a paused-slot grace that caps the inactivity window for counting; transcode counting passes a zero value to keep the full grace.pagehidelistener in usePlaybackSession.ts sends a keepalive DELETE for real page exits and does nothing when the page enters the back-forward cache.stopSequencedSessionin session-mutations.ts gains animmediateflag that skips waiting for an in-flight progress POST while still including the next sequence in the stop body.Macroscope summarized a00c6fd.