Repository navigation
A pane closed while its terminal starts stays closed (dark, layout-owner build only) - #30560
Conversation
… late (dark, layout-owner build only)
📝 Walkthrough
Priority: ⬇️ Low Merge Risk: 🔵 Low · up to
|
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
983a00e9-e2e1-4268-b982-60fc2e69420b
📒 Files selected for processing: 5
src/main/persistence-closed-pane-binding-fence.test.tssrc/main/persistence/loading-store/pty-binding-refusals.tssrc/main/persistence/terminal-topology/closed-pane-binding-fence.test.tssrc/main/persistence/terminal-topology/closed-pane-binding-fence.tssrc/main/persistence/terminal-topology/terminal-topology-commit.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.
| type SessionsRead = { | ||
| hostIds: () => readonly ExecutionHostId[] | ||
| getSession: (hostId: ExecutionHostId) => WorkspaceSessionState | null | undefined | ||
| } | ||
|
|
||
| type Fence = { sessions: SessionsRead; fences: boolean } | ||
|
|
||
| function paneKeysIn( | ||
| hostIds: readonly ExecutionHostId[], | ||
| getSession: SessionsRead['getSession'] | ||
| ): Set<string> { | ||
| const keys = new Set<string>() | ||
| for (const hostId of hostIds) { | ||
| const layouts = getSession(hostId)?.terminalLayoutsByTabId ?? {} | ||
| for (const [tabId, layout] of Object.entries(layouts)) { | ||
| if (layout?.root) { | ||
| for (const leafId of collectLayoutLeafIdsInOrder(layout.root)) { | ||
| keys.add(`${tabId}:${leafId}`) | ||
| } | ||
| } | ||
| } | ||
| } | ||
| return keys | ||
| } |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
sed -n '1,115p' src/main/persistence/loading-store/pty-binding-refusals.ts
sed -n '130,215p' src/main/persistence/loading-store/pty-binding-persistence.ts
sed -n '35,95p' src/main/runtime/runtime-layout-apply.ts
sed -n '48,85p' src/main/persistence/terminal-topology/closed-pane-binding-fence.test.tsRepository: stablyai/orca
Length of output: 12394
🏁 Script executed:
set -e
printf '%s\n' '--- host resolution and refusal/fence references ---'
rg -n -F --glob '*.ts' -e 'function resolveHostId' -e 'const resolveHostId' -e 'resolveHostId(' -e 'ptyBindingIsRefused(' -e 'isClosedPaneFenced(' -e 'fencedIfLayoutOwner(' -e 'partitionsFence(' src/main | head -240
printf '%s\n' '--- complete fence implementation ---'
nl -ba src/main/persistence/terminal-topology/closed-pane-binding-fence.ts | sed -n '1,180p'
printf '%s\n' '--- persistence host-resolution context ---'
rg -n -F --glob '*.ts' -e 'resolveHostId' src/main/persistence/loading-store src/main | head -80
nl -ba src/main/persistence/loading-store/pty-binding-persistence.ts | sed -n '1,90p'
printf '%s\n' '--- refusal-focused tests and callers ---'
rg -n -F --glob '*.test.ts' -e 'different host' -e 'legacy relay' -e 'SSH' -e 'ptyBindingIsRefused' -e 'isClosedPaneFenced' src/main/persistence | head -160
printf '%s\n' '--- relevant current/base diff paths ---'
git diff --no-ext-diff --unified=20 51530bb86cb2f799fb5162840654c64d9ff48fb2 e7691636da67006737d83f6bb67b78315b2324f2 -- src/main/persistence/terminal-topology/closed-pane-binding-fence.ts src/main/persistence/loading-store/pty-binding-refusals.ts src/main/persistence/loading-store/pty-binding-persistence.tsRepository: stablyai/orca
Length of output: 44209
🏁 Script executed:
set -e
printf '%s\n' '--- resolveHostId and partition operations ---'
nl -ba src/main/persistence/loading-store/session-host-partitions.ts | sed -n '1,155p'
printf '%s\n' '--- topology fence producer ---'
nl -ba src/main/persistence/terminal-topology/terminal-topology-commit.ts | sed -n '1,175p'
printf '%s\n' '--- binding callers and host arguments ---'
rg -n -F --glob '*.ts' -e 'persistPtyBinding(' -e 'mayCreate: false' -e 'origin:' src/main | head -240
printf '%s\n' '--- focused binding refusal tests ---'
rg -n -F --glob '*.test.ts' -e 'pty-binding-refusals' -e 'binding is refused' -e 'late' -e 'mayCreate' -e 'legacy' src/main/persistence/loading-store src/main/persistence/terminal-topology | head -220Repository: stablyai/orca
Length of output: 41528
🏁 Script executed:
set -e
printf '%s\n' '--- focused fence persistence tests ---'
nl -ba src/main/persistence/persistence-closed-pane-binding-fence.test.ts | sed -n '1,260p'
printf '%s\n' '--- fence unit tests after the supplied excerpt ---'
nl -ba src/main/persistence/terminal-topology/closed-pane-binding-fence.test.ts | sed -n '1,145p'
printf '%s\n' '--- partition type and binding persistence continuation ---'
rg -n -F --glob '*.ts' -e 'export type TerminalSessionPartition' -e 'type TerminalSessionPartition' src
nl -ba src/main/persistence/loading-store/pty-binding-persistence.ts | sed -n '145,190p'Repository: stablyai/orca
Length of output: 7638
Scope fence entries by host, but check all host partitions during refusal.
A close in one host can record tabId:leafId, and an admission in another partition can remove that shared entry. A later binding in the closed partition can then pass isClosedPaneFenced and recreate the pane.
Do not limit refusal lookup to the binding host. Legacy relay reattach can place the binding in a different host from the close, so the lookup must check the scoped fence for every partition.
Suggested fix
diff --git a/src/main/persistence/terminal-topology/closed-pane-binding-fence.ts b/src/main/persistence/terminal-topology/closed-pane-binding-fence.ts
@@
const closedAtByPaneKey = new Map<string, number>()
+function scopedPaneKey(hostId: ExecutionHostId, paneKey: string): string {
+ return JSON.stringify([hostId, paneKey])
+}
+
@@
- keys.add(`${tabId}:${leafId}`)
+ keys.add(scopedPaneKey(hostId, `${tabId}:${leafId}`))
@@
-export function isClosedPaneFenced(paneKey: string): boolean {
- const closedAt = closedAtByPaneKey.get(paneKey)
+export function isClosedPaneFenced(hostId: ExecutionHostId, paneKey: string): boolean {
+ const closedAt = closedAtByPaneKey.get(scopedPaneKey(hostId, paneKey))
if (closedAt === undefined) {
return false
}
if (Date.now() - closedAt >= CLOSED_PANE_BINDING_FENCE_MS) {
- closedAtByPaneKey.delete(paneKey)
+ closedAtByPaneKey.delete(scopedPaneKey(hostId, paneKey))
return false
}
return true
}
diff --git a/src/main/persistence/loading-store/pty-binding-refusals.ts b/src/main/persistence/loading-store/pty-binding-refusals.ts
@@
- isClosedPaneFenced(paneKey)
+ partitions.some(({ hostId }) => isClosedPaneFenced(hostId, paneKey))
ELI5
In the build where the background process owns the window layout (off in every shipped build), closing a terminal pane while its shell was still starting could bring the pane right back. This change makes the background process remember, for a few minutes, which panes it closed, and refuse a late "this pane's terminal has started" record for one of them. The closed pane stays closed, and the terminal that started too late is shut down.
What Changed
closed-pane-binding-fence.ts. It compares the pane ids before and after each terminal-layout commit interminal-topology-commit.ts: pane closes, tab closes, window close and create commands, admissions, and take-backs.pty-binding-refusals.ts, next to the existing closed-tab check.Why
Pane ids are never reused, so a longer window refuses nothing real; the limit only bounds memory.
Linked Issue
Internal layout-owner follow-up (no issue).
Visual Proof
N/A: no UI change, and the change is in a build that is not shipped.
Testing
Failing first:
persistence-closed-pane-binding-fence.test.tsruns against a real store with the layout-owner switch on. With the record not wired in, these four cases fail on the base commit:All pass with the fix. Three more cases pass on both: a pane created again under the same id (by the background process or the window) binds as usual, and after 5 minutes a late save behaves as before.
closed-pane-binding-fence.test.tscovers two rules: a write in another partition that keeps the pane does not lift its record, and a rolled-back write puts the records back.Gates:
pnpm tcpasses. The changed-code quality gate, layout-writer ratchets (212 main, 657 renderer), max-lines ratchet, and anti-slop audit all pass. Related store tests: 23 files, 147 tests pass.Full test suite (this change touches code shipped builds load): 16 files failed locally. 13 fail the same way on the base commit; they are local-environment failures in packaging, browser-manager and dev-rebuild tests. The other 3 pass when run alone, so they were load flakes.
Switch-off bundle: I compared an unminified build of the base with this head. Preload and renderer are identical apart from chunk hashes. In main, everything that differs:
fencedIfLayoutOwnerthat returns the mutation it was given, so the four commit paths pass the same mutation as before. The order of evaluation is unchanged and the mutation is still built and run when it was before.partitionsFenceandlayoutCommandFence, built only inside a callback that is never called with the switch off;The record, the refusal check and the pane-id comparison are compiled out entirely.
Layout save-divergence detector, switch on, with the same 6 specs before and after:
terminal-pane-close-layout-consistency,terminal-parked-cli-split,terminal-cli-split-closed-before-mount,golden-core-flows,terminal-closed-pane-quit-relaunch,cli-first-worktree-single-terminal. Base: 13 passed, 0 reports. Head: 13 passed, 0 reports.macOS only (local). No platform-specific code.
I manually tested these changes locally
Automated tests added/updated, or explained why not below
Review
An independent fresh review found five issues: a record lifted by a write that only kept the pane, a rollback that did not restore records, missing tests for three close paths, test isolation, and the length of the window. All five are fixed in this commit, and a re-review of the fixes found none left.
Agent skill upstream boundary
Notes
SSH: the record is keyed by the pane, not by partition, so a late save that lands in a different partition than the close is refused too. No wire change, no new layout command or field. Shipped builds: the new check and the record are compiled out; see the bundle comparison.
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)