Skip to content

fix(terminal): keep the tab when a reattach finds its process gone - #28067

Merged
Jinwoo-H merged 7 commits into
mainfrom
fix/absent-pane-keeps-tab
Oct 12, 2026
Merged

Jinwoo-H merged 7 commits into
mainfrom
fix/absent-pane-keeps-tab

Conversation

@Jinwoo-H

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

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​26 $\color{#cf222e}{\Huge{\mathbf{−}}}$​48 $\color{#cf222e}{\Huge{\mathbf{−}}}$​22
Prod 5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​100 $\color{#cf222e}{\Huge{\mathbf{−}}}$​17 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​83

ELI5

When Orca relaunches, the window reconnects each terminal pane to its old process. If that process is gone (the terminal service restarted, or the workspace was asleep), the window starts a fresh process in the same pane. Main also reacted to the missing process, but it did so by deleting the whole tab from its saved copy of the layout. The window kept showing the tab, so the two copies disagreed until the window happened to save again. Now main only forgets the dead process and keeps the tab.

What Changed

Before: relaunch after the terminal service was killed, or wake a slept workspace after a relaunch. The window shows the tabs, but main's saved layout has the terminal records with no tab bar entry and no group. Main then mints a new group with a new id, while paired clients (the phone, a second desktop) see the panes and group missing or under a different id. This lasts until the window saves its tab bar again.

After: main keeps the tab, its group and its pane, and only clears the dead process id from that pane. The fresh process the window starts then binds to the same pane, so every view keeps the same tab and group ids.

Mechanism: when the reconnect attempt hears from the process's host that the process no longer exists, attachStablePaneOwner used to:

  1. report a plain process exit, which retires the whole surface (pane, then tab, then group) from main's session; and
  2. delete the persisted surface again through retirePersistedStablePaneOwner.

The new releaseAbsentPaneOwner (src/main/ipc/pty/pane/absent-pane-owner.ts) reuses two things that already exist:

  • the intentional-stop register's replaced kind, which tells the exit handler that a new process is taking the pane, so the surface stays;
  • the replaced-pane binding clear (retireReplacedPaneBinding in pane-owner-replacement.ts, split out of the existing releaseStoppedPaneBinding), which calls store.retirePtyBinding to clear only that pane's process id. Going through that existing writer keeps the main-process layout-writer ratchet at its baseline.

A unit test on main had pinned the old behaviour as "drops the tab ... leaving re-persistence to the renderer". It now asserts that the tab and pane stay and only the binding is cleared.

Why

A missing process is not a closed tab: the window is about to start a fresh process in that same pane. Deleting the tab made main's copy disagree with the window's. The tab then came back only through a later window save, and any reader in between (the phone, the CLI, the layout stream) saw it missing. Both pieces were already there. A planned replacement (terminal restart) uses replaced today, and retirePtyBinding was written for exactly "clear a stopped process's binding, keep the pane". So this adds no new mechanism and removes one path where main edited the tab bar on its own.

The surface-wide retirement stays where it is correct, for example an agent session that exits during start.

Alternatives considered:

  • Keep main's retirement and have the window re-save its tab bar after every reattach. That keeps two writers racing, and leaves paired clients wrong until the save lands.
  • Skip the binding clear and let the fresh spawn overwrite it. That works when a fresh spawn follows. But the adopt path that finds the process gone does not spawn, so main would keep naming a dead process, and every later reattach would hit the same miss.

Linked Issue

Fixes #

Visual Proof

N/A: the window already drew the tabs correctly. What changes is main's saved layout and what paired clients are told, which the layout checker reads. Evidence is the e2e runs below.

Testing

  • I manually tested these changes locally (macOS, background dev Electron: the layout checker's sleep-quit-resume, cold-daemon-restart and restart-restore scenarios)

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

  • Updated src/main/ipc/pty/pane/stable-pane-absence-respawn.test.ts. The shared durable-store test fixture gains the Store's binding-only retirement.

  • Removed the known-on-main entries this fixes from tests/e2e/workspace-layout-oracle-known-on-main.ts: all cold-daemon-restart entries (paired-client list empty, tab bar not saved after relaunch, group re-minted) and all sleep-quit-resume entries (tab bar not saved after wake). With those entries gone, the scenarios pass in CI. Windowed and headless layout checker run, with the orcad scenarios running: 38306972065 (all 39 tests pass).

  • Full e2e suite: 38306983931. Diffed against main at the same commit (38297736386), there are no failures that main does not also have. Shards 6, 7 and 12 hit the 30-minute job limit, as they do on main, and shard 11 did too here; every test in shard 11 finished with the same results as main. An earlier head's full run (38302215596) showed manual-worktree-order-persistence (sidebar worktree drag order) failing once. It passed in three separate runs on this branch (38302237975, 38305925637, 38305935672) and on main (38305944547).

  • pnpm tc, oxlint and check:code-quality:changed pass. The main, persistence, runtime and shared layout unit suites pass.

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

  • Scope: only the "host says the process is gone" answer is affected. A lost link, timeout or unverified owner still refuses to respawn and keeps the binding, as before.
  • SSH: the binding is cleared in the SSH host's own session partition (toSshExecutionHostId), as the old retirement did. A relay's "absent" answer still counts as proof of absence, as before.
  • Folder workspaces: they use the same pane path and are handled identically.
  • No Store: when a workspace pane has no Store to clear its binding, the respawn is refused, as before. The PTY handlers take the Store as optional, so that path stays.
  • Headless servers (no window): the pane stays with no process until a client activates it, which is how any restored pane looks.
  • Not in scope: the in-app "restart terminal service" action ends processes through a different path and still empties main's layout. That is a separate change; its known-on-main entries stay.
  • Heap probe (test only): same fix and evidence as the companion tab-order PR. The paired-terminal retention spec read a cached heap figure after a single collection pass, so whether it failed depended on timing, on main too. The probe now collects twice and reads the exact heap. If the heap cannot be read, the check fails instead of being skipped. The budget is unchanged. Runs 38301290228 and 38301300121: 6 of 6 pass on both, with the heap after parking at or below the baseline.

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)

@coderabbitai

coderabbitai Bot commented Oct 12, 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

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: 10ea20d4-863a-40f9-9fd5-1b14c896d907
📥 Commits

Reviewing files that changed from the base of the PR and between 1add5a9 and e9f8297.

📒 Files selected for processing (1)
  • 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; 8 remain after this review.

📝 Walkthrough

Walkthrough

The changes add a shared helper for absent-pane PTY cleanup and binding retirement. Stable-owner handling now uses the helper when attach reports SessionNotFoundError. The durable store fixture adds serialized PTY binding retirement, and persistence tests verify that retirement preserves the tab and pane layout. The changes also remove specified workspace-layout findings from the known-on-main allowlist and update the description of the replaced stop kind.

Priority: ⬇️ Low

Merge Risk: 🔵 Low · up to e9f82

The allowlist removal has no established new defect, but a rejected CDP command may still leave an e2e session attached. Merge with owner awareness of that open concern.

Pre-merge checks · Passed 3 · Failed 2

Failed Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check Warning The description clearly explains the user impact, mechanism, rationale, scope, testing, and checklist status. However, the required Linked Issue section contains only Fixes # and does not identify a… Add the actual linked issue number or URL after Fixes #. Complete any applicable empty sections, such as Review, if required by repository policy.
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 8 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks (3 passed)
Check name Status Explanation
Title check Passed The title is concise, specific, and accurately describes the primary change: preserving the tab when reattachment finds that its process is gone.
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: Description check

Explanation

The description clearly explains the user impact, mechanism, rationale, scope, testing, and checklist status. However, the required Linked Issue section contains only Fixes # and does not identify an actual issue.

  • Fix all pre-merge checks with AI
✨ 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: 1


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 0563fe91-c314-4d1c-883c-306211b10e07
📥 Commits

Reviewing files that changed from the base of the PR and between 00381be and bec5064.

📒 Files selected for processing (6)
  • src/main/ipc/pty/pane/absent-pane-owner.ts
  • src/main/ipc/pty/pane/stable-pane-absence-respawn.test.ts
  • src/main/runtime/runtime-durable-store-fixture.ts
  • src/main/runtime/terminal-intentional-stops.ts
  • tests/e2e/helpers/paired-terminal-parking-oracle.ts
  • tests/e2e/paired-runtime-retention-metrics.ts

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

await session.send('HeapProfiler.collectGarbage')
// Why not performance.memory: it is a cached, rounded figure that can predate the GC above.
const heapBytes = (await session.send('Runtime.getHeapUsage')).usedSize
await session.detach()

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.

🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

Detach the CDP session when sampling fails.

If either HeapProfiler.collectGarbage or Runtime.getHeapUsage rejects, execution skips session.detach(). The sampler then leaves its CDP session attached while the oracle handles the failure. Keep the error propagation, but move session.detach() into a finally block.

@Jinwoo-H
Jinwoo-H merged commit 7154e90 into main Oct 12, 2026
37 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