Skip to content

fix(terminal): drop a replaced process's title and input modes on restore - #35889

Merged
nwparker merged 1 commit into
mainfrom
fix-35559-respawn-state
Oct 29, 2026
Merged

nwparker merged 1 commit into
mainfrom
fix-35559-respawn-state

Conversation

@nwparker

@nwparker nwparker commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​185 $\color{#cf222e}{\Huge{\mathbf{−}}}$​4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​181
Prod 10 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​43 $\color{#cf222e}{\Huge{\mathbf{−}}}$​23 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​20

ELI5

If the machine running a remote Orca server restarts while Claude was open in a terminal, the pane comes back with a fresh shell. Before this change, Orca still treated the pane as Claude. It showed Claude's title, and it left the browser terminal "listening" for mouse moves and window focus, so moving the mouse typed garbage like ^[[<35;59;2M into bash. Now the restored shell starts clean: a neutral title, no agent label, and none of the dead program's mouse, focus or cursor-key settings.

What Changed

Before: after a host restart that lost the terminal daemon, orca terminal list showed title: "✳ Claude Code" and agentIdentity: "claude" for a pane running only bash. Orca Web and paired desktop clients also kept mouse tracking, focus reporting and cursor-key mode armed. After: the pane shows a neutral title, has no agent identity, and only modes the new shell set itself are armed.

Two kinds of state that belong to a process now follow the "this is a new process" verdict:

  • Title (server). On a cold restore, main used to seed the dead process's last title from the checkpoint as the new shell's live title. That stale title drove the agent identity and the title-derived status, and it made clients choose the agent-preserving post-replay reset. The cold-restore payload no longer carries that title. Durable checkpoints of the respawned session now take their title only from the live terminal, so a later reattach cannot bring the dead title back. A live reattach still seeds the daemon's real title, which was the reason for fix(runtime): seed terminal previews and titles from restore payloads #12579.
  • Input modes (client). A pane now records which process incarnation its xterm's modes belong to. When the host binds a different known incarnation, the pane writes the process-boundary ground before the new process's replay. That is the same ground a fresh spawn already writes. Any modes the new process armed come back from its own snapshot. A same-incarnation reattach (for example a serve restart with the daemon still alive) is left alone.

Why

The root problem was that state belonging to the dead process outlived it. Two narrower fixes were rejected:

  • Only changing which reset clients pick still leaves the wrong title and agent identity in terminal list, on mobile and in orchestration.
  • Seeding the terminal owner as shell on a cold restore would claim a proof the daemon never makes.

Each half also covers mixed versions on its own:

  • Old clients talking to a new server get the neutral title, so they take the existing shell reset path, which clears mouse and focus.
  • New clients talking to an old server still get incarnation ids, so they ground their modes. The e2e was also run with only the client half, against the old title behaviour, and modes were clean.
  • There is no wire change.

This does not duplicate #30195 (a mouse/focus reset before every snapshot replay) or #15666 (retiring resume authority).

Linked Issue

Fixes #35559

Thanks to @clayphi for the detailed report and code-path analysis.

Visual Proof

N/A. This is a terminal-state change, not a visual one. It is verified by the e2e below, which reads the client's xterm modes and the host's terminal list.

Testing

  • New e2e tests/e2e/paired-serve-respawn-process-state.spec.ts, using a headless orca serve host and a paired client:

    1. A shell sets a Claude title and arms mouse 1003/1006, focus 1004, paste 2004 and cursor-key mode 1.
    2. Control: a serve restart that keeps the daemon reattaches the same process, and no ground runs.
    3. A serve restart that also kills the daemon must leave mouse off, focus off and cursor keys normal, with no Claude title and no agent identity.
    4. Result: it fails on origin/main (all three modes still armed, title still Claude) and passes with this change (2/2 runs).
  • Unit tests:

    • process-boundary-ground.test.ts checks that neither the cold-restore payload nor the durable checkpoint folds keep the dead title. It fails on origin/main.
    • pty-restore-record-seeding.test.ts checks that a cold restore seeds the history but not the checkpoint title.
  • Related e2e specs pass: serve-restart binding, serve cold-restore agent status, desktop restart/cold restore input, and the reattach mouse-mode leak and live-TUI mouse specs.

  • A desktop-local cold-restore probe also came back clean.

  • All unit tests that import the changed modules pass (63 files). check:changed static checks pass.

  • Tested on macOS. The new e2e is skipped on Windows because it uses POSIX printf. The code itself has no platform branches.

  • I manually tested these changes locally

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

Review

  • Codex review: no findings.
  • Independent review: no P0–P2 findings.

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

  • Security: no change.
  • Cross-platform: no platform-specific code.
  • Remote: this targets remote runtimes.
  • SSH: relay PTYs carry no incarnation, so they are unchanged.
  • Folder and git workspaces: not affected.
  • Mobile: it gets the corrected title and agent identity from the server. Whether the mobile terminal view keeps input modes across an incarnation change was not checked.
  • Separately observed, already on main and not changed here: after a serve restart that keeps the daemon, the paired client drops mouse and focus modes of a still-live mode-arming process.

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)

…tore

When a host restart restores a pane by starting a new shell, the pane kept
the dead process's title and the client's xterm kept its input modes. A
pane that had Claude open came back as bash but still read as Claude, so
the reattach picked the agent-preserving reset and mouse moves and focus
changes were typed into the shell as escape codes.

Two process-bound facts now follow the respawn verdict:

- Title: the cold-restore payload no longer carries the checkpoint's last
  title into the new process's records, and durable checkpoints of the new
  process take the title from the live terminal only. The title, agent
  identity and title-derived status reflect the new shell.
- Input modes: a pane records which process incarnation its xterm's modes
  belong to. When the host binds a different known incarnation, the pane
  grounds the process boundary before the new process's replay, the same
  ground a fresh spawn already writes, so only modes the new process set
  are armed.

Older servers still report incarnations, so new clients ground their modes
against them; older clients get the neutral title from new servers and
take the shell reset path.

Fixes #35559
@coderabbitai

coderabbitai Bot commented Oct 29, 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 6 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
  • 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: 86b3c9fc-aaf7-4a49-8bb5-effc854083f5
Commits

Reviewing files that changed from the base of the PR and between cd821ab and b14e55d.

Files selected for processing: 16
  • src/main/daemon/cold-restore-payload-cache.ts
  • src/main/daemon/daemon-durable-history-snapshot.ts
  • src/main/daemon/process-boundary-ground.test.ts
  • src/main/ipc/pty/pane/agent-session-owners.ts
  • src/main/ipc/pty/pty-restore-record-seeding.test.ts
  • src/main/persistence/loading-store/pty-spawn-restore-durability.test.ts
  • src/main/providers/pty-spawn-result.ts
  • src/renderer/src/components/terminal-pane/pty-connection/deferred-cold-restore-and-snapshot.ts
  • src/renderer/src/components/terminal-pane/pty-connection/fresh-spawn-start.ts
  • src/renderer/src/components/terminal-pane/pty-connection/pane-pty-visibility-bind.ts
  • src/renderer/src/components/terminal-pane/pty-connection/reattach-result-handler.ts
  • src/renderer/src/components/terminal-pane/pty-connection/replaced-process-input-modes.ts
  • src/renderer/src/components/terminal-pane/pty-connection/transport-output-callbacks.ts
  • src/renderer/src/components/terminal-pane/remote-runtime-pty-transport-pane-binding-ownership.test.ts
  • src/renderer/src/components/terminal-pane/remote-runtime-saved-result-consumer.test.ts
  • tests/e2e/paired-serve-respawn-process-state.spec.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

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

@greptile-apps

greptile-apps Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] This PR appears safe to merge; no actionable issues were found.

Summary

This PR stops a replacement shell from inheriting the dead process’s title and input modes.

  • Restored shells no longer inherit the previous process’s title.
  • A replacement process starts without the old process’s terminal input modes.

nwparker identified the same-process mouse/focus reset as already present on main, outside this change. nwparker also explicitly left mobile input-mode behavior unchecked; this review does not treat it as a new defect.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Restore terminal] --> B{Same process survives?}
  B -->|Yes| C[Keep live title and incarnation]
  B -->|No| D[Drop checkpoint title]
  D --> E[Bind replacement incarnation]
  E --> F[Ground old input modes]
  C --> G[Replay process snapshot]
  F --> G
  G --> H[Resume live output]
Loading

Reviews (1) · Last reviewed commit: "fix(terminal): drop a replaced process's..." · Reviewed by Greptile

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 restart leaves a dead agent's mouse and focus reporting armed in the restored shell

1 participant