Repository navigation
fix(mobile): unsubscribe session tabs by request on the direct connection - #22943
Conversation
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Direct transport sends the stream's request id on unsubscribe —
mobile/src/transport/rpc-client-stream-registry.ts:216now passesidtobuildStreamUnsubscribe, so a disposedsession.tabs.subscribestream names itself insession.tabs.unsubscribeinstead of leaving the host to sweep every stream for the worktree. This matches the relay transport and the desktop shared-control client, and is confined to session tabs (requestIdis unused fornativeChat.subscribe). - Host contract already supports it — the stream is registered under
session.tabs:{connection}:{worktree}:{requestId}(src/main/runtime/rpc/methods/session-tabs.ts:114) andsubscriptionIdcleans exactly that key (:174); without it the prefix sweep after the awaited worktree lookup can end a newer sibling stream. - Client test pins the request id —
mobile/src/transport/rpc-client-stream-registry.test.tsopens two streams for one worktree and asserts the older one's unsubscribe carries the older request id; it fails without the production change. - Host test exercises the real registry —
src/main/runtime/rpc/methods/session-tabs-unsubscribe.test.tsdrives two streams through the real dispatcher andRuntimeSubscriptionRegistry: per-request unsubscribe ends only the named stream, and a no-id unsubscribe still sweeps both, pinning the fallback the fix stops triggering.
Both changed test files pass locally (mobile vitest and repo vitest). Backwards compatibility holds: SessionTabsUnsubscribe is a plain z.object extend, so a host without the field strips subscriptionId and keeps the existing sweep. The documented out-of-scope race (disposing before the host registers the stream) is unchanged by this PR.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
|
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 (2)
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 4 remain after this review. 📝 WalkthroughWalkthroughThe client tracks whether a session-tabs stream has received a snapshot. If disposal occurs before registration, the client defers unsubscribe until a snapshot arrives and then uses the stream request ID. Tests cover snapshot handling, reconnect replay, and cases where the deferred unsubscribe is dropped. Runtime tests verify that unsubscribe ends only the named stream when an ID is provided, and both streams when no ID is provided. Priority: ⬇️ Low Merge Risk: ⚪ Minimal · up to The deferred unsubscribe targets the intended stream, and the identified end and failure paths do not leave a stale client subscription. No merge-blocking issue is established. Security Architecture ReviewSecurity architecture risk: 🔵 Low · up to The change narrows which tab stream is stopped and does not appear to expand access. A cancelled stream can, however, remain pending if its first snapshot never arrives, leaving cleanup dependent on a later error or disconnect. Retained concerns
Security review detailsSecurity Blast Radius
Trust Boundaries and Controls
Resilience and Maintainability Implications
Hardening Proposals
🚥 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 |
…napshot The desktop registers a tab-list stream only as it emits the first snapshot. A direct unsubscribe sent before that found nothing, and with per-request addressing no later worktree-wide sweep collects the late stream, so it kept its desktop listener until the socket closed. Hold the unsubscribe until the snapshot arrives, as the relay connection does.
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
Reviewed the delta since the prior pullfrog review (commit 59ea3ac, "hold a direct session tabs unsubscribe until the first snapshot") on top of the earlier request-id fix.
- Deferred session-tabs unsubscribe until the host registers the stream — the direct transport now holds a disposed
session.tabs.subscribestream (cancelled, kept in the map) when it has not yet seen a snapshot, then sends the per-requestsession.tabs.unsubscribeonce the snapshot confirms the host registered it. This closes the window where an unsubscribe sent before registration found nothing and the late stream kept its host listener.awaitsRegistration/recordSnapshotare scoped tosession.tabs.subscribe, so no other streaming method is affected. - Reset the hold across reconnects —
markForReplayclearssent/receivedSnapshot, andreplayAfterAuthenticationdrops streams that are stillcancelled, so a replayed stream holds again until its new snapshot and a held-but-never-acknowledged stream cannot survive a reconnect. - Dropped stale held unsubscribes — a held stream removed by an
endframe or a reconnect emits nothing, avoiding an unsubscribe for a registration the host no longer owns. - Tests — three new registry tests cover the hold, the reconnect re-hold, and the end/reconnect drop; the per-request test now delivers the older stream's snapshot first. The two host tests drive real streams through the dispatcher and
RuntimeSubscriptionRegistry, pinning that a per-request unsubscribe ends one stream and a no-id unsubscribe still sweeps the worktree. I confirmed all three hold tests fail withawaitsRegistrationneutered, so they are not theatre.
All four changed test files pass locally (mobile 38 tests, host 5 tests) and mobile typecheck passes. Backwards compatibility holds: SessionTabsUnsubscribe is a non-strict z.object, so a host without the field strips subscriptionId and keeps its sweep; host support for the field landed in v1.4.68 and the app is 1.4.197.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
Reviewed the new commit pushed during the previous review, a2bb68e ("test(mobile): cover a held session tabs unsubscribe whose subscribe fails"). It is test-only; no production code changed.
- Held unsubscribe on a failed subscribe is now pinned — the "drops a held session tabs unsubscribe" registry test delivers an
ok: falseerror for a stream disposed before its snapshot, and asserts the listener sees no event and no unsubscribe is sent. The stream is removed on the error, so a later reconnect drops the sibling too. The test still fails without the hold (the two disposes would emit two unsubscribes, giving four sent requests instead of two), so it remains real coverage. - Coverage trade — this replaces the previous
end-frame variant of the same test, so the held-stream-receives-endpath is no longer asserted in this file. Both paths funnel through the sameremoveinhandleResponse, so the loss is immaterial.
mobile/src/transport/rpc-client-stream-registry.test.ts passes (6 tests). No further concerns.
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. The final round was clean apart from nits. Review found that naming each tab-list stream in the unsubscribe removed an incidental cleanup of tab-list streams that register late, so a stream closed before its first snapshot could keep a desktop listener until the connection closed. The direct connection now holds that unsubscribe until the first snapshot, as the relay connection already does (59ea3ac, a2bb68e). The new tests fail without the change. The desktop side of the same gap is fixed separately in #23045. Testing. Live QA: an iOS simulator running this branch's phone app, paired to an isolated desktop host. The phone left and reopened the worktree 5 times quickly. Its worktree row then tracked a desktop tab being created (1 → 2) and closed (2 → 1), with no error banner. |
…tabs-direct-request-id # Conflicts: # mobile/src/transport/rpc-client-stream-registry.ts
…et after merging main Move the pre-snapshot hold into the session tabs stream module, note that only older hosts need it, and give the unsubscribe test the real registration version now that a worktree-wide unsubscribe spares later streams.
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
Reviewed the delta since the prior pullfrog review (a2bb68e → 94d92e0): a merge of main plus a behavior-preserving refactor of the session-tabs unsubscribe hold.
- Hold extracted into the stream module — the pre-snapshot hold moved out of
disposeintoholdUnsubscribeatmobile/src/transport/rpc-client-session-tabs-stream.ts:19, withawaitsRegistrationnow module-private. The call site atmobile/src/transport/rpc-client-stream-registry.ts:224is unchanged in behavior: it still marks the streamcancelledand returns without sending, and the helper preserves themethod === 'session.tabs.subscribe'scoping so no other streaming method is affected. - JSDoc clarified for older hosts — the doc now states only older hosts need the hold, since newer hosts register on arrival and still emit that snapshot, so the hold merely delays the unsubscribe.
- Test pins no double unsubscribe — the hold test (
mobile/src/transport/rpc-client-stream-registry.test.ts:122-124) now delivers anendframe after the snapshot-triggered unsubscribe and asserts no further request, covering a host that registered on arrival. - Host test adapted to
main's version-aware sweep —src/main/runtime/rpc/methods/session-tabs-unsubscribe.test.tswiresgetSubscriptionRegistrationVersionto the realRuntimeSubscriptionRegistryand widenscleanupSubscriptionsByPrefixto(prefix, throughVersion?), matching #23045. The no-id sweep test still ends both streams because both registered before the unsubscribe, so it genuinely exercises the through-version filter rather than passing vacuously.
The host test passes locally (5 tests). The refactor is semantics-preserving and the merge integration is consistent with main; prior approvals stand.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
…tabs-direct-request-id # Conflicts: # mobile/src/transport/rpc-client-stream-registry.test.ts
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
Reviewed the delta since the prior pullfrog review (94d92e0 → 3a402f3): a merge of origin/main whose only conflict was in the registry test.
- Merge of
mainre-synced the branch — the only new commit is3a402f3, which mergesorigin/main(409462a) and resolves a conflict inmobile/src/transport/rpc-client-stream-registry.test.tsby keeping bothmain's tests (the U-03 transcript sibling, the terminal request-id test, and the browser tombstone) and this PR's new session-tabs tests.git diff 409462a 3a402f3 --statconfirms the PR diff againstmainis still exactly the same 6 files (+211/−6). - No author behavior change — the PR's production files (
rpc-client-session-tabs-stream.ts,rpc-subscription-result-shapes.ts) and the host test are unchanged from the previously approved94d92e0; the newly merged base code (terminal.unsubscribenow carryingrequestId,agentSession.unsubscribecarryingsubscriptionId) ismain's, not this PR's. - Host test still passes —
src/main/runtime/rpc/methods/session-tabs-unsubscribe.test.tsruns green at3a402f3(5 tests). Mobile vitest remains unrunnable in this checkout becausemobile/node_modulesis absent andmobile/tsconfig.jsonextends an unresolvedexpo/tsconfig.base— the same environment limitation prior runs hit, not a regression.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
|
| export function holdUnsubscribe(stream: SessionTabsStreamState): boolean { | ||
| if (!awaitsRegistration(stream)) { | ||
| return false | ||
| } | ||
| stream.cancelled = true | ||
| return true |
There was a problem hiding this comment.
Cancelled streams can linger If the host's initial tab-list request stalls while the connection stays open, disposing the stream now waits indefinitely for a snapshot. No unsubscribe is sent, so the cancelled stream remains on both the phone and the host. A bounded wait or another cleanup path would prevent abandoned streams from accumulating.
Knowledge Base Used: Remote runtime transport
…3700, #22943, #23720, #23793, #23776, #23796) into #23059 #23573 (keep a turn's bar on the prompt that opened it) is ported onto the turn-record membership instead of kept as a second owner lookup: - The running turn's bar comes from nativeChatTurnMembership, which now returns barTurnKey beside liveTurnKey. Where the host states each row's turn they are the same key: the running root turn's anchor, and a message handed over mid-turn is already scoped to that turn. Where the host states no scope, rows still group by position, so barTurnKey is the user entry the running record names (through the same anchors) while liveTurnKey keeps the positional live group, as #23573 kept row liveness on the newest prompt. - activeTurnOpenedBy, selectStructuredAgentTurnBars' openedBy and selectNativeChatActiveTurnKey are removed; the desktop list, the slot builder and both turn-status hooks read barTurnKey. - The queued-send clock (queuedUntil: a turn counts from the previous turn's end when its send waited behind it) is kept, read in the same one-pass walk over root turn records that keys timing by anchor. - Its tests are adapted to pass a journal: each runs on a host that states no scope (the original expectations), and the desktop and mobile bar tests also run on a scoped host. #23621 (a message Claude folds into its running turn no longer splits the turn) is host-only and merged as is: the translator contract carries both openTurnInLiveProviderCycle and #23059's command-turn members. Both sides grew the Claude translator past its line budget, so its result branch moves unchanged into claude-result-journaling.ts, beside claude-message-journaling.ts (the pre-commit lint refuses the merge without it). #23801's Codex child path (no error-driven end) and #23059's Codex /compact guard (a command turn ends only on turn/completed) both stand.



ELI5
When the phone stops watching a worktree's tab list, it tells the desktop "stop sending me tabs for this worktree". On a direct connection it did not say which of its watchers it meant, so the desktop stopped all of them, including a new one the same screen had just started. Now the phone names the exact watcher it is closing, the way the relay connection already does.
What Changed
session.tabs.subscribestream, itssession.tabs.unsubscribenow carriessubscriptionIdset to the id of the request that opened the stream. The desktop already registers each tab-list stream under a key that ends in that request id, and already ends exactly that key whensubscriptionIdis present. Without it, the desktop falls back to ending every tab-list stream for that worktree on the connection, by key prefix, after first looking up the worktree (an await), so a newer stream that registered in the meantime was swept too.mobile/src/transport/rpc-client-stream-registry.tsthe direct transport now passes the stream's request id to the shared unsubscribe builder, which the relay transport and the desktop's own remote-runtime client already do.Why
The request id is the one thing that identifies a single stream: the slot the desktop sweeps by (connection plus worktree) is the same for every stream a screen opens on that worktree, so any unsubscribe addressed to the slot can hit the wrong one. #23045 has since made the desktop's worktree-wide sweep spare streams registered after the unsubscribe arrived, which protects older phones; naming the request stays the exact address for current phones and does not depend on that ordering. The desktop has supported the per-request unsubscribe since v1.4.68, so this needs no new message, field, or capability, only the phone sending what the relay path already sends.
Linked Issue
Part of #22928
Visual Proof
Pending: live QA runs after the review loop
Testing
mobile/src/transport/rpc-client-stream-registry.test.ts: two tab-list streams for one worktree on the direct transport; disposing the older one sendssession.tabs.unsubscribenaming the older stream's request id and nothing else. Fails without the fix (the unsubscribe has nosubscriptionId), passes with it.Same file: a stream disposed before its first snapshot sends nothing until the snapshot arrives, then exactly one unsubscribe naming its request id; after a reconnect the hold applies again; a held stream whose subscribe fails, or that a reconnect drops, sends nothing. Each fails without the hold.
src/main/runtime/rpc/methods/session-tabs-unsubscribe.test.ts: drives two realsession.tabs.subscribestreams for one worktree on one connection through the dispatcher and the real subscription registry. An unsubscribe naming the older request ends only the older stream; an unsubscribe with no request id (what the direct connection sent before) ends both, which pins the old behavior this PR stops triggering. The first test fails if the desktop's per-request path is changed to sweep by prefix.Desktops with fix(runtime): register phone tab-list streams when the request arrives #23045 register the stream when the request arrives and still send the first snapshot, so against them the hold only delays the unsubscribe until that snapshot: it is then sent once, it ends the stream, and the desktop's closing
endfor an already released stream sends nothing more. The hold test covers that sequence.Existing direct and relay transport tests and the desktop session-tab tests pass.
I manually tested these changes locally
Automated tests added/updated, or explained why not below
AI Disclosure
Review
subscriptionIdonsession.tabs.unsubscribeand register each tab-list stream under a key ending in its request id; both arrived in the same change. Older desktops keep one stream per worktree, registered when the request arrives, and their params schema drops the unknown field, so they end that worktree's stream as before; the hold only delays that unsubscribe until the first snapshot, the same timing the relay connection already has. Old phones against new desktops are unchanged.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
Ensure no issues in: Security, Cross-platoform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance
session.tabs.subscribeAllis not opened by the phone, so it is not touched here.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)