Skip to content

Close, rename and equalize panes through main (dark, build switch off by default) - #29187

Merged
Jinwoo-H merged 14 commits into
mainfrom
layout/c1b-pane-ops
Oct 16, 2026
Merged

Jinwoo-H merged 14 commits into
mainfrom
layout/c1b-pane-ops

Conversation

@Jinwoo-H

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

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 10 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​627 $\color{#cf222e}{\Huge{\mathbf{−}}}$​95 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​532
Prod 22 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​456 $\color{#cf222e}{\Huge{\mathbf{−}}}$​157 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​299

ELI5

This continues moving the job of deciding the tab and pane layout from the app window to the background process, in a build nobody ships yet. After splitting a pane (#29185), three more pane actions now go through the background process first: closing a pane, renaming a pane, and making all panes the same size. Builds made the normal way are unchanged.

What Changed

Stacked on #29185. In a build made with ORCA_LAYOUT_OWNER=main:

  • Closing a pane. The window asks the background process to close the pane, waits for the answer, then removes the pane. The background process now applies the rules the existing pane close already follows:

    • closing a tab's last pane is refused, because that is a tab close;
    • the pane closes in every saved partition that holds the tab;
    • the tab's remote session id moves to the remaining pane;
    • an agent still starting in that pane is marked as closed by the user.

    These rules sit behind a field on the close command that only layout.apply sets. The window cannot send that field, and phone, headless and runtime-start-failure callers of the same command are unchanged.

  • Renaming a pane. The new title, or a cleared one, is saved by the background process first; the window then shows it. Titles are trimmed, and blank titles are rejected.

  • Equal pane sizes. The background process equalizes first; the window then redraws. Equalized sizes are now saved the way the window saves them: an even split is stored with no ratio, and other ratios are rounded to 3 decimals. The only other users of that function are old-client translators that nothing calls today.

  • Writes. Only the records each command touches are written (Add the dark layout.apply channel and route pane splits through main (build switch, off by default) #29185). A command that changes nothing now writes nothing.

  • Structure. layout.apply gets its own small store section (LayoutCommandPersistence), and the routing moves into runtime-layout-apply.ts. The window uses one helper, sendPaneCommandToLayoutOwner, for every pane command.

  • Switch points added (3):

    • use-terminal-pane-close-actions.ts: pane close;
    • use-terminal-pane-layout-persistence.ts: title set and clear;
    • terminal-pane-layout-owner-commands.ts: equalize.

    All three check ORCA_LAYOUT_OWNER_IS_MAIN and are deleted when the old path goes.

User-visible before and after: no change in any build that ships. In a main build, the three actions look the same and are now decided and saved by the background process.

Why

The background process now makes these decisions, and the window shows the result: the same pattern as split.

Alternatives considered:

  • Keep calling the existing close channel. That would leave two close implementations. Instead, the existing close's rules were added to the shared close command, but switched on only for layout.apply, so nothing that runs today changes.
  • One PR for all pane actions. Dragging a pane and dragging a divider are gestures. They need a hook on drop and drag-end, plus the window's check that skips a drop which changes nothing; without that check, the shared move rebuilds the split and resets its ratio. They are a separate follow-up PR. Closing a tab and moving a pane out to a new tab are tab actions and come with that later work.

Linked Issue

Internal layout refactor, phase C1 (no public issue).

Visual Proof

N/A for every shipped build: no behaviour change. For the main build, I checked it in a hidden dev app on a tab with 4 panes, using the real menu and keyboard actions:

  • Equalize from the pane menu, a rename from the menu, and a close with Cmd+W each went through layout.apply with an ok reply.
  • After each one, the window's pane tree and titles exactly matched the background process's saved copy. The rename showed server-pane, and the close left 3 equal panes.

Testing

  • I manually tested these changes locally (macOS, hidden dev app with the switch on; built bundles with it off)

  • Automated tests added/updated

  • Close compared with the existing close: run on every saved-session test profile, both current and old-format. layout.apply must write what the existing pane close writes. Two exceptions are allowed:

    Where the existing close does nothing (last pane, or a pane it doesn't have), layout.apply writes nothing.

  • Close rules: the close applies in both a local and an SSH partition.

  • Restarted panes: a pane whose terminal restarted after the window asked still closes. Today the window removes the pane at once and saves its layout without it, even though the existing saved-state close refuses that case; main now closes it outright, so the user sees the same result.

  • Rename and equalize: both are saved exactly as the window saves them.

  • Write-only-what-changed check: extended with rename and the user pane close; no new round-trip gaps.

  • Routing: a close goes to every partition that is not a paired server, and the agent launch is marked. Other commands go to the main partition only. A paired server's tab is refused.

  • Window:

    • with the switch off, each action works immediately and never asks the background process;
    • with it on, nothing changes until the answer arrives;
    • if a close races with another close, the tab closes, not just the pane.
  • Switch off, built bundles: the registration and all window branches are compiled out. The window bundle contains no layout-owner code, and equalize compiles to the direct call.

Checks run: pnpm tc, oxlint, check:code-quality:changed, the RPC catalog check, the layout-writer ratchets, and 1,204 test files.

Review

A fresh review found 2 issues that matter only in the main build, both fixed:

  • a close refused as the last pane is now finished as a tab close;
  • if main's answer arrives when only this pane is left in the window, the tab closes.

Plus 2 test and comment fixes. A delta review followed. Later decision: a user's close closes the pane even if its terminal restarted in the same instant, as today, so that refusal was removed.

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: the close applies in every holding partition, including SSH ones.
  • Paired remote servers: they keep today's path; the window checks the host first, and the background process refuses as a backstop.
  • Folder workspaces: they go through the same partition lookup.
  • Mobile: unchanged.
  • Performance: with the switch off, no new IPC.

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.
…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
# 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
@Jinwoo-H
Jinwoo-H changed the base branch from layout/c1-apply-channel to main October 15, 2026 20:16
@coderabbitai

coderabbitai Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

📝 Walkthrough

The change expands layout commands to support pane closing, renaming, and equalizing alongside splitting. Runtime routing resolves tab host partitions, and persistence applies commands across hosts. Renderer actions coordinate pane operations with the layout owner and retain local behavior in fallback cases. Pane-close handling includes last-pane refusal, and equalization omits ratios near an even split.

Priority: ⬇️ Low

Merge Risk: 🟡 Moderate · up to 32e44

In multi-partition or refused-close cases, a pane can remain saved after it appears closed, or an agent launch can stop while its pane remains open. Fix both 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 43.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 30 functions across 29 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
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.
Title check Passed The title clearly summarizes the primary change: routing pane close, rename, and equalize operations through main, with the build switch disabled by default.
Description check Passed The description is complete and closely follows the template. It explains the user impact, implementation, rationale, scope, testing, visual-proof exception, compatibility considerations, and checklis…
  • Fix all pre-merge checks with AI
✨ Finishing Touches: 💡 2
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🛠️ Fix failing CI checks: 💡
  • 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: 2


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 801f740a-7713-469f-8116-cea8f8e5678a
📥 Commits

Reviewing files that changed from the base of the PR and between 06ead8d and 32e44e7.

📒 Files selected for processing: 32
  • src/main/persistence/loading-store/pty-binding-persistence.ts
  • src/main/persistence/loading-store/store-domain-composition.ts
  • src/main/persistence/terminal-topology/layout-command-persistence.ts
  • src/main/persistence/terminal-topology/pane-close-remote-session.ts
  • src/main/persistence/terminal-topology/terminal-layout-apply.test.ts
  • src/main/persistence/terminal-topology/terminal-layout-pane-ops.test.ts
  • src/main/persistence/terminal-topology/terminal-pane-admission.ts
  • src/main/persistence/terminal-topology/terminal-topology-commit.ts
  • src/main/runtime/orca-runtime.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/terminal-pane/layout-owner-pane-close.test.ts
  • src/renderer/src/components/terminal-pane/terminal-keyboard-action-dispatch.ts
  • src/renderer/src/components/terminal-pane/terminal-layout-gesture-persist.test.tsx
  • src/renderer/src/components/terminal-pane/terminal-pane-layout-owner-commands.test.ts
  • src/renderer/src/components/terminal-pane/terminal-pane-layout-owner-commands.ts
  • 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
  • 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/renderer/src/components/terminal-pane/use-terminal-pane-close-actions.ts
  • src/renderer/src/components/terminal-pane/use-terminal-pane-context-actions.ts
  • src/renderer/src/components/terminal-pane/use-terminal-pane-context-menu.ts
  • src/renderer/src/components/terminal-pane/use-terminal-pane-layout-persistence.ts
  • src/renderer/src/lib/pane-manager/pane-split-ratio.ts
  • src/shared/rpc-contract/workspace-layout-params.ts
  • src/shared/workspace-layout/terminal-pane-tree.ts
  • src/shared/workspace-layout/workspace-layout-command-types.ts
  • src/shared/workspace-layout/workspace-layout-pane-commands.ts
  • src/shared/workspace-layout/workspace-layout-record-patch.test.ts
  • src/shared/workspace-layout/workspace-layout-record-patch.ts
💤 Files with no reviewable changes: 3
  • src/renderer/src/components/terminal-pane/terminal-pane-split-through-layout-owner.test.ts
  • src/main/persistence/loading-store/pty-binding-persistence.ts
  • src/renderer/src/components/terminal-pane/terminal-pane-split-through-layout-owner.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 1 remain after this review.

Comment on lines +261 to +289
function commitLayoutCommand(
hostIds: readonly ExecutionHostId[],
command: LayoutCommand,
context: TerminalTopologyCommitContext
): DurableProfileStateMutation<LayoutApplyOutcome> {
const changes = hostIds.map((hostId) => ({
hostId,
change: applyCommandToSession(hostId, context.getSession(hostId), command)
}))
const routed = changes[0]?.change.value
if (!routed) {
return { value: { ok: false, code: 'workspace_not_found' }, persist: false }
}
const writes = routed.ok
? changes.filter(({ change }) => change.value.ok && change.session !== null)
: []
if (writes.length === 0) {
return { value: routed, persist: false }
}
const restores = writes.map(({ hostId, change }) =>
writeRestorable(
() => context.getSession(hostId),
(value) => context.markDirty(assignWorkspaceSessionPartition(context.state, hostId, value)),
keepFrozen(hostId, change.session!, context)
)
)
return { value: routed, rollback: () => restores.forEach((restore) => restore()) }
}

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 '255,300p' src/main/persistence/terminal-topology/terminal-topology-commit.ts
sed -n '55,85p' src/shared/workspace-layout/workspace-layout-pane-commands.ts
sed -n '135,177p' src/main/persistence/terminal-topology/terminal-layout-pane-ops.test.ts

Repository: stablyai/orca

Length of output: 4386


🏁 Script executed:

set -o pipefail
printf '%s\n' '--- changed diff ---'
git diff --unified=80 06ead8dad0329d53bb15cf3e564857680626733b 32e44e748d10c9aabf8815d881a234ab354d5fc2 -- src/main/persistence/terminal-topology/terminal-topology-commit.ts src/main/persistence/terminal-topology src/shared/workspace-layout src/main | sed -n '1,1200p'
printf '%s\n' '--- symbols and callers ---'
rg -n -F --glob '*.ts' -e 'applyLayout(' -e 'applyLayoutCommand(' -e 'applyCommandToSession' -e 'userPaneClose' -e 'closePane' src/main src/shared | sed -n '1,1000p'
printf '%s\n' '--- focused implementation ---'
sed -n '1,275p' src/main/persistence/terminal-topology/terminal-topology-commit.ts
sed -n '1,180p' src/main/persistence/terminal-topology/terminal-topology-store.ts 2>/dev/null || true
printf '%s\n' '--- repository close/routing docs and tests ---'
rg -n -i --glob '*.{ts,md,json}' -e 'last_pane' -e 'alreadyClosed' -e 'partition' -e 'layout\.apply' -e 'every partition' -e 'close.*pane' src docs README.md 2>/dev/null | sed -n '1,1000p'

Repository: stablyai/orca

Length of output: 45648


🏁 Script executed:

set -o pipefail
printf '%s\n' '--- commit module ---'
nl -ba src/main/persistence/terminal-topology/terminal-topology-commit.ts | sed -n '1,330p'
printf '%s\n' '--- layout persistence and RPC contract ---'
nl -ba src/main/persistence/terminal-topology/layout-command-persistence.ts
nl -ba src/shared/rpc-contract/workspace-layout-params.ts | sed -n '1,110p'
printf '%s\n' '--- all active layout command callers ---'
rg -n -F --glob '*.ts' --glob '*.tsx' -e 'applyLayoutCommand' -e 'layout.apply' -e 'contestedPartitionHosts' -e 'workspaceSessionPartitionHostFor' src tests | sed -n '1,800p'
printf '%s\n' '--- routing and close-related tests ---'
rg -n -i --glob '*.{ts,tsx}' -e 'hostIds' -e 'partitions holding' -e 'last_pane' -e 'alreadyClosed' -e 'close.*partition' -e 'layout.*apply' src/main src/renderer/src src/shared tests 2>/dev/null | sed -n '1,1200p'
printf '%s\n' '--- relevant changed hunks only ---'
git diff --unified=35 06ead8dad0329d53bb15cf3e564857680626733b 32e44e748d10c9aabf8815d881a234ab354d5fc2 -- src/main/persistence/terminal-topology/terminal-topology-commit.ts src/main/persistence/terminal-topology/layout-command-persistence.ts src/shared/workspace-layout/workspace-layout-pane-commands.ts src/main/ipc src/renderer/src | rg -n -B35 -A45 'commitLayoutCommand|applyLayoutCommand|contestedPartitionHosts|closePane|layout.apply|hostIds' | sed -n '1,1600p'

Repository: stablyai/orca

Length of output: 42521


🏁 Script executed:

nl -ba src/main/persistence/terminal-topology/terminal-topology-commit.ts | sed -n '1,330p'
nl -ba src/main/persistence/terminal-topology/layout-command-persistence.ts
nl -ba src/shared/rpc-contract/workspace-layout-params.ts | sed -n '1,110p'
rg -n -F --glob '*.ts' --glob '*.tsx' -e 'applyLayoutCommand' -e 'layout.apply' -e 'contestedPartitionHosts' -e 'workspaceSessionPartitionHostFor' src tests | sed -n '1,800p'
rg -n -i --glob '*.{ts,tsx}' -e 'partitions holding' -e 'last_pane' -e 'alreadyClosed' -e 'close.*partition' -e 'layout.*apply' src/main src/renderer/src src/shared tests 2>/dev/null | sed -n '1,1200p'

Repository: stablyai/orca

Length of output: 41967


🏁 Script executed:

set -o pipefail
printf '%s\n' '--- runtime layout apply ---'
nl -ba src/main/runtime/runtime-layout-apply.ts | sed -n '1,180p'
printf '%s\n' '--- runtime workspace session controller ---'
nl -ba src/main/runtime/runtime-workspace-session-controller.ts | sed -n '1,180p'
printf '%s\n' '--- command adapter ---'
nl -ba src/main/persistence/terminal-topology/terminal-pane-admission.ts | sed -n '1,150p'
printf '%s\n' '--- close command and host routing definitions ---'
nl -ba src/shared/workspace-layout/workspace-layout-command-types.ts | sed -n '130,205p'
nl -ba src/main/runtime/orca-runtime.ts | sed -n '155,185p'
nl -ba src/main/runtime/terminal-surface-close.ts | sed -n '170,215p'
printf '%s\n' '--- focused tests for refusal/divergence ---'
nl -ba src/main/persistence/terminal-topology/terminal-layout-apply.test.ts | sed -n '50,155p'
nl -ba src/main/persistence/terminal-topology/terminal-layout-pane-ops.test.ts | sed -n '55,185p'
nl -ba src/main/runtime/orca-runtime-terminal-close-spill-partition.test.ts | sed -n '90,165p'

Repository: stablyai/orca

Length of output: 36218


Apply close commands without the last-pane guard to secondary holders.

When getHostIdsForTab returns a routed partition with a split layout and another non-runtime partition with only the target pane, main adds userPaneClose: true for both partitions. The routed partition succeeds, but the secondary partition returns last_pane. commitLayoutCommand still returns the routed success and writes only the successful partition. The renderer then removes the pane locally while the secondary partition retains it.

Evaluate userPaneClose only for the routed partition. Secondary holders must also remove the target pane so the multi-partition close remains consistent.

Suggested fix
-  const changes = hostIds.map((hostId) => ({
+  const changes = hostIds.map((hostId, index) => ({
    hostId,
-    change: applyCommandToSession(hostId, context.getSession(hostId), command)
+    change: applyCommandToSession(
+      hostId,
+      context.getSession(hostId),
+      index > 0 && command.type === 'closePane'
+        ? { ...command, userPaneClose: false }
+        : command
+    )
  }))
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
function commitLayoutCommand(
hostIds: readonly ExecutionHostId[],
command: LayoutCommand,
context: TerminalTopologyCommitContext
): DurableProfileStateMutation<LayoutApplyOutcome> {
const changes = hostIds.map((hostId) => ({
hostId,
change: applyCommandToSession(hostId, context.getSession(hostId), command)
}))
const routed = changes[0]?.change.value
if (!routed) {
return { value: { ok: false, code: 'workspace_not_found' }, persist: false }
}
const writes = routed.ok
? changes.filter(({ change }) => change.value.ok && change.session !== null)
: []
if (writes.length === 0) {
return { value: routed, persist: false }
}
const restores = writes.map(({ hostId, change }) =>
writeRestorable(
() => context.getSession(hostId),
(value) => context.markDirty(assignWorkspaceSessionPartition(context.state, hostId, value)),
keepFrozen(hostId, change.session!, context)
)
)
return { value: routed, rollback: () => restores.forEach((restore) => restore()) }
}
function commitLayoutCommand(
hostIds: readonly ExecutionHostId[],
command: LayoutCommand,
context: TerminalTopologyCommitContext
): DurableProfileStateMutation<LayoutApplyOutcome> {
const changes = hostIds.map((hostId, index) => ({
hostId,
change: applyCommandToSession(
hostId,
context.getSession(hostId),
index > 0 && command.type === 'closePane'
? { ...command, userPaneClose: false }
: command
)
}))
const routed = changes[0]?.change.value
if (!routed) {
return { value: { ok: false, code: 'workspace_not_found' }, persist: false }
}
const writes = routed.ok
? changes.filter(({ change }) => change.value.ok && change.session !== null)
: []
if (writes.length === 0) {
return { value: routed, persist: false }
}
const restores = writes.map(({ hostId, change }) =>
writeRestorable(
() => context.getSession(hostId),
(value) => context.markDirty(assignWorkspaceSessionPartition(context.state, hostId, value)),
keepFrozen(hostId, change.session!, context)
)
)
return { value: routed, rollback: () => restores.forEach((restore) => restore()) }
}

Comment on lines +20 to +40
): Promise<LayoutApplyReply> {
const hostIds = hostIdsForTab(command.workspace, command.tabId)
// Why: a paired server's workspaces keep today's mirrored layout until that server owns it.
if (!hostIds[0] || parseExecutionHostId(hostIds[0])?.kind === 'runtime') {
return { ok: false, code: 'host_not_owned' }
}
if (!store.applyLayoutCommand) {
throw new Error('layout_store_unavailable')
}
if (command.type !== 'closePane') {
return store.applyLayoutCommand(command, [hostIds[0]])
}
const { workspace, tabId, leafId } = command
// A launch still starting in the pane the user closed stops, and says so (as the legacy close).
markAgentLaunchesClosedByUser(workspace, { kind: 'pane', tabId, leafId })
// Why every holder: a legacy relay reattach can leave one tab in two partitions.
return store.applyLayoutCommand(
{ ...command, userPaneClose: true },
hostIds.filter((hostId) => parseExecutionHostId(hostId)?.kind !== 'runtime')
)
}

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.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

sed -n '1,75p' src/main/runtime/runtime-layout-apply.ts
rg -n 'markAgentLaunchesClosedByUser|last_pane' src/main/runtime src/renderer/src/components/terminal-pane/use-terminal-pane-close-actions.ts

Repository: stablyai/orca

Length of output: 4186


🏁 Script executed:

set -e
printf '%s\n' '--- mark helper definition and usages ---'
rg -n -F --glob '*.ts' \
  -e 'function markAgentLaunchesClosedByUser' \
  -e 'const markAgentLaunchesClosedByUser' \
  -e 'export function markAgentLaunchesClosedByUser' \
  -e 'export const markAgentLaunchesClosedByUser' \
  -e 'markAgentLaunchesClosedByUser(' \
  src/main src/renderer

printf '%s\n' '--- helper owner block ---'
helper=$(rg -l -F --glob '*.ts' 'markAgentLaunchesClosedByUser' src/main | head -1)
printf 'helper=%s\n' "$helper"
if [ -n "$helper" ]; then
  sed -n '1,320p' "$helper"
fi

printf '%s\n' '--- renderer close action ---'
sed -n '1,240p' src/renderer/src/components/terminal-pane/use-terminal-pane-close-actions.ts

printf '%s\n' '--- layout.apply references and close reply handling ---'
rg -n -F --glob '*.ts' \
  -e 'layout.apply' \
  -e 'last_pane' \
  -e 'userPaneClose' \
  -e 'applyLayoutCommand' \
  src/main src/renderer

printf '%s\n' '--- runtime layout implementation candidates ---'
rg -n -F --glob '*.ts' \
  -e 'applyLayoutCommand' \
  -e 'userPaneClose' \
  -e 'last_pane' \
  src/main/runtime src/shared/workspace-layout

Repository: stablyai/orca

Length of output: 39194


🏁 Script executed:

set -e
printf '%s\n' '--- closedByUser consumers ---'
rg -n -F --glob '*.ts' \
  -e '.closedByUser()' \
  -e 'closedByUser()' \
  -e 'closedByUser' \
  src/main src/renderer | head -240

printf '%s\n' '--- pane command refusal implementation ---'
sed -n '1,230p' src/shared/workspace-layout/workspace-layout-pane-commands.ts

printf '%s\n' '--- persistence apply and commit result ---'
sed -n '1,190p' src/main/persistence/terminal-topology/layout-command-persistence.ts
sed -n '1,180p' src/main/persistence/terminal-topology/terminal-topology-commit.ts

printf '%s\n' '--- renderer command helper ---'
sed -n '1,180p' src/renderer/src/components/terminal-pane/terminal-pane-layout-owner-commands.ts

printf '%s\n' '--- relevant close/refusal tests ---'
sed -n '1,150p' src/renderer/src/components/terminal-pane/layout-owner-pane-close.test.ts
sed -n '1,130p' src/renderer/src/components/terminal-pane/terminal-pane-layout-owner-commands.test.ts

Repository: stablyai/orca

Length of output: 29021


🏁 Script executed:

set -e
printf '%s\n' '--- launch consumers ---'
sed -n '92,125p' src/main/ipc/pty/ipc/spawn-agent-launch.ts
sed -n '38,62p' src/main/ipc/pty/ipc/spawn-agent-launch-end.ts
sed -n '248,280p' src/main/runtime/rpc/methods/agent-launch.ts
sed -n '126,190p' src/main/runtime/rpc/methods/agent-launch-surfaces.ts

printf '%s\n' '--- multi-host commit result ---'
rg -n -F -- 'function commitLayoutCommand' src/main/persistence/terminal-topology/terminal-topology-commit.ts
sed -n '300,390p' src/main/persistence/terminal-topology/terminal-topology-commit.ts

Repository: stablyai/orca

Length of output: 6744


Mark the launch only after layout.apply succeeds.

applyWindowLayoutCommand marks the launch before store.applyLayoutCommand returns. A refusal can leave the target pane open, while launch consumers treat it as user-closed and stop or withdraw the launch.

Suggested fix
-  markAgentLaunchesClosedByUser(workspace, { kind: 'pane', tabId, leafId })
   // Why every holder: a legacy relay reattach can leave one tab in two partitions.
-  return store.applyLayoutCommand(
+  const result = await store.applyLayoutCommand(
     { ...command, userPaneClose: true },
     hostIds.filter((hostId) => parseExecutionHostId(hostId)?.kind !== 'runtime')
   )
+  if (result.ok) {
+    markAgentLaunchesClosedByUser(workspace, { kind: 'pane', tabId, leafId })
+  }
+  return result
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
): Promise<LayoutApplyReply> {
const hostIds = hostIdsForTab(command.workspace, command.tabId)
// Why: a paired server's workspaces keep today's mirrored layout until that server owns it.
if (!hostIds[0] || parseExecutionHostId(hostIds[0])?.kind === 'runtime') {
return { ok: false, code: 'host_not_owned' }
}
if (!store.applyLayoutCommand) {
throw new Error('layout_store_unavailable')
}
if (command.type !== 'closePane') {
return store.applyLayoutCommand(command, [hostIds[0]])
}
const { workspace, tabId, leafId } = command
// A launch still starting in the pane the user closed stops, and says so (as the legacy close).
markAgentLaunchesClosedByUser(workspace, { kind: 'pane', tabId, leafId })
// Why every holder: a legacy relay reattach can leave one tab in two partitions.
return store.applyLayoutCommand(
{ ...command, userPaneClose: true },
hostIds.filter((hostId) => parseExecutionHostId(hostId)?.kind !== 'runtime')
)
}
): Promise<LayoutApplyReply> {
const hostIds = hostIdsForTab(command.workspace, command.tabId)
// Why: a paired server's workspaces keep today's mirrored layout until that server owns it.
if (!hostIds[0] || parseExecutionHostId(hostIds[0])?.kind === 'runtime') {
return { ok: false, code: 'host_not_owned' }
}
if (!store.applyLayoutCommand) {
throw new Error('layout_store_unavailable')
}
if (command.type !== 'closePane') {
return store.applyLayoutCommand(command, [hostIds[0]])
}
const { workspace, tabId, leafId } = command
// A launch still starting in the pane the user closed stops, and says so (as the legacy close).
// Why every holder: a legacy relay reattach can leave one tab in two partitions.
const result = await store.applyLayoutCommand(
{ ...command, userPaneClose: true },
hostIds.filter((hostId) => parseExecutionHostId(hostId)?.kind !== 'runtime')
)
if (result.ok) {
markAgentLaunchesClosedByUser(workspace, { kind: 'pane', tabId, leafId })
}
return result
}

@Jinwoo-H
Jinwoo-H merged commit a40ae0c into main Oct 16, 2026
191 of 240 checks passed
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