Skip to content

fix(terminal): bring each pane back after a terminal service restart when it is shown - #28880

Merged
Jinwoo-H merged 3 commits into
mainfrom
fix/restart-replaced-panes-reconnect
Oct 15, 2026
Merged

Jinwoo-H merged 3 commits into
mainfrom
fix/restart-replaced-panes-reconnect

Conversation

@Jinwoo-H

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

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​309 $\color{#cf222e}{\Huge{\mathbf{−}}}$​7 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​302
Prod 5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​65 $\color{#cf222e}{\Huge{\mathbf{−}}}$​5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​60

ELI5

"Restart terminal service" ends every terminal and starts a fresh background service. Until now, every terminal that was already open stayed dead afterwards. Typing did nothing and agents didn't come back until you quit and reopened Orca. Now each terminal comes back like it does after a relaunch: the one you're looking at right away, every other one when you next look at it.

What Changed

Before: after Settings → "Restart terminal service":

  • every open pane kept its old output but had no process behind it;
  • typing did nothing, and visiting the tab or workspace didn't help;
  • agents never resumed their conversation;
  • only workspaces never opened since launch worked.

After:

  • Timing:
    • The panes you can see get a fresh shell right away.
    • Every other open pane (background tabs, splits, other workspaces) gets one the next time it is shown.
  • What comes back:
    • The shell starts in the same folder, and the old output stays above the new prompt.
    • Agents resume their conversation through the same resume a relaunch uses. Agent panes show the same "session restored" line a relaunch shows.
  • No bulk resume: panes you never look at again start nothing. A restart never resumes every background agent at once.

Mechanism:

  • Window, on a restart exit: the restart's exit already carries a "replaced" label (from fix(daemon): keep every pane in main's layout through a terminal service restart #28852). When the window sees it, it clears the pane's dead process binding and marks the pane as needing a replacement.
  • When the replacement starts: at once if the pane is visible, otherwise on the next "pane shown" signal, the same trigger the sleeping-agent wake uses.
  • What the replacement does: it starts the same fresh shell plus agent resume that the sleeping-agent wake and a relaunch use (startFreshColdRestoreAgentResume). It does this only if nothing else has given the pane a process in the meantime.
  • Main, waiting for the new service: a local terminal start that arrives while the restart is still running now waits until the new background service is in place. Without this wait, the visible panes started inside the old service and died with it, which I reproduced.

Why

  • Same recovery as a relaunch. The resume reads the per-agent recovery record that Orca already writes on every agent turn, the one a relaunch after a crash reads. So restart recovery behaves exactly like relaunch recovery, and no new state is added.
  • No sleep state or new UI. Nothing is put to sleep, and nothing new is shown.
  • One spawn per pane, only on demand. Starting replacements only on show keeps a restart cheap with hundreds of agents open.

Alternatives I rejected:

  • Keeping the window's agent status row through the exit. Main's agent-status store clears that row on any process death before the window even sees the exit, so keeping it changed nothing in a real app.
  • Remounting the whole tab. That rebuilds the terminal and is heavier than starting a new process inside the pane that is already mounted.

Linked Issue

N/A (maintainer; layout refactor follow-up to #28852)

Visual Proof

Hidden app, fake agent CLI (no real credentials). Each shot is taken after showing the pane and typing echo LIVE_….

Background tab, before (typing does nothing):
2_second_tab.png

Background tab, after (old output kept, new prompt, echo works):
2_second_tab.png

Agent pane in another workspace, before (dead, no resume):
6b_agent_in_other_workspace.png

Agent pane in another workspace, after (resume command runs, then a live shell):
6b_agent_in_other_workspace.png

Testing

Real app, hidden window (ORCA_BACKGROUND_LAUNCH=1), isolated profile and home on macOS. A fake codex reports through the real hook server. Each pane is shown, then echo is typed into it.

Case Before: live shell / agent resumed After: live shell / agent resumed / old output kept
Visible, focused pane No / – Yes / – / Yes
Agent in the visible tab No / No Yes / once / Yes
Second tab, shown later No / – Yes / – / Yes
Split in a background tab (both panes) No / – Yes / – / Yes
Another workspace, opened earlier No / – Yes / – / Yes
Agent in another workspace No / No Yes / once / Yes
Workspace never opened since launch Yes / – Yes / – / Yes
4 agent panes in a workspace never shown again 0 resumes 0 resumes

More checks:

  • Two restarts before a visit: the hidden pane still gets exactly one new process when shown.

  • Layout oracle: all 21 scenarios pass. The live-daemon-restart pane-marker check, which was known to fail on main, now passes, so its entry is removed.

  • New unit tests, pty-connection-restart-replacement.test.ts:

    • visible spawns now; hidden spawns on show, once;
    • a pane closed first spawns nothing;
    • a pane another flow rebound spawns nothing;
    • a finished-turn agent resumes once;
    • a plain -1 exit is unchanged.
    • The first two fail without the change.
  • New unit test, daemon-restart-state.test.ts: the restart wait settles on success and on failure.

  • Gates: pnpm tc, oxlint, oxfmt, the changed-code quality gate and the layout, focus, max-lines, sync-spawn and electron ratchets pass. 302 targeted terminal-pane tests pass.

  • I manually tested these changes locally

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

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

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

  • SSH and remote servers: untouched. Only the local service's restart exits carry the label, and the spawn wait is local-only.
  • Degraded mode: unchanged. Terminals on the local fallback end with real exits, as before.
  • Hibernated panes: unaffected. A pane that is already asleep has no process, so it gets no restart exit, and its wake works as before.
  • Mobile: a phone that opens a hidden pane does not start the replacement; the desktop showing the pane does. This is unchanged and noted as a possible follow-up.
  • Platforms: no platform-specific code.

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)

…when it is shown

After Settings -> "Restart terminal service", every pane that was open kept its
dead process: typing did nothing and agents never resumed until Orca relaunched.

A restart-replaced exit now arms the pane: the visible pane spawns its
replacement at once, any other pane when it is next shown, through the same
fresh spawn and cold-restore agent resume the hibernation wake uses, so old
output stays above the new prompt. The exit keeps the agent status the resume
reads, and clears the dead binding so the replacement binds as a first spawn.
Local spawns wait for an in-flight restart so they reach the new daemon.

Claude-Session: p2-headless
…her flow rebound

A restart exit is a process death to main's agent-status store, which clears the
pane's row before the window sees the exit, so keeping the window's copy changed
nothing. The resume reads the live recovery record every agent turn already
writes, as a relaunch after a crash does. The replacement also stands down when
the pane's stored binding already names another process.

Claude-Session: p2-headless
A finished-turn agent pane took the hibernation wake, which gives up when its
record changes before the pane is shown. Every restart exit now arms the
replacement directly.

Claude-Session: p2-headless
@coderabbitai

coderabbitai Bot commented Oct 14, 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: 0e14813d-e58e-47a8-bb7b-2587d4c28172
📥 Commits

Reviewing files that changed from the base of the PR and between 818e782 and ee79af8.

📒 Files selected for processing: 8
  • src/main/daemon/daemon-restart-state.test.ts
  • src/main/daemon/daemon-restart-state.ts
  • src/main/ipc/pty/register-handlers.ts
  • src/renderer/src/components/terminal-pane/pty-connection-restart-replacement.test.ts
  • src/renderer/src/components/terminal-pane/pty-connection/pty-exit-hibernate.ts
  • src/renderer/src/components/terminal-pane/pty-connection/restart-replacement-on-show.ts
  • src/renderer/src/components/terminal-pane/pty-connection/session-reconcile-dispose.ts
  • tests/e2e/workspace-layout-oracle-known-on-main.ts
💤 Files with no reviewable changes: 1
  • tests/e2e/workspace-layout-oracle-known-on-main.ts

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

📝 Walkthrough

Local PTY startup now waits for the configured startup promise and any in-flight daemon restart to settle. When a PTY exit is replaced by a restart, the pane arms a replacement resume that runs immediately if visible or when visibility resumes, subject to session and PTY checks. Tests cover these paths. The known-on-main entry for the daemon restart marker was removed.

Priority: ⬇️ Low

Merge Risk: ⚪ Minimal · up to ee79a

Replacement spawn failures already have a pane recovery path. No actionable merge-blocking risk remains after normal checks.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 54.55% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 11 functions across 7 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly describes the primary change: restoring terminal panes after a terminal service restart when they are shown.
Description check Passed The description is complete and aligned with the repository template. It explains the user impact, mechanism, rationale, testing, visual proof, compatibility considerations, and checklist results. The…
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.
  • Fix all pre-merge checks with AI
✨ Finishing Touches: 💡 2
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🛠️ Fix failing CI checks: 💡
  • Commit to this branch
  • Create a new PR
  • 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.

@Jinwoo-H
Jinwoo-H merged commit 8a6cc6c into main Oct 15, 2026
88 of 91 checks passed
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