Skip to content

Add the dark layout.apply channel and route pane splits through main (build switch, off by default) - #29185

Merged
Jinwoo-H merged 5 commits into
mainfrom
layout/c1-apply-channel
Oct 15, 2026
Merged

Jinwoo-H merged 5 commits into
mainfrom
layout/c1-apply-channel

Conversation

@Jinwoo-H

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

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​632 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​632
Prod 17 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​446 $\color{#cf222e}{\Huge{\mathbf{−}}}$​31 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​415

ELI5

We are moving the job of deciding the layout of tabs and panes from the app window to the app's background process, one action at a time, in a build that nobody ships yet. This PR adds the channel the window uses to ask the background process for a layout change, and moves the first action onto it: splitting a terminal pane. Builds made the normal way are unchanged.

What Changed

  • A build switch. ORCA_LAYOUT_OWNER is fixed when the app is built. It is window in every normal build and main only when the build asks for it. It is read in exactly one file, src/shared/layout-owner-switch.ts. Every place that behaves differently checks ORCA_LAYOUT_OWNER_IS_MAIN, so a search for that name finds them all. In a normal build both branches are removed when the app is built, which I checked in the built main and window bundles.

  • The layout.apply request (main process). The background process looks up which saved partition holds the tab: local, an SSH host, or a folder workspace. It applies the shared layout command to that partition and saves it to disk before replying. The background process creates every new id; the request schema does not accept one from the window. Workspaces that belong to a paired remote Orca server are refused with host_not_owned, because those layouts stay on the existing mirror path until that server owns them. The request is registered only in a main build, and it is not advertised to phones or remote clients.

  • Only the changed records are written. Loading a partition and saving it again also tidies up records the command never touched, such as old legacy rows, sort orders, key order and pane incarnations. To avoid that, the command's own effect is worked out by comparing the save before the command with the save after it. Only those records are written onto the stored partition (workspace-layout-record-patch.ts).

  • Splitting a pane. In a main build, a split from the keyboard or the context menu waits for the background process to reply, then shows the new pane using the id it created. In a normal build the split works exactly as before.

  • Switch points added (2):

    • src/main/runtime/rpc/methods/index.ts: register layout.apply.
    • terminal-pane-split-with-inherited-cwd.ts: route a user split through the background process.

    Both are deleted when the old path goes.

User-visible before and after: no change in any build that ships. In a main build, a split looks the same, and the pane is now decided and saved by the background process.

Why

The plan is to build the background-process path dark and switch over in one step, instead of running two layout owners side by side in released builds.

  • The split waits for the reply instead of drawing first. Drawing first would need code that reconciles the window's pane tree with the reply, which is the kind of code this work removes. The reply measured about 21 ms in a real app.
  • Writing only the changed records. The alternative was saving the whole partition again, as the existing runtime-started pane path does. That rewrote up to 8 unrelated records on every split in old-format sessions. Both approaches cost the same: about 30 ms at 60 workspaces with 20 tabs each, almost all of it in the shared load step that both already do. The changed-records step adds about 1.3 ms.

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, the split was checked in a hidden dev app:

  • A keyboard split and a requested split both went through layout.apply. The reply contained a new pane id created by the background process, the window showed that pane, and its terminal started.
  • After the split, the background process's saved session held the new pane with its terminal attached.
  • In a normal build, layout.apply returns method_not_found and splits work as before.

Testing

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

Automated tests:

  • Store: a split is written to disk with a minted id, in local, folder and SSH partitions. A refusal writes nothing. Untouched records stay exactly as stored; this test fails under a full rewrite.
  • RPC: layout.apply is absent in a normal build, never advertised or open to phones, and drops any id the window sends.
  • Write logic: every saved-session test profile (current and legacy) is run against 9 command types. The write must touch only the command's records, and the written partition must reload to the command's result. Known gaps are pinned in the test: on three legacy profiles, closing or moving a tab whose legacy row the load folds away does not round-trip. layout.apply accepts only splits today; this must be fixed before it accepts close or move.
  • Window: a split waits for the reply; a paired server's tab splits as today; a normal build never calls layout.apply.

Checks run: pnpm tc, oxlint, check:code-quality:changed, the RPC catalog check, the layout-writer ratchets, and the touched suites (591 files earlier, plus re-runs after each fix).

Review

Fresh review, then a fix round, then a delta review. The fixes:

  • A paired server's tab inside a local workspace splits as today.
  • A layout record the load supplied is written whole.
  • The round-trip check was added to the tests.

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: SSH layouts are stored by this desktop's background process, so layout.apply writes them there.
  • Paired remote servers: never sent this request. The window checks the host first, and the background process refuses as a backstop. Older servers never see the new method.
  • Folder workspaces: covered by a test.
  • Mobile: not exposed.
  • Performance: with the switch off, there is no new IPC and no new work.

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

coderabbitai Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

📝 Walkthrough

The build configuration defines whether the main process or window owns layout. Main-owned builds register a layout.apply RPC that routes commands to durable session persistence. Session patches update affected records while preserving untouched stored records. The renderer can delegate pane splits to the layout owner and use local split paths when delegation does not handle the request.

Priority: ➖ Normal

Merge Risk: 🔵 Low · up to 36341

A refused split in a main-owned build can silently leave the pane unsplit. This is a bounded edge case; use the local fallback for refused replies before merging.

Pre-merge checks: Passed 3 · Failed 2

Failed Failed checks: 2 warnings

Check name Status Explanation Resolution
Description check Warning The description covers the change, rationale, testing, visual proof, compatibility considerations, and checklist. The required Linked Issue section does not contain an actual issue reference; it state… Add the applicable pre-existing issue reference in the Linked Issue section, using the required issue-link format such as Fixes #12345. If this is a maintainer-only change with no issue, confirm that the repository policy permits omitting…
Docstring Coverage Warning Docstring coverage is 40.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 30 functions across 21 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 3 passed
Check name Status Explanation
Title check Passed The title clearly identifies the new dark layout.apply channel, main-process pane routing, and build-switch behavior.
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.
Full details: Description check

Explanation

The description covers the change, rationale, testing, visual proof, compatibility considerations, and checklist. The required Linked Issue section does not contain an actual issue reference; it states only “Internal layout refactor, phase C1 (no public issue).”

Resolution

Add the applicable pre-existing issue reference in the Linked Issue section, using the required issue-link format such as Fixes #12345. If this is a maintainer-only change with no issue, confirm that the repository policy permits omitting the link and document the approved exception.

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

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

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

Caution

Some comments are outside the diff and can’t be posted inline due to GitHub limitations.

⚠️ Outside diff range comments (1)

🟡 Minor · Use the local fallback only for refused replies. · terminal-pane-split-through-layout-owner.ts:20-42

src/renderer/src/components/terminal-pane/terminal-pane-split-through-layout-owner.ts:20-42
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Use the local fallback only for refused replies.

When reply.ok is false, LayoutApplyOutcome states that the command changed nothing. Call mount(undefined) for every refusal, not only host_not_owned.

Do not call mount(undefined) when a successful reply has no leafId. The bound splitPane implementation always returns a leafId on success, and a successful reply indicates that the command was applied. Retrying that case could duplicate the split.

Do not retry after an RPC rejection. The command state is unknown. The current rejection branch only logs the error, so surface it through the user-visible error mechanism.

Suggested fix
       } else {
         console.warn('[layout-owner] split refused:', reply.ok ? 'no_leaf' : reply.code)
+        if (!reply.ok) {
+          mount(undefined)
+        }
       }

ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 522b4ea2-9079-4734-9c28-e8582a9d3740
📥 Commits

Reviewing files that changed from the base of the PR and between 87ec728 and 363410b.

📒 Files selected for processing: 2
  • 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

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

@Jinwoo-H

Copy link
Copy Markdown
Contributor Author

On the outside-diff note about terminal-pane-split-through-layout-owner.ts:20-42 (fall back on every refusal, never retry after a rejection): this code only runs with the layout-owner switch on. #29207, stacked on this PR, makes the fallback cover every refusal and every pane command. A rejected call is safe to fall back on there: main's write is rolled back when the call fails, so the local split can't duplicate one main already applied.

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