Skip to content

The window applies each layout update record by record instead of rebuilding from its whole session (dark, layout-owner build only) - #31152

Merged
Jinwoo-H merged 9 commits into
mainfrom
e2-6/e2-incremental-apply
Oct 20, 2026
Merged

Jinwoo-H merged 9 commits into
mainfrom
e2-6/e2-incremental-apply

Conversation

@Jinwoo-H

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

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 7 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​472 $\color{#cf222e}{\Huge{\mathbf{−}}}$​86 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​386
Prod 13 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​923 $\color{#cf222e}{\Huge{\mathbf{−}}}$​208 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​715

ELI5

In the layout-owner build, main sends the window a small update after each action, naming only the records that changed. Until now the window threw that detail away: for almost any update it saved its whole session to memory, re-read it, and rebuilt every tab and pane list from scratch. Now it applies each update record by record. A terminal reconnecting changes one pane, a rename changes one tab, and anything else rebuilds only the one workspace the update names, from what the window already holds.

What Changed

Users see nothing different in shipped builds (the switch is off). With the switch on:

  • Before: each update from main made the window serialize its whole session, run the session loader on it, and rebuild every slice for the changed workspaces (about 950 ms of a 100-agent relaunch in a CPU profile).
  • After:
    • Terminal bindings and live titles patch only their pane or tab. A pane counts as rebound when its terminal id or its binding generation changes (a restart under the same id shows only as a new generation).
    • Every other record change (rename, split, pane close, tab close, move, group change, opening a file) rebuilds only that workspace. It uses the same restore builders as before, fed from the window's own store view (workspace-layout-frame-store-view.ts), with no session save, no read-back and no loader.
    • Updates between flushes are collected per workspace (workspace-layout-frame-pending.ts), so a burst still shows in one store update.
    • The workspace build reads the editor selection, groups and active group through the session save's own writers, for the updated workspaces only, so it drops what the full build drops (for example, the active file while a diff tab is focused, an empty group, or a repeated group id, where the first wins).
  • Still a full build: the startup snapshot, a reopened stream's snapshot, a workspace the window doesn't yet show from updates (a first visit), a whole-workspace change (a workspace new to the stream), and an older host's whole-workspace events. None happen during normal use.
  • Fix (switch on only): releasing a tab the window was holding now rebuilds that tab's workspace, so a terminal binding that changed during the hold shows. Before, it stayed stale until the next change.

Measured on a 100-tab workspace, before -> after:

Update Before After
One terminal binding (median / max) 0.85 / 1.8 ms 0.31 / 0.76 ms
100 binding updates (one relaunch) ~88 ms ~31 ms
One update with 100 generated titles 4-5 ms 3-3.7 ms
Rename 3.8 ms 2.7 ms
Split 3.3 ms 2.1 ms

Design: per-workspace builds, not per-tab. A per-tab build would fork the restore builders' logic, and the costs above are well within budget. Per-tab builds are a non-goal unless profiling shows a hot spot.

Also in this PR (switch-on unit tests that were red on main):

Why

The update already says exactly what changed; rebuilding everything from a read-back of the window's own session was the most expensive step left on the relaunch path, and it made every later piece (main starting terminals, editor tabs drawn from main) pay it too. Rejected alternatives:

  • Per-tab builds: would duplicate restore logic (see above).
  • Keeping the full build behind a faster read-back: still pays the whole-session cost on every update.

Cold-launch title delay, explained (no fix here): on 2 of 24 switch-on cold launches, generated tab titles reached the store about 0.9 s after main sent them. Timeline from the slow run (ms relative to titles in the store): main sends the titles update -891; session ready -872; the window's startup render blocks it -871 to -39 (832 ms, the same size as in the switch-off build); titles in the store 0. The window was already applying updates; the update simply landed just before the startup render. The switch-off build sets titles locally, before that render, so it never shows this. This PR cuts the 39 ms tail (a tab-row update no longer runs the full build; a test pins one store update with no session read-back). Removing the race itself belongs to D2, where main derives generated titles so they are in main's snapshot before the window draws. Possible user-visible effect on a rare first launch: tab titles may show their default names for a frame or two before the generated titles appear.

Linked Issue

N/A (layout-owner plan, step E2a; follows #31109 and #31140).

Visual Proof

N/A: dark change; the switch is off in shipped builds and the switch-off bundle is unchanged (below).

Testing

  • Automated tests added/updated
    • New: workspace-layout-frame-operations.test.ts (rename, split, pane close, tab close, move, group change and editor open each apply without a full build; 100 binding updates take no full build; 100 titles make one store update with no session read-back or loader).
    • Mixed flush: a test proves the apply check still catches a mismatch in one workspace when another workspace in the same flush was fully built.
    • Test-only check on every flush: the shared layout test transport and the 7 frame test files compare each per-record result with the old full build for the same inputs (workspace-layout-frame-apply-check.test-fixture.ts). It checks every workspace an update changed that was not fully rebuilt, chains to any check a test installs itself, passes in the 7 frame test files and the 37 files that use the shared transport (switch off and on), and caught two deliberate breakages.
    • Fail on the base commit, pass here: one store update with no full build for rename, split, pane close, tab close, move, group change, editor open and 100 titles; a focused diff tab and a repeated group id under the workspace build; a binding changed during a pane-command hold shows on release.
    • Pass on base too (they guard behaviour the new path must keep): a binding changed while a drawn tab was held shows on release; an invalid active tab and an empty group are dropped as the full build drops them; a binding-only update keeps the pane's terminal mounted; 100 binding updates take no full build.
    • 72 test files that import a changed file, plus the paired-server guard and routing tests: switch off 72/72 files pass; switch on 70/72, where the 9 failures in agent-generated-tab-title (8) and worktree-agent-activation-seam (1) are identical on the base commit and belong to later steps (D2 and D1b).
  • Switch-off bundle: unminified build of base and head differs only in the commit stamp and in syntax-grammar chunks that exist twice under one name once hashes are stripped, so the comparison pairs them differently from build to build; no code from this change reaches the switch-off bundle.
  • Gates: pnpm tc, check:code-quality:changed, type-aware and plugin oxlint (import cycles), check:layout-writer-ratchets (no ratchet raised), and every config/scripts/check-*.mjs step CI's static analysis runs (15, including the e2e type-check ratchet at 222).

Review

One independent review, then a review of the fixes.

  • The first review found three issues, all fixed here: the workspace build copied the editor selection and groups without the save's filtering; the hold-release fix had no test; the apply check skipped a whole flush if any workspace in it was fully built, and the shared test transport replaced a test's own check.
  • The fix review was clean. Its two test-fixture notes are also done: the shared transport restores the previous check only if its own is still installed, and a mixed-flush test proves the check catches a mismatch next to a full build (it fails if that branch is skipped).

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

Remote and SSH: the paired-server path is untouched (guard test passes). No message shapes change. Folder workspaces use the same per-workspace build.

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)

E2E Test added 8 commits October 20, 2026 10:17
…reading its session back (dark, layout-owner build only)

A records frame no longer re-serializes the window's whole session and runs the
Loader. Panes' terminal bindings and live titles apply alone, to the tabs the
frame names; any other record builds only its own workspace's slices, with the
view and facts read from the store. Only a workspace the store does not show
from frames yet (startup, a reopened stream, a first visit, one sent whole)
takes the full build.

Tests install an apply check that, after every flush, compares the store with
the full build for the same cache and pre-flush store; the shared layout-apply
transport now sends main's records frames and fails a flush that differs.
…ack or running the Loader (test, layout-owner build only)
…ing generations, so it passes with the switch on (test only)
…ave's own writers, as the full build does (dark, layout-owner build only)
… builds one in full, and the shared transport keeps a test's own check (test only)
…ld, and the shared transport restores only the check it installed (test only)
@coderabbitai

coderabbitai Bot commented Oct 20, 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: 6c903f5e-4729-432b-b87d-6883de30e1c1
📥 Commits

Reviewing files that changed from the base of the PR and between b3e9a75 and 480a4a8.

📒 Files selected for processing: 1
  • src/renderer/src/runtime/workspace-layout-frame-pending.ts
🚧 Files skipped from review as they are similar to previous changes: 1
  • src/renderer/src/runtime/workspace-layout-frame-pending.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.

📝 Walkthrough

The renderer now classifies workspace layout records and applies selective rebuilds, title updates, and terminal-binding updates. New fixtures generate layout frames and compare applied store state with rebuilt state. Tests cover frame operations, bindings, pane trees, holds, and title updates. The terminal account restart test now tracks per-pane PTY binding generations and replaces nested state objects immutably.

Priority: ➖ Normal

Merge Risk: ⚪ Minimal · up to 480a4

The naming issue is addressed, and the final change leaves layout classification behavior unchanged. No issue identified here prevents 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 61.54% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 39 functions across 19 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: incremental layout-record application instead of rebuilding from the full session. It is specific and related to the changeset, although somewhat long.
Description check Passed The description is comprehensive and follows the template. It explains the user impact, implementation, rationale, testing, performance results, compatibility considerations, and checklist status. The…
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 is comprehensive and follows the template. It explains the user impact, implementation, rationale, testing, performance results, compatibility considerations, and checklist status. The linked issue is marked N/A, but the rest of the required information is substantially complete.

  • 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: 2fa91340-7646-4d41-a1ee-384da5e7d22a
📥 Commits

Reviewing files that changed from the base of the PR and between 6ed5a93 and b3e9a75.

📒 Files selected for processing: 20
  • config/e2e-typecheck-baseline.txt
  • src/renderer/src/components/terminal-pane/pty-connection-test-store-state.ts
  • src/renderer/src/runtime/layout-apply-test-transport.test-fixture.ts
  • src/renderer/src/runtime/main-loaded-layout-frames.test-fixture.ts
  • src/renderer/src/runtime/workspace-layout-frame-apply-check.test-fixture.ts
  • src/renderer/src/runtime/workspace-layout-frame-apply-observer.ts
  • src/renderer/src/runtime/workspace-layout-frame-binding.test.ts
  • src/renderer/src/runtime/workspace-layout-frame-bindings.ts
  • src/renderer/src/runtime/workspace-layout-frame-builds.ts
  • src/renderer/src/runtime/workspace-layout-frame-changes.ts
  • src/renderer/src/runtime/workspace-layout-frame-held-tabs.test.ts
  • src/renderer/src/runtime/workspace-layout-frame-operations.test.ts
  • src/renderer/src/runtime/workspace-layout-frame-pane-trees.ts
  • src/renderer/src/runtime/workspace-layout-frame-pending.ts
  • src/renderer/src/runtime/workspace-layout-frame-records.test.ts
  • src/renderer/src/runtime/workspace-layout-frame-sync.test.ts
  • src/renderer/src/runtime/workspace-layout-frame-sync.ts
  • src/renderer/src/runtime/workspace-layout-frame-tab-props.test.ts
  • src/renderer/src/store/workspace-layout-frame-store-view.ts
  • tests/e2e/terminal-account-restart.unit.test.ts
💤 Files with no reviewable changes: 1
  • config/e2e-typecheck-baseline.txt

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

…hout its panes' bindings or live titles (dark, layout-owner build only)
@Jinwoo-H
Jinwoo-H merged commit 98e7dbe into main Oct 20, 2026
39 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