Skip to content

fix(runtime): re-attach every terminal a daemon reconnect detached - #38704

Merged
nwparker merged 3 commits into
mainfrom
fix/38433-reattach-after-daemon-loss
Nov 5, 2026
Merged

nwparker merged 3 commits into
mainfrom
fix/38433-reattach-after-daemon-loss

Conversation

@nwparker

@nwparker nwparker commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

Sometimes Orca's main process loses its link to the terminal host and then reconnects. Terminals open in the host's own window recovered by themselves. Terminals you used only from a phone, another paired desktop or orca terminal send stayed cut off: no output, and every keystroke was refused. Orca now takes back every terminal the lost link dropped.

Files Added Deleted Net
Test 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​177 $\color{#cf222e}{\Huge{\mathbf{−}}}$​1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​176
Prod 5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​117 $\color{#cf222e}{\Huge{\mathbf{−}}}$​11 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​106

What Changed

  • Before: when main lost and remade its daemon connection, the daemon dropped main's attachments, and the adapter refused input until a session was attached again. Only a pane mounted in the host window attached again. Any other session stayed silent and refused input, while terminal list still reported it as connected and writable.
  • After:
    • Every lost session is re-attached. The provider's endpoint-loss fan-out tells the runtime which sessions it lost (notePtyEndpointLoss). Main re-attaches each of them, four at a time like startup adoption, whether or not a view shows it. Background agents' records stay fresh too, not only the panes someone is watching.
    • Input waits instead of being refused. Input sent while a re-attach is in flight waits for it, for at most 10 s, instead of being refused.
    • The send is checked again after the wait. The target is resolved after the wait, and the session's lifecycle generation is checked again. Held input is refused, not written, if that terminal exited or was replaced under the same id meanwhile. A send cancelled during the wait is dropped (request_aborted).
    • A failed re-attach is retried by the next view subscribe or inventory pass, not by each keystroke.

Why

On a Windows host, main remade its daemon connection twice in one evening while the daemon kept running. A paired desktop's panes for terminals not open in the host window then went silent and refused input.

Re-attaching only the sessions some view or input needs would leave background agents' sessions detached and their records stale. So main now takes back every session the loss names, at a bounded concurrency.

Because main re-attaches every lost session itself, a write never has to work out why it was refused, and no refusal classification is needed. Either the re-attach is in flight and input waits for it, or it has finished. A refusal after that is a real one, such as an exited session, and is reported as before.

Linked Issue

Fixes #38433
Supersedes #38457

Thanks to @registered2nd for reporting this, for finding that MainDaemonAttachments kept ids after the endpoint loss, and for the first version of this fix. Their commit is kept with their authorship.

Visual Proof

N/A: this changes how main tracks daemon attachments. Nothing in the UI changes.

Testing

  • I manually tested these changes locally

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

  • Every added test fails without this change and avoids the test anti-patterns

  • terminal-subscriber-driven-daemon-attach.test.ts covers the following after an endpoint loss, against a model daemon that refuses writes to detached sessions:

    • re-attaching a session no view shows;
    • holding input during an in-flight re-attach;
    • dropping a send cancelled during the wait;
    • refusing held input once a replacement terminal took the same id;
    • leaving a failed re-attach to the next view or inventory pass;
    • redoing an earlier subscriber-driven attach;
    • a second loss during the re-attach.

    Each fails without its fix.

  • pty-write-ipc-validation.test.ts checks that the provider's loss reaches the runtime.

  • pnpm tc passes.

  • Every test file that imports a changed module passes: 4 files, 63 tests.

  • Codex review is clean. An independent Opus review found no P0 or P1 issues.

Risk

Level: Medium

This touches the input path every remote view and terminal send use. The riskiest part is input to a session whose re-attach hangs: it now waits up to 10 s, where it used to be refused at once. Sends with no pending re-attach cost one extra map lookup.

SSH sessions and sessions with a connectionId are excluded, and there is no protocol change, so mixed versions are unaffected. A plain revert backs this out.

Follow-up, not in this PR: output printed between the loss and the re-attach does not reach main's copy of the screen (main already holds the screen, so the daemon snapshot is skipped). Remote reads can show a slightly stale screen until the next output.

AI Disclosure

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

Only main's local provider changes; SSH-relayed sessions are untouched. It applies on all platforms and on headless orca serve hosts.

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)
  • I stated the risk: what could break, for whom, and how to back it out
  • 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)

registered2nd and others added 3 commits November 5, 2026 14:17
…ote views and input

When the host's main process loses and re-makes its daemon connection, the daemon drops main's
attachments and the adapter refuses input to every session until it is attached again. Only a pane
mounted in the host's own window re-attaches by itself; a session with no pane there stays silent
and refuses every keystroke from a paired desktop, a phone or `orca terminal send`, while
`terminal list` still calls it connected and writable. A client remount or restart did not help:
its new subscription never re-attached the session.

Main now notes each session the provider's endpoint loss names, re-attaches it once a remote view
shows it (at the loss or when a view subscribes later), and holds input for it until that attach
lands instead of refusing it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Nov 5, 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 56 seconds.

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

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c38755a9-1e91-4dee-a911-cd67a0654a4d
Commits

Reviewing files that changed from the base of the PR and between 3cefb66 and 10c70da.

Files selected for processing: 7

  • src/main/ipc/pty/provider/bind-listeners.ts
  • src/main/ipc/pty/pty-write-ipc-validation.test.ts
  • src/main/runtime/terminal-subscriber-driven-daemon-attach.test.ts
  • src/main/runtime/terminal/input/terminal-input-dispatch.ts
  • src/main/runtime/terminal/layout/terminal-view-presence.ts
  • src/main/runtime/terminal/lifecycle/main-daemon-attachments.ts
  • src/main/runtime/terminal/lifecycle/terminal-view-resources.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

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]: After main reconnects to the terminal daemon, terminals shown only on a phone, a paired desktop or via orca terminal send refuse input

2 participants