Repository navigation
fix(mobile): release streams whose ready arrives after a replayed cancel - #22945
Conversation
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (3)
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 3 remain after this review. 📝 WalkthroughWalkthroughThe stream registry now clears a stored subscription ID when it marks a stream for replay. Tests cover unsubscribe behavior for runtime client-event and browser screencast subscriptions, including disposal before readiness, while disconnected, and after repeated disposal. Priority: ⬇️ Low Merge Risk: ⚪ Minimal · up to No actionable merge-blocking risk is evident; the change is ready for normal merge checks. Security Architecture ReviewSecurity architecture risk: 🔵 Low · up to The change is intended to stop a reopened feed when its new registration arrives after cancellation. It does not add a new capability or access path. The mobile cleanup behavior is supported by the code and tests, but desktop-side teardown was not independently verified. Retained concerns Security review detailsSecurity Blast Radius
Trust Boundaries and Controls
Resilience and Maintainability Implications
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
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 |
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Replay forgets the closed socket's subscription id —
markForReplay()now clearsstream.subscriptionId, so a disposal between the replay and the newreadytakes the existing cancel-before-ready tombstone path and the lateready's unsubscribe carries the new id. - Registry tests parameterized over both replayed stream kinds —
browser.screencastandruntime.clientEvents.subscribepin the new-id unsubscribe, the disconnected disposal, the unchanged first-ready path, and idempotent disposal. - End-to-end direct-client test — drives a socket close, reconnect, reauthentication and replay, then asserts the unsubscribe lands on the new socket with the new id.
Verification: the focused suites pass (13/13); reverting only the two-line fix fails exactly 7 of them, including the new end-to-end client test. oxlint on the three changed files and tsc --noEmit in mobile/ are clean. The premise also holds server-side — subscriptions are socket-scoped and torn down on close (runtime-rpc-lifecycle.ts:244), and both browser.screencast.unsubscribe and the connectionId-prefixed runtime.clientEvents.unsubscribe are no-ops for a dead-socket id — so clearing the id is safe rather than a leak.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Added a regression test for browser-stream replacement during replay —
rpc-client-stream-registry.test.tsnow covers the case where a replayedbrowser.screencast(page-1) is replaced by a newer tab (page-2) before its newready: the latereadymust unsubscribe the id the new connection assigned topage-1and leavepage-2registered.
The new test exercises a genuine path that the previous suite did not: replaceBrowserStream disposes the pending replayed request, which with the fix routes through the cancel-before-ready tombstone (disposeServerSubscription leaves the sent placeholder in place) and then releases it with the new connection's id. It fails against the reverted two-line fix (unsubscribes page-1-old-connection instead) and passes with it; the focused suites are now 14/14. No production code changed in this commit.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
|
Reviewed and tested. Status: ready for review. Review. An up-front architecture challenge, a precedent check, readiness checks at the start and the end, and two review rounds, both nits-only. A test was added for a reopened browser stream that is replaced before its ready (7086992); it fails without the fix. Notifications and account feeds are handled in #23032. Testing. Live QA: an iOS simulator running this branch's phone app, paired to an isolated desktop host. The phone opened a browser tab preview. The desktop host was restarted, so the phone reconnected and replayed its streams, and the phone left the preview immediately. The desktop was not left showing the browser as controlled by or streaming to the phone. The preview opened normally again after the reconnect. Desktop after the restart and an immediate leave (no stuck control or stream): |




ELI5
Some live feeds the phone opens on the desktop, like the browser tab preview and the workspace change feed, get a ticket number from the desktop once they start. The phone uses that number to say "stop" later. When the connection drops and comes back, the phone reopens those feeds and the desktop hands out new numbers, but the phone kept the old ones. If you left the screen in the short moment before the new number arrived, the phone said "stop" with the old number, which the desktop no longer recognises, so the new feed kept running until the connection closed again.
What Changed
Before: after a reconnect, leaving a browser tab (or any screen that watches workspace changes) just as the phone was reopening its feeds could leave the desktop streaming screencast frames or workspace events to a phone that was no longer listening. For a browser tab the phone was driving, the desktop could also keep showing that tab as controlled by the phone. That lasted until the connection closed, which on a healthy connection can be a long time, or, for the browser preview, until the phone opened another one.
After: the stop goes to the feed that is actually running. The desktop tears the feed down as soon as the reopened feed reports in.
Mechanism: the direct connection's stream registry (
mobile/src/transport/rpc-client-stream-registry.ts) keeps, for each open feed, the id the desktop assigned it in itsreadyreply. When the socket closes, the registry marks every feed to be reopened on the next connection. That step now also forgets each feed's desktop-assigned id, because the id named a registration on the socket that just closed.With no id on record, a disposal after the reopen but before the new
readytakes the path that already existed for "left before the feed was ready". The feed stays as a cancelled placeholder, and when the newreadyarrives the registry sends the unsubscribe with the new id and removes the placeholder. A disposal while still disconnected removes the feed outright, since nothing was sent on the new connection.Why
The existing cancel-before-ready handling was already correct; it just never ran after a reconnect, because a leftover id from the old socket made the stream look ready. Clearing the id restores the one rule the registry already relies on: "has an id" means "ready on this connection".
The alternative was to keep the old id and add a second check at disposal time, asking whether the id belongs to the current connection. That would put two sources of truth side by side and still need the cancel-before-ready path for the new id. Tracking already-removed requests so a late
readycould still be released was also considered. With the id cleared, no path removes a feed that was sent on the current connection and is still waiting for itsready, so that tracking would be dead code.The relay connection does not have this problem. It never reopens feeds within a session: when a relay session closes, its feed list is cleared (
mobile-relay-rpc-session.tsclose/fail→streams.clear()), and a new session opens fresh feeds. Moving a connection between direct and relay is not affected either: it opens a new feed on the new session and closes the old one on the old session, and each keeps its own id.A reopened feed is resent under the same request number on the new connection rather than as a fresh request, so this relies on the connection layer discarding any reply from the closed socket before the registry sees it; it does, because the closed socket's encryption key is cleared before the registry forgets its ids.
Linked Issue
Part of #22928
Visual Proof
Pending: live QA runs after the review loop
Testing
Registry tests (
rpc-client-stream-registry.test.ts) run for bothbrowser.screencastandruntime.clientEvents.subscribe:ready; then thereadyarrives. Exactly one unsubscribe is sent, with the new id, and none with the old one. Fails without the fix.ready.readystill sends exactly one unsubscribe. Fails without the fix.ready: the reopened feed is unsubscribed with its new id and the newer feed stays. Fails without the fix.Client test (
rpc-client-runtime-events.test.ts) drives the real direct client through a socket close, reconnect, reauthentication and replay. The disposal before the newreadysends the unsubscribe on the new socket with the new id. Fails without the fix.Reverting the two-line fix makes 8 of these tests fail; restoring it makes all pass. The mobile typecheck and lint pass on the changed files.
AI Disclosure
Review
readycarrying an id and accepts an unsubscribe by that id; an older desktop now receives an unsubscribe naming the feed that is actually running, instead of one naming a leftover id.Agent skill upstream boundary
docs/reference/agent-skill-sharing-upstream-boundary.mdand copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.Notes
The desktop notification feed has the same stale-id problem, but its id is held by the notification code rather than by the connection, so fixing it means moving that ownership into the connection. That is a separate change in this series.
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)