Skip to content

fix: a tab close by the handle a split returned finds the new pane (dark, layout-owner build only) - #30786

Merged
Jinwoo-H merged 6 commits into
mainfrom
e2-6/split-handle-not-stale
Oct 19, 2026
Merged

Jinwoo-H merged 6 commits into
mainfrom
e2-6/split-handle-not-stale

Conversation

@Jinwoo-H

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

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​272 $\color{#cf222e}{\Huge{\mathbf{−}}}$​6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​266
Prod 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​83 $\color{#cf222e}{\Huge{\mathbf{−}}}$​1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​82

ELI5

In the test build where the main process owns the pane layout, a script that split a terminal and then closed that tab using the new pane's handle could be told "terminal handle stale", even though the pane was there. The close was checking the window's list of panes, and that list can lag behind main for a moment. Now, in that build only, the close falls back on main's own record of the pane.

What Changed

Before (layout-owner build only): orca terminal split returns a handle for the new pane. When main ran the split itself, a terminal close-tab with that handle could fail with terminal_handle_stale. Moments later the same close worked. CI hit this in terminal-tab-close-restart-persistence.spec.ts:26.

After: the close works whenever main's layout still binds that pane to that terminal.

How it went wrong (seen in app logs captured in CI):

  1. Main adds the new pane to its layout, starts its terminal, binds the terminal to the pane, and adds the pane to its list of panes for clients.
  2. The window sends main its own list of panes, which main takes as current. That list can lag main in three ways:
    • it was built before main added the pane, so the pane is missing;
    • it was built after main added the pane but before the terminal was bound, so the pane has no terminal;
    • the window has drawn the pane but not mounted it yet, and mounted panes are all it lists.
  3. When a lagging list arrives after main's own update, main loses its own listing of the new terminal.
  4. A close by the new handle checks that list for the terminal (resolvePtyTabCloseSurfaceAuthority). It found nothing and refused with terminal_handle_stale (mobile-session-lifecycle-close-adjudication.ts:122).

The fix is in resolvePtyTabCloseSurfaceAuthority (src/main/runtime/terminal/view/mobile-terminal-surface.ts), plus a new helper, relistPaneMainBinds, in layout-owner-close-relisting.ts. With the switch on, when the list does not show the terminal, main checks its own state:

  • the handle's live terminal matches the close's terminal and its process instance;
  • main's layout for the tab, read from the tab's host, still holds the pane and binds it to that terminal.

If all of that holds, main re-adds its own listing for the pane, without notifying clients, and the close goes ahead. If main no longer holds the pane, the close still refuses. With the switch off, this code is compiled out.

Also in this PR:

  • The spec now keeps polling when the host answers "can't answer yet" (terminal_surface_ownership_unavailable). The host gives that answer when a pane's terminal has started but is not yet bound to the pane. It is the same fix test(e2e): mount-authority spec polls through the host's "can't answer yet" terminal list #30743 made for another spec. One CI failure was this refusal, at the spec's first terminal list, before any split.
  • The spec is added to the layout-owner CI job's list.

Why

Two earlier versions each fixed only one way the list lags:

  • making the window list main's not-yet-mounted panes still lost the race when a list was built before main bound the terminal;
  • filling the terminal in from main's binding when the window's list arrives did not help when the list was built before main added the pane.

An earlier version that made the split wait for the window's list could stall up to 10 seconds while the window is minimized. Under this build main owns the layout and the binding, so the close's check now relies on main's own record, which covers all three lags at the point that needs it. Only a close that names an exact handle, terminal, process instance and workspace triggers it, so nothing on the sync path republishes in a loop.

Not the same cause as #30745, where a test helper closed panes inside the window without telling main.

Known minor gaps, both switch-on only:

  • The close reads its list of selected panes before the re-listing, so if the window's list drops the pane during that close, a client's selection of the new pane can outlive the close.
  • If a terminal is listed under two tabs at once, the re-listing writes an update that changes nothing, and the close refuses as it does today.

Linked Issue

N/A (internal layout-owner work, no issue)

Visual Proof

N/A: nothing is drawn differently. This changes only how main checks a close by handle, in the layout-owner test build.

Testing

  • New unit test close-by-split-handle-layout-owner.test.ts:

    • the two cases where the window's list lags (pane with no terminal yet, no new pane) fail on main with terminal_handle_stale and pass here;
    • a case where main has dropped the pane still refuses.
  • CI, switch on: 10 of 10 runs of the spec on this head in throwaway PR Test-only trace run (do not merge) #30799 (closed, not merged), run https://github.com/stablyai/orca/actions/runs/39302756357. 4 of the 10 runs took main's own split path. The previous head also passed 10 of 10 (run 39298967158). Before the fix, 1 of 10 failed (run 39290936288).

  • e2e, switch on, locally with 2 workers, 3 runs each: terminal-tab-close-restart-persistence, terminal-cli-split-closed-before-mount, terminal-parked-cli-split: 12 of 12 passed.

  • e2e, switch off, locally: the spec passed 3 of 3.

  • pnpm tc: pass. check:code-quality:changed: pass. Layout-writer ratchet, focus-read ratchet, anti-slop audit: pass.

  • Full vitest suite (--maxWorkers=4): 61 failures in 13 files.

    • 12 of those files fail on main too, with the same 60 failures when rerun on main and on an earlier head of this branch. They are environment failures on this machine (browser manager, process-host rebuild, forked-child paths, and others), none in code this PR touches.
    • The 13th, daemon-init-provider-installation, passed when rerun on both main and this branch.
  • Save-divergence detector, switch on, same 3 specs: main 0 reports, this branch 0 reports. A positive-control spec produced 2 reports on a switch-on build of an earlier head, so the detector was on.

  • I manually tested these changes locally

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

AI Disclosure

Review

Each design and each fix round got its own adversarial review, five in all.

  • The first two designs were replaced after review.
  • The binding fill was replaced because it missed a list built before main adds the pane.
  • The review of the current design found no blockers. On its main finding (the re-added listing could carry a wrong pane layout to phones), the re-listing now notifies no clients. Its two minor findings are listed under Why.

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

Switch-off bundle check: I built main and this head with minify: false and compared them, with hashed file names normalized. Shipped behaviour is unchanged.

  • main/index.js: only the embedded source commit differs.
  • One renderer asset: only the embedded source commit differs.
  • Every other renderer file: identical apart from its hash name.
  • Renderer manifest: only the order of one hash-named entry differs.
  • main/index.js.map: lists the new helper file and the edited source. The helper's code is removed from the built output, because it is only reached when the switch is on.

Remote compatibility: nothing changes on the wire.

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 tab close by a split's handle finds it (dark, layout-owner build only)

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

coderabbitai Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

📝 Walkthrough

When main owns layout, terminal surface resolution can relist a pane for an authorized PTY when no surface exists. New tests cover split-handle closes when the window’s terminal list lags behind main, and reject a close as stale when main no longer holds the pane. The restart-persistence E2E test now polls fresh terminal inventories. The layout-owner E2E job includes additional specs.

Priority: ⬇️ Low

Severity of issue fixed: Low

Merge Risk: 🔵 Low · up to a1d37

In a narrow legacy multi-partition case, closing a live split handle may fail with a stale-handle error. This is a bounded close-path risk; select the holder that owns the layout.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 10 functions across 8 files. (1 skipped: … 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 identifies the main fix: closing a split terminal tab by its returned handle in the layout-owner build. It is somewhat awkwardly phrased but remains specific and related to the chang…
Description check Passed The description is complete and directly matches the changes. It includes the user-facing behavior, technical mechanism, rationale, testing results, known gaps, compatibility notes, visual-proof ratio…
Linked Issues check Passed Issue #30743 is closed, so it supplies historical context only. No active directly linked issue remains. Therefore, this pull request has no linked-issue coding requirements to assess.
Out of Scope Changes check Passed The changes remain within the stated pull request scope. The relisting helper and close-path update address stale split-handle closes. The unit tests, e2e polling update, and layout-owner CI registrat…
Full details: Title check

Explanation

The title clearly identifies the main fix: closing a split terminal tab by its returned handle in the layout-owner build. It is somewhat awkwardly phrased but remains specific and related to the changes.

Full details: Description check

Explanation

The description is complete and directly matches the changes. It includes the user-facing behavior, technical mechanism, rationale, testing results, known gaps, compatibility notes, visual-proof rationale, and completed checklist items. The missing issue link is explicitly explained as internal layout-owner work, and the template permits that exception for maintainers.

Full details: Out of Scope Changes check

Explanation

The changes remain within the stated pull request scope. The relisting helper and close-path update address stale split-handle closes. The unit tests, e2e polling update, and layout-owner CI registration provide focused coverage and execution for that behavior. No unrelated change is established.

Full details: Docstring Coverage

Explanation

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

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

  • 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.

E2E Test and others added 4 commits October 19, 2026 13:50
…keeps main's terminal (dark, layout-owner build only)

Co-Authored-By: Claude <[email protected]>
…n's own record of the pane (dark, layout-owner build only)

Replaces the window-side listing and the binding fill: the window's list lags main in three
ways (built before main wrote the pane, from it before the binding, or before the window mounts
it), and only main's own layout answers all three.

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

# Conflicts:
#	.github/workflows/pr.yml
#	config/scripts/pr-layout-owner-switch-on-route.mjs

@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 · Select the layout-owning holder before relisting. · mobile-terminal-surface.ts:142-150

src/main/runtime/terminal/view/mobile-terminal-surface.ts:142-150
🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

Select the layout-owning holder before relisting.

When the same tab exists in multiple partitions, [0] selects the routed holder, not the holder that owns the layout. A holder can still list the tab while its terminalLayoutsByTabId has no matching PTY leaf. Relisting then does nothing, and a live split-handle close can still throw terminal_handle_stale.

Pass all tab holders to relistPaneMainBinds and select the holder whose layout contains the exact PTY, leaf, and incarnation.

Suggested fix
diff --git a/src/main/runtime/terminal/view/layout-owner-close-relisting.ts b/src/main/runtime/terminal/view/layout-owner-close-relisting.ts
@@
   pty: RuntimePtyWorktreeRecord | undefined,
   host: {
-    hostId: (tabId: string) => ExecutionHostId | undefined
+    hostIds: (tabId: string) => readonly ExecutionHostId[]
     session: (hostId: ExecutionHostId) => WorkspaceSessionState | null | undefined
     relist: (pty: RuntimePtyWorktreeRecord, pane: RelistedPane) => void
   }
@@
   }
   const pane = parsePaneKey(pty.paneKey ?? '')
-  const hostId = pane && pane.tabId === pty.tabId ? host.hostId(pane.tabId) : undefined
-  if (!pane || !hostId) {
+  if (!pane || pane.tabId !== pty.tabId) {
     return
   }
+  const hostId = host.hostIds(pane.tabId).find((candidate) => {
+    const session = host.session(candidate)
+    const layout = session?.terminalLayoutsByTabId?.[pane.tabId]
+    const incarnationId =
+      session?.terminalPtyIncarnationsByPaneKey?.[makePaneKey(pane.tabId, pane.leafId)]
+    return (
+      layout?.ptyIdsByLeafId?.[pane.leafId] === pty.ptyId &&
+      terminalLayoutContainsLeaf(layout.root, pane.leafId) &&
+      (!incarnationId || incarnationId === pty.incarnationId)
+    )
+  })
+  if (!hostId) {
+    return
+  }
   const session = host.session(hostId)
   const layout = session?.terminalLayoutsByTabId?.[pane.tabId]
diff --git a/src/main/runtime/terminal/view/mobile-terminal-surface.ts b/src/main/runtime/terminal/view/mobile-terminal-surface.ts
@@
-        hostId: (tabId) => this.getWorkspaceSessionHostIdsForTab(authority.worktreeId, tabId)[0],
+        hostIds: (tabId) =>
+          this.getWorkspaceSessionHostIdsForTab(authority.worktreeId, tabId),

ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: d24529fd-e08a-4071-ad00-d2b881ad7469
📥 Commits

Reviewing files that changed from the base of the PR and between 8943499 and a1d3781.

📒 Files selected for processing: 2
  • .github/workflows/pr.yml
  • config/scripts/pr-layout-owner-switch-on-route.mjs

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

@Jinwoo-H
Jinwoo-H merged commit e9fa0cf into main Oct 19, 2026
139 of 143 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