Skip to content

fix(terminal): paint paired remote terminals on first subscribe - #8954

Merged
brennanb2025 merged 3 commits into
stablyai:mainfrom
rodboev:pr/paint-paired-remote-terminals-on-first-subscribe
Jul 18, 2026
Merged

brennanb2025 merged 3 commits into
stablyai:mainfrom
rodboev:pr/paint-paired-remote-terminals-on-first-subscribe

Conversation

@rodboev

@rodboev rodboev commented Jul 16, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Make desktop paired remote-runtime subscribers request a renderer tab mount and wait briefly for a late PTY instead of immediately retiring the terminal with no_connected_pty.
  • Send the initial desktop fit and driver events only after the first snapshot has been delivered.
  • Keep the mobile subscribe path, already-spawned PTY behavior, and timeout behavior unchanged.

Closes #8696.

Screenshots

No visual change

Testing

  • pnpm lint
  • pnpm typecheck
  • pnpm test
  • pnpm build
  • Added or updated high-quality tests that would catch regressions, or explained why tests were not needed

Focused 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:node
  • pnpm exec oxlint src/main/runtime/rpc/methods/terminal.ts src/main/runtime/rpc/terminal-multiplex.test.ts
  • pnpm exec oxfmt --check src/main/runtime/rpc/methods/terminal.ts src/main/runtime/rpc/terminal-multiplex.test.ts

All 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 waitForLeafPtyId timeout 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.

@coderabbitai

coderabbitai Bot commented Jul 16, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Desktop 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 no_connected_pty if no PTY appears and emit initial fit-override and driver values later in the lifecycle. Clientless multiplex subscriptions retain immediate error behavior without PTY waiting or mounting. Legacy subscriptions apply the same client-metadata PTY gate, while clientless flows complete with subscribed and end.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly matches the core change: desktop paired terminals now paint on first subscribe.
Description check ✅ Passed The description includes all required sections and gives a detailed, relevant summary, testing, review, security, and notes.
Linked Issues check ✅ Passed The changes address #8696 by mounting and waiting for late PTYs on desktop, while preserving mobile and timeout behavior.
Out of Scope Changes check ✅ Passed The diff stays focused on terminal subscription behavior and regression tests, with no obvious unrelated code changes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 win

Add requestRendererTerminalTabMount() before awaiting waitForLeafPtyId().
waitForLeafPtyId() only waits; the legacy terminal.subscribe path mounts never-mounted tabs first so their PTY can attach. Without that mount here, terminal.multiplex can still fall through to no_connected_pty for 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/driverListener invocation inside the readTerminal mock is a no-op given the new emission order.

Since the implementation now installs subscribeToFitOverrideChanges/subscribeToDriverChanges only after readTerminal/snapshot completes (Lines 2231-2252 in terminal.ts), fitListener and driverListener are still undefined when this mock's readTerminal runs, so the fitListener?.(...) / driverListener?.(...) calls silently do nothing. The test still passes and correctly validates ordering via the trace array, 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.ts
  • src/main/runtime/rpc/terminal-multiplex.test.ts

@rodboev
rodboev force-pushed the pr/paint-paired-remote-terminals-on-first-subscribe branch from 71783fc to a787aad Compare July 16, 2026 04:49
@AmethystLiang
AmethystLiang requested a review from Jinwoo-H July 16, 2026 17:17
@brennanb2025
brennanb2025 requested review from brennanb2025 and removed request for Jinwoo-H July 17, 2026 23:10
@brennanb2025

Copy link
Copy Markdown
Contributor

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.
@brennanb2025

Copy link
Copy Markdown
Contributor

Thanks @rodboev — reviewed this closely and it lands at the right layer.

  • Mount + wait for the late PTY has to be host-side: a paired client can't bootstrap a host PTY itself, so widening the gate from mobile-only to any client is exactly right for the SSH-backed / never-mounted cases that used to hit no_connected_pty and never paint.
  • The fit/driver reorder pins down the "paints only after a resize" symptom: the renderer parks xterm at the override dims and skips the real DOM-measured fit when a fit-override arrives before the first snapshot. Emitting it after the snapshot makes that first event indistinguishable from a steady-state one the renderer already handles — and mobile never sends these events, so it's untouched.

I pushed one small follow-up commit: a regression test for the desktop terminal.subscribe gate. The multiplex path was covered, but reverting the legacy gate back to isMobile still left the suite green.

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.
@brennanb2025

Copy link
Copy Markdown
Contributor

Follow-up reliability/performance review found and fixed one meaningful widened-wait regression in 7647f9a42.

  • Invariant (terminal-runtime.remote-multiplex-subscription-ownership): once a multiplex slot unsubscribes, a late PTY may not create snapshot work, live-output listeners, or a remote-view registration for that slot.
  • Failure source: desktop subscribers can close during the new bounded late-PTY wait; before this fix no slot handler existed yet, so Unsubscribe was dropped and the late PTY resurrected a ghost stream.
  • Oracle: the new deterministic test is red on the prior head and green now. It requires immediate wait abort plus zero readTerminal, subscribeToTerminalData, and registerRemoteTerminalViewSubscriber calls.
  • Gate: terminal-runtime.mobile-stream-budget passed 48/48 tests. Broader remote transport/lifecycle coverage passed 119/119, and fit/driver/mount coverage passed 63/63.
  • Performance budget: no polling, subprocess, inventory scan, or output-hot-path work was added. One abort listener is shared by the multiplex connection; per-slot controllers exist only during missing-PTY waits and are removed on settle, Unsubscribe, connection abort, or teardown.
  • Provider/platform coverage: shared host TypeScript covers local, SSH/remote, daemon, WSL, macOS, Linux, and Windows without platform-specific assumptions; mobile behavior remains covered and unchanged after PTY attachment.
  • Diagnostics/residual gap: the deterministic slot counts make this leak diagnosable. A live two-desktop paired-runtime visual first-paint run is still unavailable, so reporter confirmation remains the residual gap.

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
src/main/runtime/rpc/terminal-multiplex.test.ts (1)

3046-3051: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Assert that the scrollback fallback is exercised.

The test still passes if readTerminal is 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

📥 Commits

Reviewing files that changed from the base of the PR and between a787aad and 7647f9a.

📒 Files selected for processing (2)
  • src/main/runtime/rpc/methods/terminal.ts
  • src/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

@brennanb2025
brennanb2025 merged commit 72a5c6f into stablyai:main Jul 18, 2026
1 check passed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Remote runtime desktop client doesn't render terminals (workspaces sync fine; mobile client works)

3 participants