Repository navigation
fix(preview): close streams when their session is invalidated - #802
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Warning Review limit reached
This review includes 4 billable files and costs up to $1.00. Or wait 54 minutes for your next included review. View limit details
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Race preview streams against session invalidation apps/server/src/preview/ServerBrowserStream.ts, apps/server/src/preview/ServerBrowserStream.test.ts, FORK.md, docs/j5/product/upstream.md |
The handler observes authenticated-session invalidation during an established stream. Tests check viewer detachment, socket closure, and active input interruption. Documentation records the stream behavior and its test coverage. |
Estimated code review effort: 2 (Simple) | ~10 minutes
Change: Bug fix · Severity of issue fixed: Medium
Sequence Diagram(s)
sequenceDiagram
participant ViewerSocket
participant ServerBrowserStream
participant SessionStore
participant InputFiber
ViewerSocket->>ServerBrowserStream: Open authenticated preview stream
ServerBrowserStream->>SessionStore: Await invalidation for the session
SessionStore-->>ServerBrowserStream: Signal session invalidation
ServerBrowserStream-->>ViewerSocket: Complete stream with an empty response
ServerBrowserStream-->>InputFiber: Interrupt active input
Possibly related issues
- Jacksondr5/j5code issue 276: It tracks revoked or expired preview sessions continuing to receive frames and send input, which this change addresses.
Possibly related PRs
- Jacksondr5/j5code#797: It reports established preview streams remaining usable after a collaborator is demoted; this change ends the stream when its session is invalidated.
Suggested reviewers: juliusmarminge, maria-rcks
Merge Risk: 
Minimal · previous review 074ee
-
No merge-blocking risk is established from the supplied review evidence.
Pre-merge checks: 
4
-
Full details: Description check
-
Explanation
The description is detailed and follows the required structure. It explains the problem, implementation, testing evidence, live testing limits, upstream impact, merge risk, and checklist status. The UI section is omitted appropriately because no UI changed, and the unchecked Surfaces item is explained by the listed unverified scenarios.
Full details: Linked Issues check
-
Explanation
The changes satisfy the coding requirements in
#798.apps/server/src/preview/ServerBrowserStream.tsretrievesSessionStoreand races the scoped viewer lifecycle againstawaitInvalidation. This interrupts stream and input fibers and runs scope finalizers. The test adds established-socket coverage for read-only and operate sessions, including socket closure, input interruption, detachment, and rejection of later frames.FORK.mdrecords the upstream-owned change. The linked objective treats offering the fix upstream as a separate publication step, so no upstream pull request is required here.
Full details: Out of Scope Changes check
-
Explanation
The four changed files stay within
#798. The source change implements session invalidation. The test verifies the required behavior.FORK.mdrecords the upstream-owned file.docs/j5/product/upstream.mddocuments the resulting product behavior. No unrelated implementation or product change is shown.
-
Finishing Touches
-
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
Jacksondr5
left a comment
There was a problem hiding this comment.
The race wraps the whole scoped attach/upgrade/viewer lifecycle, so invalidation interrupts both the stream and the input fibers and releases the viewer. awaitInvalidation subscribes before it reads, so a revocation during the upgrade isn't lost. The tests wait on Deferred milestones, not timers. FORK.md records both upstream files. No code findings. Jackson reviews the D33 wording separately.
Review panel: Claude Opus 5.5 (lead) and GPT-6 Astra, for @Jacksondr5.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts: # FORK.md
Problem
An established preview WebSocket keeps streaming and accepting input after its session is revoked, including when its collaborator is demoted. The ordinary browser reload masks this for normal clients, but a client retaining the socket keeps access. Closes #798.
What changed
I race the entire scoped preview viewer lifecycle against
SessionStore.awaitInvalidation, following the existing RPC socket behavior. Invalidation interrupts the stream and input fibers and runs the viewer finalizers. Existing frame backpressure and control handling remain intact. An action already dispatched to Playwright cannot be rolled back.Evidence
At
e77cd431d5d74200706d9d8d0b0d40fcaf645bca, based onj5/mainat5e45a791e238dd5357c17b188a9cdda1b5700afa, using pinned Node 26.12.1 and pnpm 12.14.0:vp run check:changedpassed: formatting, lint, both Knip checks, generated GraphQL checks, typechecks for all three affected packages, and 13 preview-stream tests. The stream suite includes two deterministic established-socket revocation cases.vp test run apps/server/src/auth/SessionStore.test.ts: 16 tests passed, for 29 focused tests total.git diff --checkpassed and the working tree is clean.8456ca762.Not verified: full CI on this new head, browser tests locally for this merge, desktop/mobile, relay/tailnet, expiry or restart live scenarios, post-invalidation owner click receipt, and #799's separate preview-initialization problem. No UI source changed, so there are no visual changes requiring screenshots.
Live testing
PASS on an isolated real server, real SessionStore and real server Chromium at
d3443282eaaaaf9545bbce2ad22b04711667edbd, base6a6aa43d08034bcd3bb69f2364903c061e7c8137. The current heade77cd431d5d74200706d9d8d0b0d40fcaf645bcaincludes the later fork-table/D33 documentation commit and a merge ofj5/main. Preview-stream and SessionStore source/tests remain unchanged; focused automated validation was repeated, but this live flow was not rerun for the merge.An independent tester retained Node preview WebSockets across each event, avoiding the ordinary client's automatic reload:
j5.people.setLevelindependently closed the retained socket with code 1001. Its frame count stayed at 25; the owner's stream continued from 30 to 42 and regained control.authenticated: falseon the session endpoint.Observation windows were finite. Owner control acquisition and continuing frames were observed; an owner click after invalidation was not separately counted. No provider turn was sent. The disposable test servers and sockets were stopped after verification.
Upstream impact
apps/server/src/preview/ServerBrowserStream.tsand its test are recorded inFORK.md, section “Preview stream session invalidation (#798)” and the file table. D33 indocs/j5/product/upstream.mdnow states the explicit preview invalidation behavior. The issue requests this shared authorization fix; offering it upstream is a separate publication step. #799 is outside this change.Merge Danger
Door: two-way; a revert restores the prior stream lifecycle.
Blast Radius: authenticated preview-stream lifecycle and its scoped cleanup.
After merge: consider offering the shared fix upstream separately; no upstream PR is created here.
Checklist
FORK.md(case text and file-table row) in this PRdocs/j5/product/upstream.md— An open preview stream outlives its session's revocation #798 and D33AGENTS.md) — real server/Chromium revocation and demotion verified; wider surfaces listed as unverifieddocs/j5/product/and user docs rewritten where this changes them — existing D33 implementation statement corrected