Skip to content

feat(layout): draw local and SSH layouts from main's layout stream behind the layout-owner build switch - #29221

Merged
Jinwoo-H merged 14 commits into
mainfrom
layout/e2b-frame-switch
Oct 15, 2026
Merged

Jinwoo-H merged 14 commits into
mainfrom
layout/e2b-frame-switch

Conversation

@Jinwoo-H

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

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​423 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​423
Prod 8 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​563 $\color{#cf222e}{\Huge{\mathbf{−}}}$​7 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​556

ELI5

Today the window keeps its own copy of every workspace's tabs and panes and saves it to disk. The plan is for the app's background process to own that layout and for the window to just draw it. This PR adds the drawing half, but only in a special internal build. Normal builds do not include it.

What Changed

  • Normal builds: no change. The new code is compiled out. The main-process and preload bundles are byte-identical to the base. The renderer bundle differs only in dead code: five unused helper functions, one unused constant, and name-mangling/import-list reshuffles.
  • Builds made with ORCA_LAYOUT_OWNER=main: after startup restore, the window subscribes to the background process's layout stream. It then draws local and SSH workspaces (git worktrees and folders) from those layout updates, using the existing frame-to-store builder (refactor(layout): build today's store slices from layout frames (inert) #29181).
    • Paired-server workspaces stay on today's mirror.
    • Live terminal titles sent by the background process update the tab title.
  • How:
    • runtime/workspace-layout-frame-sync.ts keeps the latest layout per workspace.
      • When only titles changed, it updates just the titles.
      • Otherwise it rebuilds only the changed workspaces.
    • store/workspace-layout-frame-store-patch.ts lays the rebuilt records over the store:
      • Unchanged records keep their objects, so nothing re-renders.
      • Each record keeps the state only the window knows: which terminal a pane is attached to right now, a pane's in-flight start or recovery, an open file's editor state, a browser tab's page.
    • Selection, focus, drafts and scrollback still come from the window's own state.
    • Sleeping-agent records, closed-tab records, default-tab marks and what reconnects at startup still come from today's restore.

Why

  • The window keeps saving its whole layout in this build. New tab, close, rename, move and open file do not go through the background process yet; only split does (base PR). If the background process ignored the window's layout, those changes would be lost.
  • To keep the two copies from overwriting each other, layout updates wait while the window still owes the background process a save. That includes before saving is allowed at all, and after a failed save. Title-only updates never wait.
    • This relies on the background process sending a save's layout update before it acknowledges that save. That holds today: the store write, its listener and the stream emit are all synchronous before the reply.
    • Layout update sequence numbers replace this check later in the plan.
  • Alternatives considered:
    • Applying every update at once: overwrites unsaved local edits.
    • Making the background process ignore the window's layout now: loses the actions that are not routed through it yet.
    • Batching title updates: measured, and not needed (see Testing).

Linked Issue

Internal refactor plan (phase E2b), no issue.

Visual Proof

Hidden app (background launch), screenshots taken over the debugging protocol, normal build vs ORCA_LAYOUT_OWNER=main build.

Split right then down. Normal build vs switch on:
off
on

Two tabs, quit, relaunch. Normal build vs switch on:
off
on

Testing

  • Layout parity journeys, run on the normal build and the switched-on build, then diffed. Journeys: create tab, split, close pane, close tab, reorder, drag out across restarts, CLI split, restart, folder workspace.

    • All 9 pass on both builds.
    • The only differences are invisible saved data:
      • Tab entries gain an explicit executionHostId: 'local' (the frame builder names every tab's host).
      • After a tab closes, sortOrder is renumbered.
  • Workspace layout check on the switched-on build: 21/21 pass. It covers rename, CLI create/rename/close, paired clients, reload, quit, restart, cold and live daemon restart, sleep/resume, and folder workspaces.

  • Latency check on both builds, 10 samples, including three panes changing titles about 150 times a second in total. The switched-on build matches or beats the normal one, and main's event-loop p99 under titles is 3.3 ms vs 4.7 ms. Close pane is bimodal (about 25 or about 115 ms) on both builds.

  • Unit tests:

    • Startup from the first update changes nothing that restore showed, across every stored profile fixture.
    • Structure updates wait for an owed save and keep the window-only state.
    • Title-only updates apply while a save is owed.
    • Paired-server workspaces are untouched.
    • Store patch cases: a closed terminal, file or browser tab; editor and page state kept.
    • Session-write busy reporting.
  • Rebuild cost with 400 tabs: 1.6 ms per structural update. Reading the view back is scoped to the changed workspaces (it was 10.7 ms before scoping).

  • Tested on macOS only.

  • I manually tested these changes locally

  • Automated tests added/updated

Review

Independent review, then a fix round, then a delta review: MERGE AS IS.

Agent skill upstream boundary

  • Not applicable.

Notes

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • Before/after screenshots attached
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered
  • Typecheck, targeted tests, changed-code quality gate and layout ratchets pass locally

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

coderabbitai Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

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: 0d20692a-598c-4b1e-8191-da3b64c69689
📥 Commits

Reviewing files that changed from the base of the PR and between 3a3889c and 836ab0d.

📒 Files selected for processing: 11
  • config/renderer-layout-writer-baseline.txt
  • src/renderer/src/app-shell/reconcile-hydrated-workspace-tab-models.ts
  • src/renderer/src/lib/session-write-subscriber-activity.test.ts
  • src/renderer/src/lib/session-write-subscriber.ts
  • src/renderer/src/lib/window-session-write-activity.ts
  • src/renderer/src/runtime/workspace-layout-frame-sync.test.ts
  • src/renderer/src/runtime/workspace-layout-frame-sync.ts
  • src/renderer/src/store/workspace-layout-frame-slices.ts
  • src/renderer/src/store/workspace-layout-frame-store-patch.test.ts
  • src/renderer/src/store/workspace-layout-frame-store-patch.ts
  • src/shared/workspace-layout/workspace-layout-beside.ts

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

📝 Walkthrough

The renderer now tracks session-write activity and synchronizes runtime layout frames into window state. Structural frame updates wait until session-write activity becomes idle, while live title updates apply directly. Store patches reconcile workspace slices and tab-related state while retaining window-owned values. The changes also add tests, update the layout-writer ratchet, and annotate three session-field initializers.

Priority: ➖ Normal

Merge Risk: ⚪ Minimal · up to 836ab

No confirmed issue blocks merging after normal checks.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 42.31% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 26 functions across 10 files. (1 skipped:… 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 identifies the main change: drawing local and SSH layouts from the main-process layout stream behind the layout-owner build switch.
Description check Passed The description is detailed and aligned with the template. It covers the user-facing change, implementation, rationale, testing, visual proof, platform considerations, and checklist status.
Full details: Docstring Coverage

Explanation

Docstring coverage is 42.31% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 26 functions across 10 files. (1 skipped: 1 unsupported.)

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

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