Skip to content

Create terminal tabs through main behind the layout-owner build switch (off by default) - #29311

Merged
Jinwoo-H merged 36 commits into
mainfrom
layout/c3-terminal-create
Oct 16, 2026
Merged

Jinwoo-H merged 36 commits into
mainfrom
layout/c3-terminal-create

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{+}}}$​645 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​645
Prod 8 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​267 $\color{#cf222e}{\Huge{\mathbf{−}}}$​7 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​260

ELI5

The plan is for the app's background process to own every workspace's tabs and panes, with the window only drawing them. This step covers making a new terminal tab, and it only applies in a special internal build. Normal builds do not include it.

What Changed

  • Normal builds: no change. The new window code sits behind the build switch.
    • Preload is identical to the base.
    • The window bundle differs only in unreachable code: the activation helper and the frame-hold counter.
    • The background-process bundle adds only the new command's input check and its id check. Both are reachable only through layout.apply, which normal builds do not register.
  • Builds made with ORCA_LAYOUT_OWNER=main:
    • Every new terminal tab is written by the background process too. The window's one tab-create action, which every create site uses (new tab, "+", agent launch, quick command, setup, CLI/phone reveal, folder workspaces), sends the background process a createTerminalTab command carrying the ids it just drew. The background process writes the tab before any later command from the window can name its pane.
    • The background process checks the ids. It refuses a tab id another tab already holds. The same create sent again changes nothing; this happens when it wrote the tab first, as for CLI and phone creates.
    • A workspace's first terminal on opening is the background process's decision. It creates the terminal only when its own copy of the workspace has no tab, so the window and the background process asking at once still make one tab. Layout updates are held while the window waits for the answer, then the window draws the tab under the background process's ids. If the background process holds no saved data for the workspace, the window opens the terminal as today, but only if the workspace is still shown and still empty.
    • A CLI or phone terminal reveal reuses a tab the layout update already drew. It also passes the background process's pane id, so the window's create matches the tab that is already written.
    • Like the other layout commands, this writes only the records the command touched, never the rest of the saved data.

Why

  • Closes two known gaps in the internal build:
    • A split of a pane the background process had not saved yet was refused until the window's next whole-session save.
    • A tab the CLI or phone made could be drawn from a layout update and then refused ("Terminal tab … already exists") by the reveal. That only happened when old records left it unclear which tab owned the terminal.
  • The window still draws first, except for the first tab. About 24 callers act on the new tab right away: they select, retitle, anchor, mount and launch into it. Waiting for the background process would need a "do this once it appears" step for each of those actions. That step belongs to the later phase where the window draws only from layout updates. Because the window sends its own ids and the background process checks them, no id ever has to be swapped. When the background process places a tab in a different group from the window (a group it does not know yet), the window's next save, as before, puts it right.
  • Alternatives considered:
    • Making every create wait for an answer: too wide for this step.
    • Letting the background process choose new ids: the terminal's environment and hook routing need the id at once.

Linked Issue

Internal refactor plan (phase C3), no issue.

Visual Proof

N/A. Normal builds are unchanged. In the internal build the tab bar looks the same; the difference is in what the background process has saved, which the checks below verify.

Testing

  • Hidden app (background launch), internal build, before and after this change. Right after each create, in the same JavaScript turn, a probe asked the background process about the new pane.

    • After: it already held the pane for every site: Cmd+T, the "+" menu, agent new tab, quick command, setup (two ways), first tab on opening, a never-visited worktree, CLI create, a folder workspace, and create then split.
    • Before: the same probe got tab_not_found or pane_not_found.
    • At every site, the window, the background process and the saved file list the same tabs, with no duplicates and no "already exists" errors.
  • Workspace layout check, internal build: 21/21 pass. The headless variant: 9 pass and 9 skipped (that variant's server was not built).

  • Unit tests:

    • Background-process create: written under the window's ids, durable, in the named group; a split right after is accepted; the same create again changes nothing; a taken id is refused; untouched records stay byte-identical; the first tab on opening only goes into an empty workspace; SSH writes only to that host's data.
    • Command input check, window-side create command, activation flow (draw, decline, fall back, workspace left or no longer empty, paired server), CLI reveal: frame first, frame not yet drawn, unclear owner.
  • Bundle diff: off build vs base, unminified, compared line by line across chunks (results above).

  • SSH, hidden app against a Docker SSH host, this build vs the base: new tab, agent tab, create then split, and quit/relaunch all match across the window, the server and the saved file. There were no duplicates, refusals or layout warnings. Every SSH host now runs its own managed server (a host it can't serve fails to connect; there is no relay fallback). So SSH tabs are created on that server and kept under its entry, and this change never runs for them. It skips them like any paired-server workspace. The unit test for SSH-only saved data covers a case current builds no longer produce.

  • macOS only.

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

Review

Two independent reviews. The first: merge after fixes. All of its findings were fixed except the group fallback, which is described above. The second, on the fixes: merge as is. Its one cheap finding was also applied.

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

Stacked on #29207. Paired-server workspaces keep their mirrored layout, and the web client is not affected (the switch is not set there).

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
Main writes each window-created terminal tab under the window's ids before any later command names
its pane, and decides a workspace's first terminal on activation. Main refuses a tab id another tab
holds; the same create again changes nothing.
… activation fallback only in the shown workspace
@Jinwoo-H
Jinwoo-H changed the base branch from layout/c1c-dark-followups to main October 16, 2026 03:28
@coderabbitai

coderabbitai Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: f9a5c8e0-ab90-4315-9f83-ed65131b8992
📥 Commits

Reviewing files that changed from the base of the PR and between 4490ec8 and aa6046b.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 8cbd25e7-f922-4b94-8afc-4d26cbcd3d18
📥 Commits

Reviewing files that changed from the base of the PR and between 0b71bc8 and 4490ec8.

📒 Files selected for processing: 4
  • src/main/persistence/terminal-topology/terminal-pane-admission.ts
  • src/main/runtime/rpc/methods/workspace-layout-apply.test.ts
  • src/shared/rpc-contract/workspace-layout-params.ts
  • src/shared/workspace-layout/workspace-layout-command-types.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.

📝 Walkthrough

The layout command contract now supports validated terminal-tab creation. Persistence handles existing tab IDs and stores created layouts. In main-layout-owner mode, the renderer routes initial creation through the layout owner and holds layout frames while awaiting a reply. Terminal presentation can reuse a matching tab or create one with the supplied tab and leaf IDs.

Priority: ➖ Normal

Merge Risk: 🔵 Low · up to 4490e

A delayed reply can add a terminal after the user has moved away from or populated the workspace. This bounded issue needs owner acceptance or a late state check before merge.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 42.11% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 19 functions across 13 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 and concisely identifies the main change: creating terminal tabs through main behind the layout-owner build switch.
Description check Passed The description is complete and matches the template. It explains the user-facing change, implementation, rationale, alternatives, testing, scope, compatibility considerations, and checklist status. I…
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.
✨ 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: 1


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 08d422f2-e02e-450e-bc4a-ab3ae6e80bb9
📥 Commits

Reviewing files that changed from the base of the PR and between 9b99928 and 78f28e4.

📒 Files selected for processing: 13
  • src/main/persistence/terminal-topology/terminal-layout-create.test.ts
  • src/main/persistence/terminal-topology/terminal-pane-admission.ts
  • src/main/runtime/rpc/methods/workspace-layout-apply.test.ts
  • src/renderer/src/components/use-terminal-watcher-effects.ts
  • src/renderer/src/hooks/ipc-events/terminal-presentation-frame-drawn-tab.test.ts
  • src/renderer/src/hooks/ipc-events/terminal-presentation-ipc-bridge.ts
  • src/renderer/src/lib/window-session-write-activity.ts
  • src/renderer/src/store/slices/store-create-tab-layout-owner.test.ts
  • src/renderer/src/store/terminals/terminal-tab-create-through-layout-owner.test.ts
  • src/renderer/src/store/terminals/terminal-tab-create-through-layout-owner.ts
  • src/renderer/src/store/terminals/terminal-tab-creation.ts
  • src/shared/rpc-contract/workspace-layout-params.ts
  • src/shared/workspace-layout/workspace-layout-command-types.ts

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

Comment on lines +112 to +116
if (reply.ok) {
// No tab id: main's copy already shows a tab here, which its frames bring.
if (reply.result.tabId === tabId && !holdsTerminalTab(getState(), tabId)) {
create({ tabId, leafId })
}

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 '75,155p' src/renderer/src/store/terminals/terminal-tab-create-through-layout-owner.ts
sed -n '235,275p' src/renderer/src/components/use-terminal-watcher-effects.ts
sed -n '170,305p' src/renderer/src/store/terminals/terminal-tab-creation.ts

Repository: stablyai/orca

Length of output: 10739


🏁 Script executed:

rg -n -F --glob '*.ts' -e 'function createTab' -e 'const createTab' -e 'shouldActivate' -e 'ownsGlobalSelection' -e 'holdLayoutFramesForWindowCommand' -e 'layout.apply' src/renderer/src/store src/renderer/src/components
sed -n '1,220p' src/renderer/src/store/terminals/terminal-tab-creation.ts
sed -n '1,180p' src/renderer/src/components/use-terminal-watcher-effects.ts

Repository: stablyai/orca

Length of output: 28492


🏁 Script executed:

sed -n '1,80p' src/renderer/src/store/global-selection-owner.ts
sed -n '205,275p' src/renderer/src/store/terminals/terminal-tab-creation.ts
sed -n '1,125p' src/renderer/src/store/terminals/terminal-tab-create-through-layout-owner.ts
rg -n -F --glob '*.ts' -e 'holdLayoutFramesForWindowCommand' -e 'pendingActivationSpawn' src/renderer/src/lib src/renderer/src/store src/renderer/src/components

Repository: stablyai/orca

Length of output: 26108


Do not activate a late main-owned tab.

A successful reply must still draw main’s tab so the window receives the tab that main created. However, createTab activates by default and updates the workspace’s remembered selection even when that workspace is inactive. If the user opens another tab or leaves the workspace while the RPC is pending, the reply can select the activation tab when the user returns.

Set activation only when the workspace is still active and empty. Keep drawing the tab in all successful-reply cases.

Suggested fix
-  create: (ids?: { tabId: string; leafId: string }) => void
+  create: (ids?: { tabId: string; leafId: string; activate?: boolean }) => void
...
          if (reply.result.tabId === tabId && !holdsTerminalTab(getState(), tabId)) {
-            create({ tabId, leafId })
+            const state = getState()
+            create({
+              tabId,
+              leafId,
+              activate:
+                state.activeWorktreeId === worktreeId &&
+                !state.tabsByWorktree[worktreeId]?.length
+            })
          }

Pass ids.activate through the watcher’s createTab options.

@Jinwoo-H
Jinwoo-H merged commit d6d335a into main Oct 16, 2026
56 of 57 checks passed
Jinwoo-H added a commit that referenced this pull request Oct 16, 2026
Main split the layout.apply command type into runtime/layout-apply-send.ts: the tab-bar rename and props commands join it there.
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