Skip to content

fix(agent-status): show agent status on a terminal that comes back in a new tab after a restart - #31841

Closed
AmoabaKelvin wants to merge 3 commits into
mainfrom
pane-key-after-restart
Closed

AmoabaKelvin wants to merge 3 commits into
mainfrom
pane-key-after-restart

Conversation

@AmoabaKelvin

@AmoabaKelvin AmoabaKelvin commented Oct 22, 2026 •

Copy link
Copy Markdown
Collaborator
Files Added Deleted Net
Test 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​232 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​232
Prod 17 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​97 $\color{#cf222e}{\Huge{\mathbf{−}}}$​7 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​90

What users saw

A terminal that survives an Orca quit and relaunch can come back in a tab with a new id (the renderer no longer had its recorded tab). Agent hooks from that shell still post the old ORCA_PANE_KEY, so Orca filed their status under a tab that no longer exists:

  • the live tab and the sidebar showed no agent status;
  • orca worktree ps listed the agent under the dead pane key;
  • on iOS and Android, long-pressing the tab showed no "Switch to chat view";
  • claude --resume in the same tab did not help, because the new process inherits the same env.

Now the status shows on the tab the terminal is in, and later hooks from that shell (including a claude --resume there) land on it too.

Root cause

Hooks identify themselves only by the pane key their env exported at spawn, and a running shell's env can't change. After a relaunch, nothing in main knew which key a surviving terminal had exported: main's only per-terminal record of it was in memory, and the terminal host's session list didn't carry it. So when the terminal was shown in a newly minted tab, nothing told the hook server to move that key's status, the way a pane move or detach does with transferPaneAuthority.

Fix

  • The terminal host reports the key it exported. The daemon's session keeps the ORCA_PANE_KEY from its spawn env (a reattach never re-exports it) and lists it as an optional envPaneKey, next to the terminalHandle it already lists. The same host code runs for the desktop, headless orca serve, WSL and orcad on SSH hosts.
  • Main follows it. The runtime stores the key on its terminal record from every inventory. After each inventory and graph sync (and when main places a terminal itself, or adopts an orphan headless), a live terminal shown in a different pane than the key it exported gets that key's status moved there through the existing transferPaneAuthority. That is the same move a pane detach does, and the same persisted alias, cleared when the terminal exits.
  • It never guesses. If another live terminal also exported or is shown in either the old or the new pane, nothing moves. A move made before that was known is undone: the status goes back under the exported key, and posts land there as before. The same happens when the terminal is shown in its exported pane again.

Desktop, the sidebar, orca worktree ps and mobile all read the host's per-pane status, so they follow without client changes.

Mixed versions: the field is optional. A daemon or orcad that predates it (an old daemon keeps running after an app update) lists nothing, and status stays where it lands today. An older app ignores the field. Not covered: the legacy SSH relay (the released relay.js can't be changed) and the in-process fallback provider used when the daemon fails to start (its terminals die with the app, so they can't survive a restart).

Verification

  • src/main/runtime/exported-pane-key-follow.test.ts drives the real runtime and hook server through inventory and graph sync: the row filed under the old key moves to the new tab and later posts land there; an older host without the field keeps today's behaviour; a key another live terminal shows or also exported is left alone; a move made before a second terminal was known is undone with its status; a destination another terminal exported is refused; and a terminal shown in its exported pane again gets its status back. With the move removed the first case fails; with the guard removed the third fails; the last three each failed before the follow-up commit.
  • src/main/daemon/terminal-host-env-pane-key-listing.test.ts: the daemon lists the spawn-time key after a reattach from another pane, and fails without the change.
  • Live: in a hidden dev build of this branch, a shell that survived a force-quit and relaunch posted a hook that showed on its tab and in the sidebar (no regression on the normal path).
  • Neighbouring daemon, admission, graph-sync and placement suites pass; check:code-quality:changed, check:react-doctor:changed and pnpm tc:node are clean.

Visual Proof

N/A: I couldn't reach the bug's trigger in a real app without hand-editing saved state. The trigger is a surviving terminal whose tab the renderer no longer has after a relaunch. In a hidden dev build I opened a tab, started a delayed hook from its shell and force-quit Orca within a second. The tab was already saved, so it came back under its own id, and the hook landed on it as usual (no change from main). #24458 also found no natural path that loses the tab. The runtime test above drives the restart sequence through the real runtime and hook server instead.

Fixes #23753

@coderabbitai

coderabbitai Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
Walkthrough

The daemon now retains and reports the pane key exported when a PTY starts. Runtime PTY records store that key and compare it with each terminal’s current pane key. When exactly one live PTY claims each differing key, runtime code transfers authority to the current pane. Runtime update paths invoke this logic. Tests cover moved panes, missing keys, and competing claims.

Priority: Normal

Severity of issue fixed: Medium

Merge Risk: Low · up to dc128

Agent status can occasionally appear under the wrong tab after a terminal is pruned or another terminal reports status during a pane move. The change is mergeable with owner awareness of these bounded cases and a follow-up for alias cleanup.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 35.48% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 31 functions across 33 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 names the change: a terminal that comes back in a new tab after a restart now shows its agent status. The fix is in the agent-status routing path. The title uses the conventional fix(scope) …
Description check Passed The description follows the template well. It has the ELI5-style narrative in 'What users saw', a 'Root cause' section, a 'Fix' section, a 'Verification' section, a 'Visual Proof' section with an N/A …
Linked Issues check Passed Issue #23753 requires status from a surviving terminal to follow the pane that now owns its PTY. The daemon records the spawn-time ORCA_PANE_KEY as optional envPaneKey. Runtime inventory tracks th…
Out of Scope Changes check Passed The changes stay within issue #23753. Host metadata, runtime tracking, authority transfer and restoration, inventory and placement integration, mixed-version handling, and focused tests directly suppo…
Full details: Title check

Explanation

The title names the change: a terminal that comes back in a new tab after a restart now shows its agent status. The fix is in the agent-status routing path. The title uses the conventional fix(scope) prefix. It is 95 characters, which is longer than a short title should be, but it stays specific and readable.

Full details: Description check

Explanation

The description follows the template well. It has the ELI5-style narrative in 'What users saw', a 'Root cause' section, a 'Fix' section, a 'Verification' section, a 'Visual Proof' section with an N/A reason, and a 'Fixes #23753' line. The 'What Changed' and 'Why' headings are replaced by 'What users saw', 'Root cause', and 'Fix'. The description does not include the template's 'Testing' checklist, the 'AI Disclosure' section, the 'Agent skill upstream boundary' checkbox, or the 'Checklist'. Those are template items the author did not fill in. The description also covers why the chosen approach beats alternatives only implicitly. These gaps are non-critical, so the description is mostly complete.

Full details: Linked Issues check

Explanation

Issue #23753 requires status from a surviving terminal to follow the pane that now owns its PTY. The daemon records the spawn-time ORCA_PANE_KEY as optional envPaneKey. Runtime inventory tracks that key and followExportedPaneKeys transfers authority to the current pane only when both keys have one live claimant. returnPaneAuthority restores the exported key when the mapping becomes ambiguous or the terminal returns to its original pane. The reported tests cover the restart flow, later hooks, older hosts, conflicts, and restoration.

Full details: Out of Scope Changes check

Explanation

The changes stay within issue #23753. Host metadata, runtime tracking, authority transfer and restoration, inventory and placement integration, mixed-version handling, and focused tests directly support surviving-terminal status attribution. No unrelated product behavior is demonstrated.

Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • 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.

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

Actionable comments posted: 2


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: e0e2f8c4-20f4-47d8-968b-7892935182c2
📥 Commits

Reviewing files that changed from the base of the PR and between aa5594d and 964f955.

📒 Files selected for processing: 35
  • config/main-layout-writer-baseline.txt
  • src/main/agent-hooks/server/server-authority-aliases.ts
  • src/main/daemon/daemon-pty-session-inventory.ts
  • src/main/daemon/session-options.ts
  • src/main/daemon/session.ts
  • src/main/daemon/terminal-host-env-pane-key-listing.test.ts
  • src/main/daemon/terminal-host-session-create.ts
  • src/main/daemon/terminal-host-session-listing.ts
  • src/main/daemon/types.ts
  • src/main/ipc/pty/delivery/attached-pty-size.ts
  • src/main/ipc/pty/ipc/spawn-commit-persist.ts
  • src/main/ipc/pty/ipc/spawn-commit.ts
  • src/main/ipc/pty/ipc/spawn-options.ts
  • src/main/ipc/pty/pane/key-state.ts
  • src/main/ipc/pty/pane/stable-owner.ts
  • src/main/ipc/pty/runtime/spawn-commit-pty-size.ts
  • src/main/ipc/pty/runtime/spawn-commit-response.ts
  • src/main/ipc/pty/runtime/spawn-commit.ts
  • src/main/ipc/pty/spawn-commit-assembly.ts
  • src/main/ipc/pty/spawn-commit-binding.ts
  • src/main/ipc/pty/spawn-commit-publication.ts
  • src/main/ipc/pty/spawn-host-env.ts
  • src/main/ipc/pty/spawn-options-assembly.ts
  • src/main/providers/pty-process-info.ts
  • src/main/providers/pty-process-list-admission.ts
  • src/main/runtime/exported-pane-key-follow.test.ts
  • src/main/runtime/rpc/methods/agent-launch-instant-tab.test.ts
  • src/main/runtime/runtime-terminal-state-records.ts
  • src/main/runtime/session-graph/session-graph-promotion.ts
  • src/main/runtime/session-graph/session-window-graph.ts
  • src/main/runtime/terminal/adoption/adopt-terminal-orphans-from-inventory.ts
  • src/main/runtime/terminal/identity/exported-pane-key-follow.ts
  • src/main/runtime/terminal/identity/pty-worktree-record.ts
  • src/main/runtime/terminal/lifecycle/pty-controller-inventory-refresh.ts
  • src/main/runtime/workspaces/persisted-surfaces/restored-terminal-placement.ts
💤 Files with no reviewable changes: 2
  • src/main/ipc/pty/runtime/spawn-commit-pty-size.ts
  • src/main/ipc/pty/ipc/spawn-commit-persist.ts

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

@AmoabaKelvin
AmoabaKelvin force-pushed the pane-key-after-restart branch from 964f955 to 41f84ce Compare October 22, 2026 07:16
…after a restart

A surviving terminal's hooks keep posting the ORCA_PANE_KEY its env exported,
but after a relaunch nothing in main knew that key once the terminal came back
in a newly minted tab. The terminal host now reports the key it exported, and
when main records the terminal in a different pane it moves that key's status
with the existing transferPaneAuthority, as a pane move does.
@AmoabaKelvin
AmoabaKelvin force-pushed the pane-key-after-restart branch from 41f84ce to 4acba1d Compare October 25, 2026 02:41

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

Actionable comments posted: 2


Review info
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: 81a9d0c2-cf62-435b-9c8a-3d9904f67cc7
Commits

Reviewing files that changed from the base of the PR and between 41f84ce and 4acba1d.

Files selected for processing: 16
  • src/main/agent-hooks/server/server-authority-aliases.ts
  • src/main/daemon/daemon-pty-session-inventory.ts
  • src/main/daemon/session.ts
  • src/main/daemon/terminal-host-session-create.ts
  • src/main/daemon/terminal-host-session-listing.ts
  • src/main/daemon/types.ts
  • src/main/providers/pty-process-info.ts
  • src/main/providers/pty-process-list-admission.ts
  • src/main/runtime/runtime-terminal-state-records.ts
  • src/main/runtime/session-graph/session-graph-promotion.ts
  • src/main/runtime/session-graph/session-window-graph.ts
  • src/main/runtime/terminal/adoption/adopt-terminal-orphans-from-inventory.ts
  • src/main/runtime/terminal/identity/exported-pane-key-follow.ts
  • src/main/runtime/terminal/identity/pty-worktree-record.ts
  • src/main/runtime/terminal/lifecycle/pty-controller-inventory-refresh.ts
  • src/main/runtime/workspaces/persisted-surfaces/restored-terminal-placement.ts

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

Comment thread src/main/daemon/types.ts Resolved
…biguous

Status moved off a terminal's exported pane key now goes back under that key
when another live terminal also exported or shows either key, or when the
terminal is shown in its exported pane again. A move also needs its
destination to be unambiguous.

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

Caution

Some comments are outside the diff and can’t be posted inline due to GitHub limitations.

⚠️ Outside diff range comments (1)

Minor · Clear aliases when pruning a certified PTY. · exported-pane-key-follow.ts:35-39

src/main/runtime/terminal/identity/exported-pane-key-follow.ts:35-39
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Clear aliases when pruning a certified PTY.

dropDisconnectedPtyRecord can remove a certified PTY without clearing its pane-key alias. If PTY1 leaves A → B, a later PTY2 can export A while appearing at C. followExportedPaneKeys then calls transferPaneAuthority(A, C, PTY2). The PTY mismatch makes getPhysicalPaneKeyForAuthority fall back to A, but resolvePaneKeyAlias(A) still returns B. transferPaneAuthority therefore moves the cached status from B to C, and PTY2 inherits PTY1’s status.

Clear the certified PTY’s pane-key aliases before deleting its runtime record. The existing canTransferPaneAuthority check does not protect this path because followExportedPaneKeys calls transferPaneAuthority directly, and transferPaneAuthority does not invoke that check.


Review info
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: a31c7450-1c69-4d08-b795-8c3505e4f215
Commits

Reviewing files that changed from the base of the PR and between 50f2b2e and dc12842.

Files selected for processing: 3
  • src/main/agent-hooks/server/server-authority-aliases.ts
  • src/main/runtime/exported-pane-key-follow.test.ts
  • src/main/runtime/terminal/identity/exported-pane-key-follow.ts
Files skipped from review as they are similar to previous changes: 3
  • src/main/runtime/terminal/identity/exported-pane-key-follow.ts
  • src/main/agent-hooks/server/server-authority-aliases.ts
  • src/main/runtime/exported-pane-key-follow.test.ts

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

nwparker added a commit that referenced this pull request Oct 25, 2026
…after a restart (#33601)

After an Orca restart with the PTY daemon alive, a surviving terminal placed in a different pane than its spawn ORCA_PANE_KEY now carries that key's agent status (prompt, session) to the live pane, using the daemon-reported spawn key and the manual pane-move mechanism; ambiguous keys (claimed by more than one live terminal) are left alone.

Fixes #23753
Supersedes #31841

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

[Bug]: Agent status goes to a dead tab after Orca restart — surviving shells keep the old ORCA_PANE_KEY, mobile hides Switch to chat view

1 participant