Repository navigation
fix: a tab close by the handle a split returned finds the new pane (dark, layout-owner build only) - #30786
Conversation
… a tab close by a split's handle finds it (dark, layout-owner build only) Co-Authored-By: Claude <[email protected]>
📝 Walkthrough
Priority: ⬇️ Low Severity of issue fixed: Low Merge Risk: 🔵 Low · up to
|
…r yet" terminal list Co-Authored-By: Claude <[email protected]>
…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]>
…yout-owner build only) Co-Authored-By: Claude <[email protected]>
…-stale # Conflicts: # .github/workflows/pr.yml # config/scripts/pr-layout-owner-switch-on-route.mjs
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to GitHub limitations.
🟡 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 winSelect 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 itsterminalLayoutsByTabIdhas no matching PTY leaf. Relisting then does nothing, and a live split-handle close can still throwterminal_handle_stale.Pass all tab holders to
relistPaneMainBindsand 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
📒 Files selected for processing: 2
.github/workflows/pr.ymlconfig/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.
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 splitreturns a handle for the new pane. When main ran the split itself, aterminal close-tabwith that handle could fail withterminal_handle_stale. Moments later the same close worked. CI hit this interminal-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):
resolvePtyTabCloseSurfaceAuthority). It found nothing and refused withterminal_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, inlayout-owner-close-relisting.ts. With the switch on, when the list does not show the terminal, main checks its own state: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:
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.Why
Two earlier versions each fixed only one way the list lags:
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:
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:terminal_handle_staleand pass here;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.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.
Agent skill upstream boundary
Notes
Switch-off bundle check: I built main and this head with
minify: falseand compared them, with hashed file names normalized. Shipped behaviour is unchanged.main/index.js: only the embedded source commit 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
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)