Repository navigation
feat(layout): record the window's terminal tab close through main behind the layout-owner build switch - #29327
Conversation
… through main behind ORCA_LAYOUT_OWNER A build made with ORCA_LAYOUT_OWNER=main registers layout.apply: main applies the window's layout command to the stored partition through the shared applyLayoutCommand, minting new ids. A user split then waits for main's answer and mounts the pane id main minted. Every other build substitutes 'window', so neither branch is compiled in.
A load-then-save rewrite also normalizes records the command never touched. The command's effect is now the diff between the save before and after it, written onto the stored partition record by record. A split whose main reply says a paired server holds the tab splits as today.
…d partitions reload to the command's result
…CA_LAYOUT_OWNER In a layout-owner build the window's pane close, title change and equalize go through layout.apply and the window shows main's answer. A window pane close keeps the legacy close's rules: the tab's last pane is refused, a pane restarted since main read the close is left alone, every partition holding the tab closes it, and the tab's remote session id follows the remaining pane. The rules sit behind a command field only layout.apply sets.
…ORCA_LAYOUT_OWNER Claude-Session: 10569c9a-a0a1-4fc9-8469-0edfb7aed125
Claude-Session: 10569c9a-a0a1-4fc9-8469-0edfb7aed125
…e drops main cannot take Claude-Session: 10569c9a-a0a1-4fc9-8469-0edfb7aed125
…oday Claude-Session: 10569c9a-a0a1-4fc9-8469-0edfb7aed125
…de-up profile state Claude-Session: 10569c9a-a0a1-4fc9-8469-0edfb7aed125
…row names a paired server The split switch point asked which host to route to with a helper that falls back to the focused server, so a focused server could claim a workspace whose row names no owner. Use the same owner test the tab mirror uses.
…yout/c1b-pane-ops # Conflicts: # src/renderer/src/components/terminal-pane/terminal-pane-split-through-layout-owner.test.ts # src/renderer/src/components/terminal-pane/terminal-pane-split-through-layout-owner.ts
…/c1b2-pane-gestures
…ed or failed splits and moves, ratios during a move, release guard - A pane main saved but the window could not mount (source pane or manager gone during the await) is closed again in main, so it does not come back on restart. - A split main refuses because its copy lacks the workspace, tab or pane, or a failed call, splits as today; a refused or failed move moves as today. - Divider ratios committed while a move is in flight wait for the window's move, then go to main. - The orcad bundle gets the ORCA_LAYOUT_OWNER define when the switch is on. - Packaging and the orcad template refuse ORCA_LAYOUT_OWNER=main and any output a dark build marked. - workspace-layout-record-patch.ts: no non-null assertions; plain comment for the map depth.
…throws, not just for splits - sendPaneCommandToLayoutOwner runs asToday for workspace/tab/pane_not_found and a thrown call, so close, rename and equalize fall back like split and move; a handler that throws no longer runs the fallback too. - A close main refuses as its last pane, while this window still has others, closes as today. - A move whose local step throws still releases held divider ratios. - Drop the orcad output marker: nothing read it; the template build refuses the switch itself.
# Conflicts: # src/main/persistence/loading-store/pty-binding-persistence.ts # src/main/persistence/terminal-topology/terminal-layout-apply.test.ts # src/main/persistence/terminal-topology/terminal-pane-admission.ts # src/main/runtime/orca-runtime.ts # src/main/runtime/rpc/methods/workspace-layout-apply.test.ts # src/renderer/src/components/terminal-pane/terminal-pane-split-with-inherited-cwd.test.ts # src/renderer/src/components/terminal-pane/terminal-pane-split-with-inherited-cwd.ts # src/shared/rpc-contract/workspace-layout-params.ts # src/shared/workspace-layout/workspace-layout-record-patch.test.ts # src/shared/workspace-layout/workspace-layout-record-patch.ts
… layout-owner files
…1b2-pane-gestures
…1c-dark-followups
…e checkout fixture
…ut.apply command touches its claim A legacy terminal row the load folds into a tab-bar tab stays stored as is. Closing the tab it repeats, or giving it a tab-bar entry by moving it, let the next load resolve the claim the other way: the row came back or took the other tab's terminal. Such a command now writes the row as the load had it; every other record still stays as stored.
…t.apply Group sizes have no tab, so they go to the workspace's routed partition.
…rminal pane folder Tab groups send through it too; it now also acts as today when main lacks the group.
…s, through main behind ORCA_LAYOUT_OWNER A tab drop and Move Tab to Split wait for main's answer and then show main's placement, with main's new group id; group divider sizes are drawn while dragging and saved by main when the drag ends. Closing an empty group needs no command: main never holds an empty group.
- Read a folded row's terminals with the loader's own claim rule, so rows sharing only an SSH session are covered too, and drop the row's remote session entry with it. - The record-patch test allows a folded row only in its loaded form. - A tab drag ends at once; main's answer shows the move after. - A lone group main moved whole is placed so only when this window's group is lone too.
A row's remote session entry is carried through load and save unchanged, so adopting it from the load changed nothing (the earlier commit's message overstated it).
closeTabs can now record each terminal tab it closes, or does not find, as closed for the given reason (pruned as a partition's records are), so a start that commits later is refused, as today's close records it. layout.apply takes one tab's close with the window's reason: main forces it in every holder partition, marks a user close's launches, stops no terminal (the window already did, sparing any another tab shares), and leaves a workspace it lacks to today's close. A sibling the load supplied that the close only renumbered is no longer written.
…A_LAYOUT_OWNER The window still closes the tab and stops its terminals itself; main records the close through layout.apply instead of the close intent, which stays for paired servers and when main lacks the workspace.
- The window's close sends through a store-free sender, so the store no longer imports itself. - Main marks a user close's launches by the terminal's own id. - A recorded close prunes the whole partition's close records, as today, not one workspace's.
📝 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:
26fa1e1c-ea04-4021-ad22-d39cb6662196
📒 Files selected for processing: 17
src/main/persistence/terminal-topology/terminal-layout-apply.test.tssrc/main/persistence/terminal-topology/terminal-pane-admission.tssrc/main/runtime/rpc/methods/workspace-layout-apply.test.tssrc/main/runtime/runtime-layout-apply.test.tssrc/main/runtime/runtime-layout-apply.tssrc/renderer/src/components/tab-group/tab-group-layout-owner-commands.tssrc/renderer/src/runtime/layout-apply-send.tssrc/renderer/src/runtime/layout-owner-command.tssrc/renderer/src/store/terminals/terminal-tab-close-layout-owner.test.tssrc/renderer/src/store/terminals/terminal-tab-close-layout-owner.tssrc/renderer/src/store/terminals/terminal-tab-close.tssrc/shared/rpc-contract/workspace-layout-params.tssrc/shared/workspace-layout/workspace-layout-command-types.tssrc/shared/workspace-layout/workspace-layout-commands.tssrc/shared/workspace-layout/workspace-layout-record-patch.test.tssrc/shared/workspace-layout/workspace-layout-record-patch.tssrc/shared/workspace-layout/workspace-layout-tab-commands.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review.
| export function closeTabs( | ||
| model: WorkspaceLayoutModel, | ||
| command: CommandOf<'closeTabs'>, | ||
| context?: LayoutContext | ||
| ): Applied { | ||
| let next = model | ||
| const closed: string[] = [] | ||
| const recorded: string[] = [] | ||
| const refused: RefusedClose[] = [] | ||
| const stopPtyIds: string[] = [] | ||
| for (const tabId of command.tabIds) { | ||
| const tab = findTab(next.workspaces[command.workspace]!, tabId) | ||
| if (!tab) { | ||
| closed.push(tabId) | ||
| recorded.push(tabId) |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
sed -n '95,165p' src/shared/workspace-layout/workspace-layout-tab-commands.ts
sed -n '15,75p' src/main/runtime/runtime-layout-apply.ts
rg -n 'closedTerminalTabTombstonesByTabId|recordClose' src/main/persistence/terminal-topology src/main/runtime | head -90Repository: stablyai/orca
Length of output: 9607
🏁 Script executed:
set -o pipefail
printf '%s\n' '--- changed diff ---'
git diff 991e2dda26360b71473c771bed0fad22dc321035..3c17f4576814507a33cb33ecad19ac5e2140c87b -- src/shared/workspace-layout/workspace-layout-tab-commands.ts src/main/runtime/runtime-layout-apply.ts src/main/persistence/terminal-topology/terminal-pane-admission.ts src/main/runtime/runtime-terminal-orphan-adoption.ts src/main/runtime/terminal-surface-close.ts | sed -n '1,300p'
printf '%s\n' '--- identity declarations/usages ---'
rg -n -F --glob '*.ts' -e 'function findTab' -e 'const findTab' -e 'findTab(' -e 'unifiedTabs' -e 'entityId' src/shared/workspace-layout src/main/persistence/terminal-topology src/main/runtime | sed -n '1,280p'
printf '%s\n' '--- tombstone consumer blocks ---'
sed -n '150,225p' src/main/runtime/runtime-terminal-orphan-adoption.ts
sed -n '250,315p' src/main/runtime/terminal-surface-close.ts
printf '%s\n' '--- close and partition tests ---'
sed -n '1,190p' src/main/persistence/terminal-topology/terminal-layout-apply.test.ts
sed -n '95,180p' src/main/runtime/orca-runtime-terminal-close-spill-partition.spec.tsRepository: stablyai/orca
Length of output: 42405
🏁 Script executed:
set -o pipefail
printf '%s\n' '--- loaded tab identity and lookup ---'
sed -n '1,135p' src/shared/workspace-layout/workspace-layout-load-tabs.ts
sed -n '1,75p' src/shared/workspace-layout/workspace-layout-model.ts
rg -n -F --glob '*.ts' -e 'function findTab' -e 'findTab =' -e 'findTab(' src/shared/workspace-layout | sed -n '1,100p'
printf '%s\n' '--- tombstone helper and claim identity ---'
rg -n -F --glob '*.ts' -e 'function hasClosedTerminalTabRecord' -e 'hasClosedTerminalTabRecord' -e 'tabId:' src/shared/closed-terminal-tab-tombstones.ts src/main/runtime/runtime-terminal-orphan-adoption.ts src/main/runtime/terminal-surface-close.ts | sed -n '1,180p'
sed -n '1,180p' src/shared/closed-terminal-tab-tombstones.ts
sed -n '1,120p' src/main/runtime/runtime-terminal-orphan-adoption.ts
printf '%s\n' '--- distinct-id fixtures and route tests ---'
rg -n -F --glob '*.ts' -e 'entityId:' -e 'id:' src/main/runtime/runtime-layout-apply.test.ts src/main/runtime/rpc/methods/workspace-layout-apply.test.ts src/main/runtime/orca-runtime-terminal-close-records.test.ts src/main/runtime/orca-runtime-terminal-close-spill-partition.spec.ts src/main/persistence/terminal-topology/terminal-topology-window-session-fixture.ts | sed -n '1,240p'
sed -n '1,145p' src/main/runtime/runtime-layout-apply.test.tsRepository: stablyai/orca
Length of output: 24057
🏁 Script executed:
set -o pipefail
printf '%s\n' '--- close context and command contract ---'
rg -n -F --glob '*.ts' -e 'export type LayoutContext' -e 'LayoutContext' -e 'type LayoutCommand' -e 'closeTabs' src/shared/workspace-layout src/main/persistence/terminal-topology | sed -n '1,220p'
sed -n '1,130p' src/shared/workspace-layout/workspace-layout-command-types.ts
printf '%s\n' '--- layout load/save identity path ---'
rg -n -F --glob '*.ts' -e 'loadTerminalTab(' -e 'closedTerminalTabs' -e 'closedTerminalTabTombstonesByTabId' src/shared/workspace-layout src/main/persistence/terminal-topology | sed -n '1,260p'
sed -n '1,150p' src/shared/workspace-layout/workspace-layout-load-workspace.ts
sed -n '1,150p' src/shared/workspace-layout/workspace-layout-save.ts
printf '%s\n' '--- existing ID normalization helpers ---'
rg -n -F --glob '*.ts' -e 'entry.id ===' -e 'tab.id ===' -e 'tab.entityId ===' -e 'entityId ===' src/shared src/main/runtime | sed -n '1,260p'Repository: stablyai/orca
Length of output: 41573
Use the terminal entity ID for missing-holder close records.
A window close uses the unified entry ID, but a partition without that entry loads the terminal row with its entity ID. The new missing-tab branch then stores the entry ID as the tombstone key. Orphan adoption checks the entity ID, so it can miss the tombstone and adopt a late PTY. The entry-ID record is also a spurious tombstone.
Carry the canonical entity ID already resolved in runtime-layout-apply.ts into the close-record path. Keep the entry ID for lookup in partitions that still contain the entry. Do not remove missing-tab recording because the command contract requires it to block late starts.
ELI5
In a test-only build (switch
ORCA_LAYOUT_OWNER=main), closing a terminal tab is now recorded by the background process through the same layout command path as other tab changes, instead of through the older close message. Normal builds are unchanged.Stacked on #29313 (tab moves through the background process).
What Changed
Normal builds: nothing. The one switch point compiles to today's code.
Test builds with the switch on, for a local or SSH workspace:
session:close-terminal-surface). It now goes throughlayout.applyascloseTabs, with the window's reason (user or clean-up).Saved-data rule (switch on only): a close no longer writes a record the background process's loader filled in for a neighbouring tab when the only change is a renumbered sort order. Writing it would have given that neighbour a tab-bar record it never had.
Refactor: the window's
layout.applysender is now store-free (runtime/layout-apply-send.ts), so store code can send without importing the store.sendLayoutCommandToOwnerstays as a thin wrapper that reads the store.Why
closeTabswould stop every terminal the tab is bound to. The background process ignores that stop list for the window's close.closeTabswithrecordClose), not in a second close path. That makes the window's close the same command phones and the command line will use, which is the point of phase C.layout.applymeans teaching the sharedmovePaneToNewTabthe existing rules: last pane, every holding partition, a stale terminal binding, and re-keying pane-keyed records such as agent status and orchestration. That is a separate PR.Linked Issue
Part of the layout single-owner plan (phase C2).
Visual Proof
N/A for shipped builds: no behaviour change with the switch off.
Switch on, hidden test app, closing a tab from its close button:
closeTabs ["61a2b27a…"], recordClose: "user".ok, closed ["61a2b27a…"].{reason: "user", worktreeId: …}, and the empty group collapsed. The window and the saved session both have 3 tabs in 3 groups.Testing
Automated tests:
layout.apply:Layout oracle, switch on, built from this branch merged with current
main: 21/21, including the close-tab scenario.Switch off, built bundles (base #29313's head d67766d, chunk hashes, minified names and build commit normalized):
closeTabcompiles to today's close message; the window's close module is not in the bundle at all.closeTabsrecord option, the record-patch rule, the prune, and thelayout.applyclose params and routing. All of these run only fromlayout.apply, which is registered only with the switch on.Checks run locally: the static-analysis steps from the PR workflow,
pnpm tc, and the vitest suites for workspace-layout, terminal-topology,layout.apply, the renderer store (all files), tab-group and terminal-pane.Review
Agent skill upstream boundary
Notes
SSH workspaces take the same path as local ones. Paired-server workspaces keep today's close message. Folder workspaces are covered by the oracle. Phones, the command line and the headless host call
closeTabswithoutrecordClose, so they are unaffected.Temporary code (removed when main becomes the only layout writer, phase F unless noted): the close switch point in
closeTab, the window still stopping the terminals, therecordClosefield and its close records (go with the closed-tab write fence), and the renumber-only skip (goes with the touched-records-only write).Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)