Repository navigation
fix(runtime): register phone terminal subscriptions when the request arrives - #22948
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 (2)
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review. 📝 WalkthroughWalkthroughTerminal subscriptions are now registered before PTY waits. A shared registration manages request cancellation, PTY-exit release, teardown, and mobile presence. The legacy lease, JSON, and binary runners use this registration for lifecycle handling. New and updated tests cover registration cleanup, pending waits, aborts, replacement, and failure cases. Priority: ➖ Normal Severity of issue fixed: Medium Merge Risk: ⚪ Minimal · up to The examined cancellation and phone-presence paths do not leave a stale subscription or phone control. No identified issue blocks merging after normal checks. Security Architecture ReviewSecurity architecture risk: 🔵 Low · up to The new lifecycle appears to close the gap where a phone could leave while its terminal was starting yet remain in control afterward. No new terminal access path or weakened control was identified. Some surrounding authorization and failure behavior remains outside the reviewed source. 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 — this run reviewed the complete diff (13 files, one commit 018ce01) against main.
- Admission-time registration — every
terminal.subscribenow enters the host subscription registry before the PTY wait, through a newTerminalSubscriptionRegistrationobject that owns teardown, phone presence, the PTY-exit observer, and the request-abort listener. - Handler re-checks —
terminal-subscribe-method.tsre-checksregistration.releasedafter each await, routesregistration.signalinto the PTY wait and the runners, suppresses an error frame once something already ended the stream, and releases infinally. - Runners refactored — the legacy lease, JSON, and binary runners move to
setTeardown/addMobilePresence; phone-presence teardown is centralized in the registration, so the binary teardown no longer unsubscribes mobile. - Deliberate behavior changes — the mobile
binary_terminal_stream_requiredcheck now runs before admission, and a request released while pending receives exactly oneend.
I traced the two riskiest properties directly and with two independent falsification passes: (1) no interleaving of replacement cleanup, request abort, PTY exit, connection cleanup, or runner error produces two end frames or an error-after-end (the released/ended latches plus the registry wrapper's finally { end() } cover it; the only no-end release is the intentional releaseSilently + rethrow); (2) no reachable path leaves the driver mobile after release, because the subscriber record is inserted synchronously before the first enqueueLayout await and replacement cleanup runs before the new registration records presence. The terminal.unsubscribe version fence is unaffected by the earlier registration bump. The added tests pin exact frame sequences and real-runtime driver state, so they can genuinely fail on the pre-fix behavior.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes — incremental delta since the prior pullfrog review (018ce01 → 70222ed, one commit, two files).
- Already-aborted requests skip the slot —
terminal-subscription-registration.tsnow setsregistryEntry = nullwhenrequestSignal?.aborted, so it never callsregisterOwnedSubscriptionCleanup(which would evict a live stream under the same key) and instead callsreleaseOnce()directly. - No
endon arrival — the pre-aborted registration releases without emittingend, matching the handler's existing early return for an aborted signal. releasemade optional —release()is nowregistryEntry?.releaseIfCurrent(), a no-op in the pre-aborted path wherereleaseOnce()already ran.- Regression test strengthened — the unit test now seeds a live entry in a shared registry and asserts it survives (and can still be cleaned up), which fails on the parent commit where
registerevicts it.
I traced the new branch: with registryEntry === null, releaseOnce() flips the released latch, aborts the controller, and leaves teardown/presence untouched, so a later setTeardown still runs immediately and addMobilePresence/releaseOnPtyExit stay inert. Ran the unit file locally: 7/7 pass.
One observation, no action needed: the new guard is not reachable through its only caller — terminal-subscribe-method.ts:28 already returns for signal?.aborted before registration, with no await between that check and the call. So this commit hardens the object's exported contract rather than changing production behavior (the tests exercise it directly). Keeping it as defense-in-depth is reasonable.
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 with two independent reviewers each. Both rounds came back nits-only. One fix was pushed during review (70222ed): a subscribe that arrived after its connection had already closed could end the live stream for the same terminal before releasing itself. It is now released on arrival without taking that stream's place. The full runtime RPC suite passes on this branch and on its base. Testing. The fix is proven by a deterministic test on the real runtime service: a phone subscribe that is still waiting for its terminal, followed by an unsubscribe, leaves the desktop driver idle. On main it stays Desktop after the phone left (typed Stacked follow-up: #23006 (unsubscribe by request id), then #23058. |



ELI5
When you open a terminal on your phone, the desktop sometimes has to wait a moment for that terminal to start. If you left the terminal during that wait, the desktop never heard that you left. Once the terminal started, the desktop acted as if the phone was still in control: it showed the "phone in control" banner and ignored your desktop typing until you pressed Take back. Now the desktop writes the phone's request down the moment it arrives, so leaving during the wait cancels it.
What Changed
Before: a phone's terminal stream was only written into the host's list of open streams after the terminal's process was ready, which can take up to 10 seconds for a tab that has not started yet. A "stop streaming" message that arrived during that wait found nothing to stop. When the process came up, the stream started anyway: the desktop switched to phone control (banner shown, desktop keystrokes and terminal query replies dropped), output streamed to a phone that was no longer listening, and the automatic size restore never ran. It stayed that way until the phone disconnected, re-opened the same terminal, the process exited, or the user pressed Take back. The same gap caused a second bug after a host restart: the phone replays its streams, then closes and re-opens one, and the stale replayed request could start late and knock out the fresh one.
After: every
terminal.subscribeis entered in the host's stream list before it waits for anything, under the same key as before (terminal plus phone id). A stop message or a newer request for the same terminal from the same phone can now end a request that is still waiting, alongside a closed connection or a desktop IPC abort, which already cancelled the wait. When it ends, it sends oneend, and its late process never starts the stream.The mechanism is a new registration object (
terminal-subscription-registration.ts) that owns everything the stream has to undo, so every way of ending it goes through one idempotent release:finally, then aborts the registration's signal in an outerfinally. A failing teardown can therefore neither leave the phone in control nor leave the pty wait running.endis never followed by an error. If it fails before that, the stream is released without anendand the error is reported as before.subscribedwith no stream id) followed by exactly oneend.One deliberate behavior change: the "binary stream required" check for phones now runs before the request is entered, so a request that can never stream cannot knock out a live stream for the same terminal. As a result, a phone build that predates binary terminal streaming, opening a terminal whose process never started, now gets the
binary_terminal_stream_requirederror instead of a scrollback preview andend. Those builds already got that error for every running terminal, so they cannot use terminal streaming either way.Why
The bug happens because a waiting request is not addressable: nothing about it is recorded until setup finishes. Entering it at admission removes the window instead of guarding it. The existing "one live stream per terminal per phone" replacement rule and the #22505 ordering check apply to waiting requests unchanged.
Alternatives considered:
This change is host-only and changes nothing on the wire, so every phone version gets the fix. A follow-up can let newer phones stop a stream by the request that created it rather than by terminal key; the registration introduced here is the thing that follow-up will address.
Linked Issue
Fixes #22928
Visual Proof
Pending: live QA runs after the review loop
Testing
New dispatcher-level tests (
src/main/runtime/rpc/terminal-subscribe-admission.test.ts), using a pty wait that honors its abort signal the way the runtime does:end. The same flow on the real runtime service (only handle lookup, the pty wait, the scrollback read, tab mounting and the pty controller are doubled) leaves the desktop driver idle and no phone-fit size override. Both fail on main: the first leaves the stream entered, the second leaves the drivermobile.endand never subscribes the phone. Fails on main: the phone subscribe runs twice.enddiffers there; it fails if the abort listener is not installed at admission.endis sent, no error. Fails on main, which sendsendand then an error.end, and phone presence removed.end; the desktop IPC signal is released and its listener removed.Unit tests for the registration object (
terminal-subscription-registration.test.ts): teardown runs once when it re-enters release, a teardown set after release runs immediately, an already-aborted request is released without taking the stream's slot, a throwing teardown still removes presence and aborts, no presence is added after release, silent release, and process-exit release.Updated tests: the shared terminal test stubs now provide the stream registry, because every request now registers; one ownership test now asserts that the abort listener is removed instead of never added; a desktop pty wait now receives the registration's signal; and a request aborted while waiting now ends with
end.Checks run locally:
pnpm tc:node,oxlinton the changed files,pnpm run check:code-quality:changed, the terminal RPC test files (56 files, 360 tests), andsrc/main/runtime/orca-runtime.test.ts(1307 tests).AI Disclosure
Review
live/unverifiable/exitedverdicts.end; a stream that was ended and then fails setup gets onlyend, no error; and a phone build predating binary streaming gets an error instead of a preview for a terminal whose process never started. Current phones already drop anendfor a stream they stopped. Because the request is entered on arrival, a newer request for the same terminal from the same phone now ends the older stream when it arrives rather than once its process is ready, and a request with no phone id (keyed by terminal alone) does the same for a terminal whose process never started.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 registration records the connection id, because the stream list already uses it to clean up when a connection closes. It does not record the request id yet: nothing in this change would read it, and the follow-up that lets phones stop a stream by request id adds it along with its lookup.
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)