Skip to content

fix(remote-runtime): a paired terminal accepts input again after its host app relaunches - #25736

Merged
Jinwoo-H merged 8 commits into
mainfrom
remote-terminal-reconnect-fix
Oct 6, 2026
Merged

Jinwoo-H merged 8 commits into
mainfrom
remote-terminal-reconnect-fix

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 12 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1016 $\color{#cf222e}{\Huge{\mathbf{−}}}$​27 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​989
Prod 12 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​115 $\color{#cf222e}{\Huge{\mathbf{−}}}$​35 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​80

ELI5

When the Orca app on a paired host machine is quit and reopened, the terminals keep running in the background. A client connected to that host showed "Reconnecting…", the message went away, and then typing into the terminal did nothing. Now the client waits for the host to finish starting and reconnects the same terminal, so typing works again.

What Changed

Before: a reopened host starts answering requests before its window has reported its tabs. In that gap it answers "what tabs exist?" with a placeholder: an empty list marked "not published yet". The client already knew how to read that marker, but only the bare form. A paired client receives the placeholder through its per-client view, where the marker is renamed (none becomes none:client-navigation). So the client took the empty list to mean the terminal was closed and shut the pane down for good. The overlay cleared and input went nowhere.

After:

  • One rule for "the host hasn't answered yet" (hostSnapshotAffirmsWorktreeContents): the placeholder marker counts as "no answer" in both its bare and per-client forms. The per-client suffix is now a shared constant used by both host and client. Every client reader of this rule benefits, not just terminals.
  • Reconnect keeps asking instead of retiring when the host's tab list is that placeholder. A real, published list that lacks the terminal still closes it, as before.
  • Placeholder updates pushed by the host are ignored where they enter, instead of being read as "terminal gone".
  • The host only says "not ready yet" while it really is starting. Before this PR, the host also sent the placeholder for any worktree it had no tabs for, including one its window had never opened, long after it finished starting. Now the placeholder is sent only until the host's window first publishes its tabs. After that, a worktree with no tabs gets a real empty answer. A client that was told "ask me later" during startup is sent that answer once, as soon as the host publishes. So a paired client opening a never-opened host worktree still gets its first terminal automatically, while a host that is merely still starting never triggers one.
  • The host's first real update reconnects the pane. When the bounded reconnect wait runs out with no answer, the client parks a retry. A published update showing the terminal now fires that retry right away, instead of waiting out the ~3-minute recovery deadline. retryNow() can now fire a retry parked while recovery is still running (nothing is in flight at that point), so going back online or waking the machine can fire it too.

Why

The host already labels the frame as unpublished; the client was misreading one spelling of the label. Fixing it on the client also covers older hosts, which send exactly this frame. The host change makes the placeholder honest: it now means only "still starting". Older clients read the new empty answer correctly, since it is just an ordinary empty list. Against an older host, a new client doesn't automatically create a first terminal in a worktree that host never opened, because it can't tell that apart from a host still starting. The user can still create one, and holding back an automatic action is the safe direction when versions differ. The alternative was to make the host hold back its tab list until its window publishes. That would slow every caller of that request (mobile, CLI), could hang if the window never publishes, and changes what the host publishes to every client. Firing the existing parked retry reuses the normal reconnect path, rather than adding a separate reattach state. Older clients keep the bug until they update, which is acceptable.

Linked Issue

N/A (internal report).

Visual Proof

N/A. This changes reconnect behavior with no UI change. The e2e checks the rendered pane: the overlay clears, typed text reaches the host terminal, and the echo appears.

Testing

  • e2e repro, tests/e2e/paired-remote-terminal-host-quit-reconnect-input.spec.ts: a real host and a paired client run on isolated profiles. The host app quits and reopens while its background terminal process survives. The reopened host is held before it publishes its tabs, then the test types through the pane.

    • macOS: red before the fix (recovery: ended); 3/3 green after.
    • Windows (real Windows machine): red before the fix, with the same recovery: ended symptom as the field; 3/3 green after. The spec now launches its fixture through PowerShell's & call operator so it can run on Windows.
    • Before releasing the hold, the spec checks that the host still answers with the "not published yet" placeholder. A hold that installs too late fails the test instead of passing silently against unfixed code. The base commit still fails with this check in place, on both macOS and Windows.
  • e2e first terminal, tests/e2e/paired-client-first-terminal-unopened-host-worktree.spec.ts: a paired client adds a repo through the host, so the host's window never opens it, then opens it on the client and expects a first terminal. It passes before this PR, failed partway through it (the regression this commit fixes), and passes now.

  • Host unit tests (session-tabs-empty-worktree-publication.test.ts): the placeholder is sent only before publication; afterwards the answer is a real empty list; a client that asked during startup is told once on publication; nothing extra is sent when the publication already includes the worktree.

  • Unit tests (remote-runtime-pty-transport-unpublished-host-graph.test.ts, web-session-tabs-sync-terminal-bootstrap.test.ts):

    • a placeholder from the inventory or a pushed update keeps the pane;
    • the first published update reattaches it;
    • a published list that lacks the surface still retires it;
    • a handle the host marked stale is not reattached just because the host republishes it, and its parked retry survives, so coming back online still starts a fresh attempt.
  • Existing suites: all transport, recovery-state, and session-snapshot suites pass, plus pnpm tc and the changed-code gate. Two tests that pinned "a placeholder with a nonzero version counts as an answer" were removed: no host has ever sent that.

  • SSH: unaffected, since this path is the paired remote runtime. The change follows the execution-boundary rule that absence is never evidence a process exited.

  • I manually tested these changes locally

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

Review

An independent review pushed for the simplest design: a single epoch rule, dropping placeholder frames where they enter, and firing the parked retry instead of reading phase, epoch, and policy state in the listener. All of it is applied.

Agent skill upstream boundary

  • Not applicable, or this change follows docs/reference/agent-skill-sharing-upstream-boundary.md and copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Ensure no issues in: Security, Cross-platoform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance

  • No new fields or messages. A new client against an old host gets the reconnect fix; the one difference is the automatic first terminal, described in Why. An old client against a new host reads the new empty answer as the ordinary empty list it is.
  • No new timers or polling. The reattach is driven by the host's own update.

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)

A relaunched desktop host accepts RPC before its renderer publishes a window
graph. During that gap session.tabs.list answers with an unpublished empty
graph (publicationEpoch "none", snapshotVersion 0, tabs []). The client's
reconnect inventory treats that as removal and retires the pane
(retireRemoteTerminalId(-1)): the pane goes to "ended", the reconnect overlay
disappears, and keystrokes never reach the surviving daemon PTY.

Both tests are red on main by design; they are the repro for the fix.

- e2e: holds the relaunched host's runtime:syncWindowGraph so the client's
  reconnect deterministically meets the unpublished host (4/4 red).
- unit: transport-level repro of the same retirement (red in ~2s).
- restart helper gains a beforeFirstWindow hook; LaunchOptions moves to its
  own module to stay under the max-lines budget.
After the host app quit and relaunched (daemon still running), a paired
client's terminal cleared its reconnect overlay and then ignored all input.
The relaunched host answers session.tabs.list before its renderer publishes,
with a synthesized empty frame. A paired client sees that frame through its
navigation projection as epoch "none:client-navigation", which the shared
"does this frame answer for the worktree" check did not recognise, so the
pane read it as removal and retired itself.

- hostSnapshotAffirmsWorktreeContents treats the client-projected placeholder
  as no answer at any version (the projection adds its navigation revision).
- The reconnect inventory keeps polling on such a frame instead of retiring;
  a published frame lacking the surface still retires the pane.
- Pushed frames that affirm nothing no longer report the surface absent.
- When the bounded inventory wait ends without evidence, the first published
  snapshot carrying the same handle now reattaches the pane, rather than
  waiting out the ~3 minute auto-recovery deadline.

Client-only: the host already labels the frame, old hosts send the same
frame, and the wire is unchanged. The e2e helper drops its type assertions.
- One epoch rule: the placeholder epoch, bare or with the shared
  client-navigation suffix, is no answer. Hosts only ever send it at
  version 0, so the version check is dropped.
- Unpublished frames are dropped where pushed snapshots enter, instead of
  a nullable per-subscriber update.
- A published same-handle snapshot fires the parked retry through
  retryNow(), which now also fires a retry parked while still
  'recovering' (nothing is in flight then). This replaces state-reading
  wiring in the listener and lets online/resume fire it too.
- The Windows e2e runs the fixture through PowerShell's call operator.
@coderabbitai

coderabbitai Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 00830ac3-01c7-4857-89ab-12941ae920fb
📥 Commits

Reviewing files that changed from the base of the PR and between 35e8002 and b6581b3.

📒 Files selected for processing (7)
  • config/reliability-gates.jsonc
  • src/main/runtime/orca-runtime-runtime-id.ts
  • src/main/runtime/orca-runtime-schedule-mobile-session-tabs-changed.ts
  • src/main/runtime/session-tabs-empty-worktree-publication.test.ts
  • src/renderer/src/components/terminal-pane/remote-runtime-pty-transport.ts
  • src/renderer/src/runtime/web-session-tabs-sync-terminal-bootstrap.test.ts
  • tests/e2e/paired-client-first-terminal-unopened-host-worktree.spec.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review.


📝 Walkthrough

Walkthrough

Snapshot authority now treats unpublished host-graph epochs, including client-navigation projections, as non-authoritative. Remote PTY recovery keeps polling when an unpublished graph omits a terminal surface and retries eligible same-handle updates. Empty-worktree responses use authoritative publication epochs after graph publication. New unit and end-to-end tests cover delayed graph publication, terminal reattachment, and input after reconnect.

Priority: ➖ Normal

Merge Risk: ⚪ Minimal · up to b6581

No concrete issue remains that would prevent merging after normal checks.

Security Architecture Review

Security architecture risk: 🔵 Low · up to b6581

The reconnection change preserves the distinction between a host still starting and a terminal actually being removed. One limited availability concern remains: pending publication notifications can outlive their requesting connection when startup stalls.

Retained concerns

  • Low · security · inferred: The new publication callback retains each distinct placeholder-returning worktree ID until graph publication, independently of the requesting connection. During stalled publication, repeated requests can accumulate runtime-owned callbacks and IDs that survive request completion or disconnection, creating a potential host-wide availability impact. Repeated requests for the same ID are coalesced and successful publication drains the callbacks; actual exhaustion and external quota protection were not established.
Security review details

Security Blast Radius

  • inferred — The retained-state concern targets one host runtime's memory and publication work, potentially affecting clients sharing that runtime. The inspected path does not establish cross-host data disclosure, credential access, or privilege escalation.

Security Findings and Attack Paths

  • inferred — A paired caller issuing requests for distinct IDs that return unpublished placeholders can leave callbacks behind after the requests finish. If authoritative publication remains unavailable, retained state grows with those distinct IDs. This is a newly introduced retention mechanism; practical exhaustion and protection by external quotas remain unverified.

Trust Boundaries and Controls

  • observed — The inspected WebSocket transport rejects missing or invalid device tokens and mismatches with the authenticated channel identity. It supplies the validated device identity to RPC handlers and applies a method allowlist for mobile-scoped devices. The publication callback still uses each listener's client-navigation projection.

Resilience and Maintainability Implications

  • observed — Same-worktree requests share one pending callback, and publication removes both callback and worktree marker before delivery. These controls contain normal execution, but differ from the existing inventory waiter, which also removes its callback on AbortSignal cancellation.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 22.58% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 31 functions across 23 files. (1 skipped:… Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the primary fix: restoring input to a paired terminal after the host app relaunches.
Description check ✅ Passed The description covers the required change, user impact, rationale, testing, visual-proof exception, compatibility considerations, and checklist. The internal-report issue reference and omitted AI dis…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 22.58% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 31 functions across 23 files. (1 skipped: 1 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
  • Autopilot · 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

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

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

ℹ️ No critical issues — one test-integrity suggestion inline.

Reviewed changes

  • Placeholder epoch recognized in both forms (host-session-snapshot-authority.ts, shared CLIENT_NAVIGATION_PUBLICATION_EPOCH_SUFFIX): hostSnapshotAffirmsWorktreeContents now keys only on the epoch, so a paired client's none:client-navigation projection — which carries a nonzero snapshotVersion — is treated as "no answer" again. Confirmed the host placeholder is only ever emitted at version 0, so dropping the version half does not misclassify any genuine host answer.
  • Transport keeps asking on an unpublished frame (remote-runtime-pty-transport.ts): inventory absence retires the pane only when the frame affirms; a synthesized placeholder keeps the bounded (15s) loop alive instead of returning handle: null.
  • First published update reattaches (remote-runtime-pty-transport.ts update listener + remote-runtime-pty-recovery-state.ts): retryNow() now fires a retry parked during recovering, so the host's own republish reconnects the pane rather than waiting out the ~3-minute recovery deadline. Traced that recovering + pendingRetry only ever means a parked retry with nothing in flight, so this cannot double-reconnect.
  • Placeholder frames dropped at the handle-event boundary (web-session-terminal-handle-events.ts), plus unit coverage that fails without the fix and an e2e repro that holds the relaunched host's graph publication.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

export async function holdWindowGraphPublication(app: ElectronApplication): Promise<void> {
await app.evaluate(({ ipcMain }, channel) => {
Reflect.set(globalThis, '__e2eGraphHeld', true)
Reflect.set(globalThis, '__e2eGraphPublished', 0)

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.

The counter is zeroed here at install and never compared against a pre-install value, so releaseWindowGraphPublication(...).toBe(0) in the spec proves only that no publication completed after install — not that the hold beat the host's first publication. If the relaunched renderer already completed its first runtime:syncWindowGraph before this beforeFirstWindow evaluate runs (there is a CDP round-trip plus assertElectronResolvedIsolatedHome ahead of it in orca-restart.ts:183-190), the wrap silently no-ops and the e2e can pass against unfixed code.

Technical details
# Hold does not prove it won the race against the host's first graph publication

## Affected sites
- tests/e2e/helpers/hold-window-graph-publication.ts:13-14 — `__e2eGraphPublished` initialized to 0 with no record of whether a publication already happened.
- tests/e2e/helpers/hold-window-graph-publication.ts:32-38 — the wrap silently no-ops if `_invokeHandlers` is not a `Map` or the channel handler is absent, with no install self-check and no return value the caller verifies.
- tests/e2e/paired-remote-terminal-host-quit-reconnect-input.spec.ts:330-333 — `expect(releaseWindowGraphPublication(...)).toBe(0)` is the assertion that is meant to guarantee the client met an unpublished host.

## Required outcome
- `toBe(0)` should mean "the hold was installed before the host's first publication", so a lost install race fails the spec instead of silently making it pass against unfixed code.

## Suggested approach (optional)
- At install, verify the handler was actually wrapped (and fail loudly if not), and record whether any publication had already completed before install; assert that pre-install count is 0 (or expose the runtime's already-published graph state) rather than assuming the reset-to-zero is meaningful.

…irst publish

The spec now asks the held host for its tab list and requires the
unpublished placeholder before releasing, so a hold installed too late
fails instead of passing against unfixed code. The helper keeps its gate
in a typed global instead of Reflect lookups.
A retry parked for a handle that needs a replacement was consumed by an
early external trigger and then refused by the epoch's snapshot-wait
guard, leaving nothing to revive the pane. An external trigger now takes
over that snapshot wait as a fresh attempt, and a republished fenced
handle no longer fires the retry. Also refreshes comments that still
paired the placeholder epoch with version 0.
…t has published

The host sent its unpublished placeholder for any worktree it had no
entry for, including one its window had never opened, long after
startup. With the placeholder now read as "ask me later", a paired client
opening such a worktree never got its first terminal.

The host now sends the placeholder only until its graph first publishes.
Afterwards a worktree with no tabs gets a real empty answer, and a client
that was told "ask me later" during startup is sent that answer once on
publication. Against an older host the client withholds the automatic
first terminal for such a worktree, which the user can still create.

A host push now fires only a parked retry, never cutting a scheduled
backoff short.
@Jinwoo-H
Jinwoo-H merged commit e2ccf52 into main Oct 6, 2026
41 checks passed
Jinwoo-H added a commit that referenced this pull request Oct 13, 2026
… later

Hosts before #25736 answer an empty workspace with "ask me later" and
never follow it with a real answer, so waiting for that answer left a
blank workspace with no terminal against them. Wait only on hosts that
advertise session-tabs.empty-worktree-answer.v1; older hosts keep
main's behaviour. Workspaces this client just created are known empty
and open their first terminal without waiting.

Co-Authored-By: Claude <[email protected]>
Jinwoo-H added a commit that referenced this pull request Oct 13, 2026
…ing a terminal (#28154)

* fix(remote-runtime): wait for the host's terminal list before opening a terminal

A paired client opening a workspace whose terminals it had not heard about
yet read "no answer from the host" as "zero terminals" and asked the host for
one. When the host's list then arrived with terminals, the workspace gained an
extra terminal; when it arrived empty, the first-frame bootstrap created a
second one.

The client now treats an unknown host count as unknown. Activation without
explicit startup work waits, and the active subscription's first real answer
seeds the workspace if it is empty. An "ask me later" frame from a host that
has not published yet no longer records a count of zero, and the host's later
answer (sent as an update) is accepted as the first answer for seeding.

* fix(remote-runtime): count an unknown host as empty unless it answers later

Hosts before #25736 answer an empty workspace with "ask me later" and
never follow it with a real answer, so waiting for that answer left a
blank workspace with no terminal against them. Wait only on hosts that
advertise session-tabs.empty-worktree-answer.v1; older hosts keep
main's behaviour. Workspaces this client just created are known empty
and open their first terminal without waiting.

Co-Authored-By: Claude <[email protected]>

* fix(remote-runtime): log a failed delayed terminal open; drop an inert flag

Co-Authored-By: Claude <[email protected]>

---------

Co-authored-by: Claude <[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.

1 participant