Repository navigation
fix(terminal): paint paired remote terminals on first subscribe - #8954
brennanb2025 merged 3 commits into
Conversation
📝 WalkthroughWalkthroughDesktop multiplex subscriptions now wait for a PTY when client metadata is provided, request renderer mounting, and cancel pending waits during unsubscribe or socket closure. They report 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 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.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/main/runtime/rpc/methods/terminal.ts (1)
2028-2038: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick winAdd
requestRendererTerminalTabMount()before awaitingwaitForLeafPtyId().
waitForLeafPtyId()only waits; the legacyterminal.subscribepath mounts never-mounted tabs first so their PTY can attach. Without that mount here,terminal.multiplexcan still fall through tono_connected_ptyfor tabs that have never been mounted.
🧹 Nitpick comments (1)
src/main/runtime/rpc/terminal-multiplex.test.ts (1)
2838-2844: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value
fitListener/driverListenerinvocation inside thereadTerminalmock is a no-op given the new emission order.Since the implementation now installs
subscribeToFitOverrideChanges/subscribeToDriverChangesonly afterreadTerminal/snapshot completes (Lines 2231-2252 interminal.ts),fitListeneranddriverListenerare stillundefinedwhen this mock'sreadTerminalruns, so thefitListener?.(...)/driverListener?.(...)calls silently do nothing. The test still passes and correctly validates ordering via thetracearray, but these calls don't exercise the scenario they appear to simulate (an event firing before subscription). Consider removing them or clarifying intent, since as written they add noise without additional coverage.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: fcfae7c7-1250-4e15-bbdf-74d53f43c1f9
📥 Commits
Reviewing files that changed from the base of the PR and between 69c14fa and 71783fc89c9403d6eb3da23cf7b4debd5f400aff.
📒 Files selected for processing (2)
src/main/runtime/rpc/methods/terminal.tssrc/main/runtime/rpc/terminal-multiplex.test.ts
71783fc to
a787aad
Compare
|
Taking a look! |
The widened terminal.subscribe gate (isMobile -> params.client) had no regression test: reverting it to the mobile-only gate left the suite green. Add a desktop legacy-subscriber case asserting the mount request and late-PTY wait fire before the scrollback-only fallback.
|
Thanks @rodboev — reviewed this closely and it lands at the right layer.
I pushed one small follow-up commit: a regression test for the desktop Verified locally: 33/33 focused tests, oxlint + oxfmt clean, and a perf pass came back clean (the new wait is gated to never-mounted tabs, event-driven, cancellable, and concurrent across tabs — no stampede). LGTM. |
Desktop subscribers can close while the new late-PTY wait is pending. Register provisional slot cancellation and abort all pending waits on unsubscribe, connection abort, or multiplex teardown so a late PTY cannot resurrect a ghost output stream.
|
Follow-up reliability/performance review found and fixed one meaningful widened-wait regression in
Validation: full typecheck, full lint and reliability-manifest checks, production desktop/web/native build, focused formatting, and all targeted terminal suites passed. A repository-wide run on unsupported Node 26 passed 30,585 tests; its 35 unrelated environment-sensitive failures were localStorage setup, inherited Git environment, and one WSL relay timeout. |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/main/runtime/rpc/terminal-multiplex.test.ts (1)
3046-3051: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAssert that the scrollback fallback is exercised.
The test still passes if
readTerminalis removed. Assert the mocked fallback is called so the behavior named by this regression test remains covered.Proposed assertion
expect(runtime.requestRendererTerminalTabMount).toHaveBeenCalledWith('terminal-1') expect(runtime.waitForLeafPtyId).toHaveBeenCalledWith('terminal-1', 10_000, undefined) + expect(runtime.readTerminal).toHaveBeenCalled() expect(messages.map((msg) => JSON.parse(msg).result?.type)).toEqual(['subscribed', 'end'])
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 13819791-4d3f-439c-a7e2-8d1f42857b8e
📒 Files selected for processing (2)
src/main/runtime/rpc/methods/terminal.tssrc/main/runtime/rpc/terminal-multiplex.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- src/main/runtime/rpc/methods/terminal.ts
…lyai#8954) * fix(terminal): paint paired remote terminals on first subscribe * test(terminal): cover desktop legacy subscriber PTY wait The widened terminal.subscribe gate (isMobile -> params.client) had no regression test: reverting it to the mobile-only gate left the suite green. Add a desktop legacy-subscriber case asserting the mount request and late-PTY wait fire before the scrollback-only fallback. * fix(terminal): cancel abandoned multiplex PTY waits Desktop subscribers can close while the new late-PTY wait is pending. Register provisional slot cancellation and abort all pending waits on unsubscribe, connection abort, or multiplex teardown so a late PTY cannot resurrect a ghost output stream. --------- Co-authored-by: Brennan Benson <[email protected]>
Summary
no_connected_pty.Closes #8696.
Screenshots
No visual change
Testing
pnpm lintpnpm typecheckpnpm testpnpm buildFocused validation to record from the implementation worktree:
pnpm exec vitest run --config config/vitest.config.ts src/main/runtime/rpc/terminal-multiplex.test.ts -t "waits for a desktop multiplex subscriber's PTY before retiring the terminal|still reports no_connected_pty when a desktop multiplex subscriber's PTY never appears|emits initial desktop fit events after the first multiplex snapshot|does not wait when a desktop multiplex subscriber already has a PTY"pnpm run typecheck:nodepnpm exec oxlint src/main/runtime/rpc/methods/terminal.ts src/main/runtime/rpc/terminal-multiplex.test.tspnpm exec oxfmt --check src/main/runtime/rpc/methods/terminal.ts src/main/runtime/rpc/terminal-multiplex.test.tsAll four focused Vitest cases passed, along with two clientless compatibility cases, node typecheck, oxlint, and oxfmt checks. The late-PTY case is supplemental state-matrix coverage, not a reproduction of the issue's connected-PTY report. The connected-PTY ordering case includes desktop capabilities and callbacks during the snapshot read await; base failed its ordering assertion and head passed. Clientless multiplex and legacy subscriptions preserve their prior no-wait behavior. No headed Orca E2E was run. The paired desktop visual first-paint check remains unverified because a real paired remote-runtime session was not available.
Cross-platform review: this stays in shared host-side TypeScript subscribe logic. The rework adds one renderer-tab mount request before the existing PTY wait and proves the unchanged clientless/mobile paths in focused tests. No macOS, Linux, or Windows-specific branches, shortcuts, shell paths, labels, or Electron platform conditionals were changed.
AI Review Report
The diff stays in the host-side terminal subscribe owner and its focused test file. Review should focus on PTY wait ownership, initial snapshot ordering, timeout preservation, and already-spawned PTY preservation. No renderer diff, mobile diff, dependency change, or release surface change is planned.
Security Audit
The change adds no new network surface, subprocess, dependency, credential flow, or path handling. It reuses the existing
waitForLeafPtyIdtimeout and the existing subscribe protocol, and only changes host-side ordering and gating.Notes
The end-to-end paired desktop first-paint experience was not verified visually. Local coverage is host-side behavioral testing for renderer-backed mount-before-wait, PTY wait, and snapshot ordering. Reporter or maintainer confirmation on a real paired remote-runtime setup is still needed for the visible first-paint claim.