Skip to content

fix(runtime): stop a remote-typed terminal hidden on the host from reconnecting on every send - #29252

Merged
nwparker merged 1 commit into
mainfrom
nwparker/hidden-host-pane-send-reconnect
Oct 15, 2026
Merged

nwparker merged 1 commit into
mainfrom
nwparker/hidden-host-pane-send-reconnect

Conversation

@nwparker

@nwparker nwparker commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​169 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​169
Prod 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​18 $\color{#cf222e}{\Huge{\mathbf{−}}}$​1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​17

ELI5

If you typed from a paired client into a terminal that wasn't the tab showing on the host, every send flashed "Reconnecting", blanked the pane and repainted it. Typing into that terminal now just works, whether or not the host is showing it.

What Changed

Before: each send to a terminal hidden on the host was refused. The client then rebuilt the pane (reconnect banner, blank, repaint), and the host's daemon.log logged one session-attached for that pane. Showing the pane on the host (orca terminal switch) made it stop.

After: sends are accepted, and the pane stays put.

Mechanism. Terminal handles are minted per pane slot. When the host remounts a hidden pane (from cold parking or a paired client's reconnect), the pane's slot briefly reports no PTY until its transport reattaches the same session. Main read that gap as "this slot lost its PTY", dropped the handle, and minted a new one once the PTY came back. The client's open stream still carried the old handle, so its next send came back terminal_handle_stale. The client treats that as "this pane can't take input" and rebuilds the pane. The rebuild asks the host to mount the pane again, which mints yet another handle, so the next send is refused too. A pane that is visible on the host never remounts, which is why it never did this.

syncWindowGraph (src/main/runtime/session-graph/session-window-graph.ts) now keeps the slot's PTY through that gap when all three hold:

  • the host's PTY controller still knows the PTY is live,
  • the PTY has not been certified exited,
  • the same graph doesn't bind that PTY to another slot.

Main already did this during a renderer reload. The handle stays the same and input keeps reaching the PTY in the meantime. A PTY that is gone, or that has moved to another slot, is still dropped as before.

Why

The execution host owns which PTY a handle names. A pane remounting onto the session it already had is not a new terminal, so main should not re-mint its identity. I considered two other fixes:

  • Re-route stream input to the stream's bound PTY when the handle goes stale. That only patches multiplex input. Viewport claims, terminal.send, CLI handles and the session inventory would still see the handle churn, and the inventory change alone makes clients resubscribe.
  • Make the host renderer publish the saved PTY id while its transport attaches. The renderer can't prove the PTY is still live. Main can, through the controller.

There is no wire change. The fix lands on the host, which is the side that has to be updated.

Linked Issue

Fixes #23759

Visual Proof

N/A. This changes how the host tracks terminal identity in main, with no UI change. The user-visible effect (no reconnect or repaint on send) needs two paired machines, so it is covered by the stream-level test below.

Testing

  • New src/main/runtime/host-pane-remount-terminal-handle.test.ts:

    • A paired client subscribes over terminal.multiplex. The host pane then remounts (leaf PTY goes to null, then back), and the client sends input. The test asserts the handle is unchanged, the write reaches the PTY, and no WriteUnavailable frame is sent.
    • Input sent during the gap is accepted.
    • A PTY the controller no longer has is still dropped as stale.
    • A PTY the same graph rebinds to another leaf is not duplicated.
    • The first two tests fail on main (terminal_handle_stale). All four pass with the fix.
  • pnpm test passes on the new test plus the related handle incarnation, cold-park remote subscriber, orphan and reattach suites.

  • pnpm tc:node and pnpm tc:web pass. pnpm run check:code-quality:changed passes.

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

AI Disclosure

Claude Opus 5.5; reviewed with Codex (gpt-6.1-sol, high).

Review

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

  • SSH: a PTY whose provider can't confirm it is live (it answers unknown) is not held, so behavior there is unchanged.
  • Cross-platform: the change is in platform-neutral main code.
  • Compatibility: no protocol change. Mixed client and host versions are unaffected.
  • Performance: one Set per graph sync.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

…ne remounts

A pane hidden on the host remounts onto the same live PTY, and for a moment its graph leaf has no PTY. Main dropped the handle then and minted a new one, so the paired client's next send was refused as stale and the client remounted the pane, which made the host remount it again. Main now holds the live PTY on the leaf through that gap.

Fixes #23759
@coderabbitai

coderabbitai Bot commented Oct 15, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 7 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 10 included reviews currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: b6b2363c-87cf-4527-a5e9-66c71c07fd3c
📥 Commits

Reviewing files that changed from the base of the PR and between 0fea878 and 796d983.

📒 Files selected for processing: 2
  • src/main/runtime/host-pane-remount-terminal-handle.test.ts
  • src/main/runtime/session-graph/session-window-graph.ts

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.

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-watched pane reconnects on every send when it is hidden on the host (#11189 follow-up)

1 participant