Repository navigation
Conversation
On mobile reconnect the client re-sends terminal.subscribe, rebinding the composite `terminal:clientId` id to a newer stream and tearing down the old one. The old connection's exit-waiter (bound to its AbortSignal) then fires `cleanupSubscription(id)`, which now points at the live replacement stream — killing it and freezing the mobile terminal output. Guard every exit-waiter to its own cleanup generation: only tear down when the id still owns the cleanup it registered.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
Included review availability: Your plan includes up to 10 reviews per rolling hour; 7 remain after this review. 📝 WalkthroughWalkthroughThe change adds a public accessor for subscription cleanup callbacks. Terminal subscriptions now register named cleanup callbacks and verify callback ownership before exit-waiters, abort paths, exceptions, and setup failures perform cleanup. Mobile input-lease, legacy JSON, and binary subscriptions retain their existing teardown behavior. Regression tests verify reconnect rebinding and protection against stale cleanup. Merge Risk: 🟡 Moderate · up to The change prevents stale reconnect cleanup from closing the replacement terminal stream, but the regression test may finish before that cleanup path completes and therefore could pass without proving the live stream survives. Merge readiness remains moderate until the test waits for completion or this bounded risk is explicitly accepted. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
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.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: af5dddc5-f6b9-4fb5-bc0e-cc963369665d
📒 Files selected for processing (3)
src/main/runtime/orca-runtime.tssrc/main/runtime/rpc/methods/terminal.tssrc/main/runtime/rpc/terminal-subscribe-reconnect-exit-waiter.test.ts
Included review availability: Your plan includes up to 10 reviews per rolling hour; 9 remain after this review.
A rebind tears down the old cleanup, but a pre-reconnect setup continuation (error path or abort early-return) can still call cleanupSubscription(id), which now resolves to the live replacement stream. Route all of them through cleanupOwnIfCurrent so only the id's current owner tears down.
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 2ce434fb-b7c5-4d60-b893-89217cc57932
📒 Files selected for processing (3)
src/main/runtime/rpc/methods/terminal.tssrc/main/runtime/rpc/terminal-subscribe-buffer.test.tssrc/main/runtime/rpc/terminal-subscribe-reconnect-exit-waiter.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- src/main/runtime/rpc/methods/terminal.ts
Included review availability: Your plan includes up to 10 reviews per rolling hour; 8 remain after this review.
…test.ts Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
|
Thanks for this — your diagnosis is correct, and the serve-log evidence (two Leaving this open until #14992 actually merges, so the bug isn't left unfixed if mine stalls. Why a separate PR rather than iterating here:
Two smaller things worth knowing: One thing I'd have missed without your write-up: that the rebind is what makes the stale waiter dangerous, rather than the waiter leaking. That framing is what made the fix obvious. |
Problem
Fullscreen TUIs (nvim, opencode, claude) freeze on Orca Mobile after a reconnect. The serve log shows two
terminal.subscribestreams (streamId 1 and 2) for the same terminal, then no further live output.Root cause
On mobile reconnect, the RPC client re-sends
terminal.subscribe, rebinding the composite subscription id`${terminal}:${clientId}`to a newer stream and tearing down the old one (registerSubscriptionCleanupruns the previous cleanup before overwriting).The old connection's exit-waiter is bound to its own
AbortSignal:When the old socket finally dies (detected after the reconnect has already rebound the id), the stale exit-waiter fires
cleanupSubscription(id)— which now points at the live replacement stream — closing it. Live output stops forever: the mobile terminal is frozen.Fix
Guard every exit-waiter to its own cleanup generation. Only tear down when the subscription id still owns the cleanup that waiter registered:
OrcaRuntimeService.getSubscriptionCleanup(subscriptionId)exposes the currently-registered cleanup.terminal.subscribebranches (binary stream, legacy JSON, lease-only) captures its owncleanupand routes the exit-waiter throughcleanupOwnIfCurrent, which no-ops when the id was rebound to a newer stream.Tests
terminal-subscribe-reconnect-exit-waiter.test.tsreproduces the reconnect sequence (subscribe → reconnect rebind → old connection aborts) and asserts the live stream survives the stale waiter.Verified: 182 terminal-subscribe/multiplex/presence tests pass;
terminal.tsandorca-runtime.tstypecheck clean.