Skip to content

feat(layout): record the window's terminal tab close through main behind the layout-owner build switch - #29327

Merged
Jinwoo-H merged 37 commits into
mainfrom
layout/c2-tab-close
Oct 16, 2026
Merged

Jinwoo-H merged 37 commits into
mainfrom
layout/c2-tab-close

Conversation

@Jinwoo-H

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

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​234 $\color{#cf222e}{\Huge{\mathbf{−}}}$​3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​231
Prod 12 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​252 $\color{#cf222e}{\Huge{\mathbf{−}}}$​93 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​159

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:

  • The window side is unchanged. It still confirms the close, removes the tab, and stops the tab's terminals. Any terminal another tab still shares is spared, as today.
  • What changes is how the close reaches the background process. It used to go through the close message (session:close-terminal-surface). It now goes through layout.apply as closeTabs, with the window's reason (user or clean-up).
  • What the background process does with it:
    • closes the tab in every saved partition that holds it, forced, because the window already confirmed;
    • records the close, so a terminal start that finishes later is refused. Like today, this also covers a tab it does not list. Recording prunes old close records the same way today's close does;
    • advances the layout revision, so a stale save from the window cannot bring the tab back;
    • marks a user close's starting agent launches as closed, by the terminal's own id;
    • stops no terminal.
  • When the background process lacks the workspace, or a paired server owns it, today's close message still records the close.

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.apply sender is now store-free (runtime/layout-apply-send.ts), so store code can send without importing the store. sendLayoutCommandToOwner stays as a thin wrapper that reads the store.

Why

  • The window still stops the terminals itself. It already knows which terminals another tab shares, and the background process's closeTabs would stop every terminal the tab is bound to. The background process ignores that stop list for the window's close.
  • The close records live in the shared layout model (closeTabs with recordClose), 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.
  • Dragging a pane out into a new tab is not in this PR. Today the background process already commits that move first, through its own command. Moving it onto layout.apply means teaching the shared movePaneToNewTab the 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:

  • The window sent: closeTabs ["61a2b27a…"], recordClose: "user".
  • The background process replied: ok, closed ["61a2b27a…"].
  • The background process's saved session afterwards: the tab's row is gone, there is a close record {reason: "user", worktreeId: …}, and the empty group collapsed. The window and the saved session both have 3 tabs in 3 groups.

Testing

  • I manually tested these changes locally (macOS, hidden dev app with the switch on)
  • Automated tests added/updated

Automated tests:

  • Record patch:
    • Every saved-session fixture round-trips a recorded close, including a tab the background process does not list.
    • A close does not write a neighbour the loader filled in (this test fails without the rule).
  • Store-level layout.apply:
    • the close is durable and recorded;
    • the layout revision advances;
    • expired close records anywhere in the partition are pruned.
  • Main routing:
    • every non-paired-server partition is closed, forced;
    • a user close's launches are marked by the terminal's id;
    • a clean-up close leaves launches alone;
    • a missing workspace falls back to today's close message.
  • Request checks: one tab, the window's reason only, and no force or refusals from the window.
  • Window: sends the tab-bar entry's id, and falls back to today's close message.

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):

  • Renderer: 329 chunks differ only in export names. The remaining differences are the layout sender moving into the store chunk, where it has no caller, and the commit hash. closeTab compiles to today's close message; the window's close module is not in the bundle at all.
  • Main: differs in the shared closeTabs record option, the record-patch rule, the prune, and the layout.apply close params and routing. All of these run only from layout.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

  • Opus review: BLOCK, with three more findings. All are fixed in c7f51d3:
    • Blocking: the new close module made the store import itself, which broke 178 store test files. It now sends through the store-free sender.
    • Should-fix: launch marking used the tab-bar id. It now uses the terminal's id.
    • Should-fix: pruning covered one workspace instead of the whole partition. It now prunes the partition.
    • Accepted nit: a holder partition can be written twice when the routed partition lacks the workspace.
  • Opus delta review: MERGE AS IS. It ran 749 test files with 0 failures and confirmed the cycle is gone.

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

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 closeTabs without recordClose, 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, the recordClose field and its close records (go with the closed-tab write fence), and the renumber-only skip (goes with the touched-records-only write).

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)

… 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.
…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
…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
…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.
@Jinwoo-H
Jinwoo-H changed the base branch from layout/c2-tab-groups to main October 16, 2026 05:48
@coderabbitai

coderabbitai Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

📝 Walkthrough

The change adds user and cleanup close reasons to single-tab layout commands. The shared close command records tombstones, and the persistence path prunes tombstones when it handles a recorded close. The runtime routes forced tab closes across non-runtime holders and marks launches for user closes. The renderer sends eligible terminal-tab closes through the layout owner, with a local close commit as fallback.

Priority: ➖ Normal

Merge Risk: 🟡 Moderate · up to 3c17f

In a workspace with a partition missing the tab entry, a closed terminal can be adopted again after a late start. Correct the tombstone key before merging.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 44.44% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 18 functions across 17 files. 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 change: recording terminal-tab closes through main behind the layout-owner switch. It is specific and related to the changeset.
Description check Passed The description is complete and covers the user impact, implementation, rationale, testing, compatibility, review findings, and checklist. It includes a reference to issue #29313 and explains why visu…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI
✨ Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • 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.

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

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 26fa1e1c-ea04-4021-ad22-d39cb6662196
📥 Commits

Reviewing files that changed from the base of the PR and between 955c7a9 and 3c17f45.

📒 Files selected for processing: 17
  • src/main/persistence/terminal-topology/terminal-layout-apply.test.ts
  • src/main/persistence/terminal-topology/terminal-pane-admission.ts
  • src/main/runtime/rpc/methods/workspace-layout-apply.test.ts
  • src/main/runtime/runtime-layout-apply.test.ts
  • src/main/runtime/runtime-layout-apply.ts
  • src/renderer/src/components/tab-group/tab-group-layout-owner-commands.ts
  • src/renderer/src/runtime/layout-apply-send.ts
  • src/renderer/src/runtime/layout-owner-command.ts
  • src/renderer/src/store/terminals/terminal-tab-close-layout-owner.test.ts
  • src/renderer/src/store/terminals/terminal-tab-close-layout-owner.ts
  • src/renderer/src/store/terminals/terminal-tab-close.ts
  • src/shared/rpc-contract/workspace-layout-params.ts
  • src/shared/workspace-layout/workspace-layout-command-types.ts
  • src/shared/workspace-layout/workspace-layout-commands.ts
  • src/shared/workspace-layout/workspace-layout-record-patch.test.ts
  • src/shared/workspace-layout/workspace-layout-record-patch.ts
  • src/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.

Comment on lines +102 to +116
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)

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.

🗄️ 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 -90

Repository: 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.ts

Repository: 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.ts

Repository: 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.

@Jinwoo-H
Jinwoo-H merged commit cfca220 into main Oct 16, 2026
75 of 87 checks passed
Jinwoo-H added a commit that referenced this pull request Oct 16, 2026
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