Repository navigation
Main repairs a terminal stored in two panes once at startup (dark, layout-owner build only) - #30178
Conversation
…t startup, after moving the dropped pane's owners (dark, layout-owner build only)
📝 Walkthrough
Priority: ➖ Normal Merge Risk: 🟡 Moderate · 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:
565611ee-edfd-4bd3-8cf5-db4a8213806d
📒 Files selected for processing: 9
src/main/persistence/terminal-topology/duplicate-pty-pane-repair.test.tssrc/main/persistence/terminal-topology/duplicate-pty-pane-repair.tssrc/main/persistence/terminal-topology/layout-command-persistence.tssrc/main/persistence/terminal-topology/terminal-topology-commit.tssrc/main/runtime/moved-pane-owner-rekey.tssrc/main/runtime/orca-runtime-tests/mobile-session-tabs-duplicate-pty-repair.spec.tssrc/main/runtime/orca-runtime.test.tssrc/main/runtime/runtime-terminal-orphan-adoption-duplicate-pty.test.tssrc/main/startup/main-process-runtime-service.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 2 remain after this review.
…nd skips the write when an owner move fails (dark, layout-owner build only)
…ce untouched (dark, layout-owner build only)
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:
a3e06f63-c33b-4aaf-9d0d-17dca582389c
📒 Files selected for processing: 6
src/main/agent-hooks/server/server-authority-aliases.tssrc/main/persistence/terminal-topology/duplicate-pty-pane-repair.test.tssrc/main/persistence/terminal-topology/duplicate-pty-pane-repair.tssrc/main/persistence/terminal-topology/layout-command-persistence.tssrc/main/persistence/terminal-topology/terminal-leaf-move.tssrc/main/runtime/moved-pane-owner-rekey.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 2 remain after this review.
| if (owner && owner.tabId !== move.tabId) { | ||
| return false |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win
Reject a same-tab authority owner on a third leaf.
If the dropped pane aliases to a different leaf in the same tab, this guard permits the transfer. transferPaneAuthority then moves that third leaf’s agent status to the retained leaf, although the repair removes only removedLeafId. Accept an existing owner only when its key is the dropped or retained pane key; otherwise leave its ownership unchanged.
ELI5
Sometimes a saved terminal tab ends up describing one terminal as two side-by-side panes. Every time Orca opens, it quietly fixes this in memory, but it never fixes the saved copy, so the bad layout stays on disk forever. In the build where the main process owns the layout, this change has main fix the saved copy once at startup. Before it does, it moves everything that was filed under the extra pane (the agent status and any orchestration record) over to the pane that keeps the terminal. Only then does it write the fixed layout to disk.
What Changed
Before (layout-owner build): a tab stored with one terminal in two panes kept that shape on disk across every restart. The window showed one pane because it repairs on load, but anything that reads the stored layout directly saw two: recovering an orphaned terminal for that pane failed with
terminal_orphan_competing_owner, and the phone's list of a desktop with no window open showed the terminal twice.After (layout-owner build): the first startup with a running runtime rewrites the stored tab to one pane per terminal. The disk shows one pane right after launch and after quit; orphan recovery replays the kept pane; the phone list shows one row.
Mechanism:
planDuplicatePtyPaneRepairruns the existing one-pane-per-terminal repair (normalizeTerminalLayoutPtyOwnership) over each stored tab and lists the pane transfers it implies (dropped pane, kept pane, terminal id). It skips paired-server partitions (runtime:), which are display copies that their own server repairs.repairDuplicatePtyPanes(transfer)runs as one durable write: it callstransferfor every dropped pane first, then writes the repaired partitions. If an owner move fails, nothing is written and the next start tries again. A frozen or imported Store does nothing.rekeyMovedPaneOwners): its body is now a sharedrekeyPaneOwners(from pane, to pane)that both the move and the repair call. It moves agent status (transferPaneAuthority) and the orchestration row (rekeyWorkerTerminalResourcePaneKey). It still logs a failed step and carries on, as before, and now also reports it; the move ignores the report, and the repair skips its write.With the switch off nothing calls the new code: shipped builds keep the duplicate on disk exactly as today.
Why
The window already repairs this on every load, but its save cannot reach disk: main's save rule keeps its stored pane tree when a window save without a newer revision changes the pane set. Repairing in main, once, at the place that owns the stored tree, fixes every reader at once, instead of teaching each reader that skips the load repair (orphan recovery, the phone list) to repair again.
Alternatives considered:
setWorkspaceSession: that path rebases the pane tree back to the stored one, which is the bug. The repair uses the same partition write as layout commands instead.Linked Issue
Internal layout-owner work (phase E2-6, prerequisite P2).
Visual Proof
N/A: no UI change. With the switch off nothing runs; with it on, the window already showed one pane and now the stored layout matches it. Disk evidence is below.
Testing
New tests (failing first: with the repair stubbed to a no-op, the two runtime-load cases failed with
transferPaneAuthoritycalled 0 times):duplicate-pty-pane-repair.test.ts(real Store on SQLite; the four record, owner-rule and failure cases were added in round 2 and all failed against the first commit): a runtime start moves the dropped pane's agent status and orchestration row, and the spy records that disk still held both panes at the moment of the transfer, then disk holds one pane. A load with no runtime leaves the stored layouts byte-identical and runs no transfer; a later runtime start transfers once and writes the session domain once. A frozen Store and an imported Store neither transfer nor write. A second start is a no-op (no transfer, no write). A terminal another tab also binds is repaired without moving its owner, matching the window's rule. The dropped pane's sleep record, three read marks, incarnation and SSH lease end on the kept pane, and the kept pane's own incarnation wins over the dropped one. A status owner already in another tab is not moved and its records stay. A failing orchestration rekey leaves disk unchanged. A frozen WSL-move workspace is not repaired.runtime-terminal-orphan-adoption-duplicate-pty.test.ts: the stored duplicate is refused asterminal_orphan_competing_owner; the repaired tree replays the kept pane.mobile-session-tabs-duplicate-pty-repair.spec.ts: the windowless phone list shows 2 terminal rows for the stored duplicate and 1 after the repair.Gates (macOS):
pnpm tcpass;pnpm run check:code-quality:changed0 new findings; oxlint on changed files clean;pnpm run audit:anti-sloppass;check:layout-writer-ratchets,check:focus-read-ratchet,check:max-lines-ratchetpass. Vitest (4 workers) oversrc/main/persistence/terminal-topology,src/main/startup,src/main/agent-hooks, leaf-move, orphan adoption andorca-runtime.test.ts: 3677 passed, 1 failed (preserves existing badgeColor on runtime cloneRepo folder->git dedupe upgrade, a macOS/private/vartemp path mismatch that fails the same way on main).End to end (
terminal-duplicate-pty-renderer-reveal.spec.ts, plus a local copy that reads the profile database after each step):Switch-off bundle (unminified, main vs this branch): renderer and preload identical apart from file hashes and the commit stamp. Main bundle changes in two places:
repairDuplicatePtyPanes, and the hook server'sresolvePaneAuthorityOwner.rekeyMovedPaneOwnersnow calls the sharedrekeyPaneOwnerswith the same pane keys, terminal id and order of steps; it now also returns whether both steps succeeded, which the move ignores.rekeyMovedLeafProfileRecordsnow calls the sharedrekeyPaneProfileRecordswith the same keys; a moved SSH lease also gets its leaf id written, which is the same leaf id it already had.moveRecordKeygained akeepTargetoption that defaults off. The pane move behaves the same.AI Disclosure
Review
Agent skill upstream boundary
Notes
runtime:) partitions are display copies and are not repaired here.orcad) does not run this repair yet. Its startup file sits at the 300-line limit, so wiring it needs a small extraction first. Until then a paired server keeps its own stored duplicate, as it does today.layout.applyfield or command, so nothing for the flip capability list.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)