Skip to content

Main sends one layout update per action, with only what changed (dark, layout-owner build only) - #31109

Merged
Jinwoo-H merged 7 commits into
mainfrom
e2-6/e1-per-operation-frames
Oct 20, 2026
Merged

Jinwoo-H merged 7 commits into
mainfrom
e2-6/e1-per-operation-frames

Conversation

@Jinwoo-H

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

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 20 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1423 $\color{#cf222e}{\Huge{\mathbf{−}}}$​284 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1139
Prod 45 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1976 $\color{#cf222e}{\Huge{\mathbf{−}}}$​337 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1639

ELI5

In the build where the main process owns the tab layout (off in every shipped build), main tells the window about layout changes by sending it updates. Before this change, main sent a full copy of a workspace's layout after every single save. When 100 restored terminals restarted at relaunch, it sent about 200 of these, and the window rebuilt everything each time, so the window stuttered. Now main sends one small update per action, listing only what changed, and a restarted terminal's update names only that terminal. If the window ever misses an update, it notices and asks for a fresh copy.

What Changed

Layout-owner build only. With the switch off, main still sends today's whole-workspace updates; the window does not listen for them in that build.

Main sends one update per action, with only the changed parts.

  • Before: every save made main reload the whole partition and compare it to what it last sent. Then it sent the full layout of each workspace that changed. A relaunch respawning 100 dead terminals saved twice per terminal (clear the old terminal, then bind the new one), so about 200 full updates.
  • After: an action means one layout request (including a batch such as many agent titles), one terminal binding write, or one load repair. When it ends, main sends one "records" update listing only what changed: tab rows, groups, a tab's pane tree, and each pane's terminal binding, kept separate from the tree. Writes that are not yet part of an action (the window's own session save) still send one update at the end of their task, so nothing is missed. The reply to a layout request still names a position at or after its update.
  • Respawned terminals: a terminal whose process is gone now rebinds in one write. Main keeps the old binding until the new terminal's bind replaces it, so no update ever shows the pane without a terminal. This reuses the existing swap used when a terminal is restarted.
  • Binding generation: each pane's binding carries a generation that rises on every bind, retire and rollback in this process, so readers can tell a new process from the dead one under the same id.

The window notices a missed update and resyncs.

  • How updates are checked: every update now carries a stream epoch, one per main process. The window asks for a fresh full copy if any of these happen:
    • the epoch changes;
    • an update's position is not one past the last;
    • an update of a known type cannot be read or applied.
  • Limit: after three immediate resyncs that each fail again, it falls back to the existing reconnect delay instead of looping.
  • Applying updates: the window rebuilds its copy of each workspace from the changed parts. When only bindings changed, it updates just those panes' bindings in its store, without rebuilding the workspace.

Headless servers and other readers.

  • The publishing lives entirely in main and does not depend on a window. A headless server publishes the same updates to any local subscriber.
  • Main's runtime exposes one hook that fires when an action ends, and one shared read of each partition's loaded layout, so other main-side readers do not load the layout a second time.
  • In tests, a check runs on every update: it confirms that applying the updates gives the same layout as a fresh full load. Development builds only log the first mismatch; release builds never run the check.

Measured on the 100-agent relaunch harness (the relaunch restarts 100 terminals whose processes died; titles are generated):

before (main) this PR rollback build
layout updates per relaunch ~200 full workspaces 1 for all titles + 100 single-binding records 0
p95 frame gap 92 ms (lead measurement) 10.3 ms (all 5) 10.3 ms (all 5)
frame gaps over 100 ms 18 (lead measurement) 9, 6, 5, 6, 8 (median 6) 7, 6, 5, 7, 6 (median 6)

UNGATED: 5 interleaved relaunches per build, run while the machine was busy (1-minute load 22 to 28) because it never got quiet enough for the gated run. Both builds ran under the same load, one after the other.

Why

  • Not tied to the window: sending one update per action, at the end of the action, is the boundary the main process owns. It needs no timers and no throttling, and it works the same for a headless server as for a window.
  • Why the window still needed a cheap path: a terminal binding is per-pane status, not layout structure. Sending it as its own small record lets the window update only that pane.
  • Why one write per respawn: it is a single change of terminal under the same pane, so it should never be published as "unbound".
  • Alternatives rejected:
    • coalescing updates on a timer, which delays and throttles;
    • teaching the window to ignore binding-only updates, which would hide real changes;
    • keeping full-workspace updates, which grow with workspace size on every change.

Linked Issue

Fixes #

Visual Proof

N/A. Nothing changes in shipped builds: the change is limited to the layout-owner build, which is off everywhere. In that build, the relaunch stutter is gone; the numbers above measure it.

Testing

  • I manually tested these changes locally (100-agent relaunch harness on the layout-owner build, hidden windows, isolated profiles)
  • Automated tests added/updated

New tests. Each failed on the base before its fix:

  • Titles: 100 generated titles across workspaces give exactly 1 update and 1 window store update.
  • Respawns: a dead terminal's respawn under the same id or a new one gives 1 update whose only change is one binding record. If a later step fails, the swapped binding stays.
  • Resync:
    • an epoch change, a skipped position, or an unreadable or unappliable update each give exactly one resync, on both local and remote transports;
    • a frame of an unknown type still counts as a position;
    • repeated failures back off.
  • Frame check: a deliberately broken update is caught.
  • Headless: with no window, main still fires the end-of-action hook, and window-style and phone-style subscribers get identical updates.
  • Listeners: a listener on the end-of-action hook that throws cannot fail a committed write.

Tests that import a changed file, 59 files, run with the switch off and on:

  • Switch off: 624 passed.
  • Switch on: 621 passed. The 3 failures also fail on the base: workspace-layout-fact-locations, workspace-layout-views, old-client-session-tabs-projection.
  • The paired-server guard and the unit test routing check pass in both.

Gates: pnpm tc, check:code-quality:changed (0 findings), oxlint on changed files, the layout-writer and max-lines ratchets, and verify:rpc-params-catalog.

Reviews: one adversarial review, and a review of its fix round. The review found no high-severity issue. All nine findings are fixed in this PR:

  • a later failure after a same-id respawn could clear the live binding;
  • unbounded resyncs;
  • a skipped frame's position;
  • a throwing listener;
  • a shared read that could be mutated;
  • the cost of the check in development builds;
  • two comments;
  • SSH panes keep today's retire-then-respawn path.

Switch-off bundle diff (unminified, base vs head, file hashes normalized):

  • The layout stream module is rewritten. With the switch off it still sends today's per-workspace updates with no epoch, and nothing subscribes in that build.
  • The store's write callback ends through a new helper. With the switch off it calls the same write notice as before. The generation bump compiles to an empty function.
  • Some terminal-binding helpers moved between files, unchanged.
  • The binding write's incarnation code is merged into one place. It behaves the same unless the new layout-owner-only flag is set.
  • In the renderer, chunks differ only in the names of the shared chunk's exports, which were renamed because exports were added.
  • The commit stamp changes.
  • Grammar chunks with duplicate names collapse when hashes are stripped; checked identical.

AI Disclosure

Review

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

  • Owner-visible switch-on changes: none a user would notice. With the switch on, the only differences are fewer updates, and a resync instead of a dropped update.
  • Compatibility: layout updates go only to this app's own window over local IPC. The subscription is unadvertised, and no phone, CLI, paired desktop or web client subscribes, so the new update shape needs no negotiation and adds no capability. A headless server registers the subscription, but no shipped peer calls it.
  • Remote SSH: an SSH partition's changes are published the same way. SSH panes keep today's retire-then-respawn path.
  • Folder workspaces: covered by the same path.
  • For other work:
    • Update type: WorkspaceLayoutRecordsFrame in src/shared/workspace-layout/workspace-layout-stream-frames.ts.
    • Record types: in workspace-layout-records.ts.
    • Binding generation: LayoutLeaf.ptyGeneration.
    • Hooks: runtime.workspaceLayoutReads.onLayoutOperationCommitted, and runtime.workspaceLayoutReads.readPartition, which returns a shared, read-only result.

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 5 commits October 20, 2026 06:53
…s a binding-only frame without a rebuild (dark, layout-owner build only)

Main: when the window's spawn for a restored pane finds its process gone, the spawn that holds
the pane's reservation keeps the dead binding and its fresh bind swaps it (the restart swap), so
the pane is never published unbound: a same-id respawn publishes no frame, a new id one. A failed
spawn still retires the dead binding. Other callers and window-owned builds retire early as before.

Window: a frame that differs from the shown one only in panes' terminal bindings updates the
store's pane trees as a rebuild would, falling back to a rebuild for holds and shared terminals.
… resubscribes on a missed frame (dark, layout-owner build only)

Main: a durable mutation (a layout.apply, the renameTabs batch, a binding write, a repair) is
one operation. It names the partitions it wrote, and at its end the layout stream publishes
once: one `records` frame holding only the changed records (tab rows, workspace groups, a pane
tree per tab, a binding record per pane, editor files, browser tabs, removed workspaces), each
keyed by main's own ids. Writes no operation scopes (window saves) still publish when their
task ends. The snapshot and every records frame carry a stream epoch. Each pane's binding
carries `ptyGeneration`, which rises on every binding write in this process, so a same-id
respawn is one frame with one binding record. Readers beside the stream get the end of each
operation and the stream's own per-partition loaded model (`workspaceLayoutReads`), so they
need no second Loader pass, with or without a window.

Window: the cache applies records frames to its full layouts, so the existing flush and the
binding-only path are unchanged. A records frame of another epoch or out of sequence, a
malformed frame, or one the cache cannot apply resubscribes at once for a fresh snapshot.

Tests install main's model check, which applies each frame to what subscribers held and
compares it with a fresh projection; dev builds log a mismatch, release builds run none.
…guard operation listeners (dark, layout-owner build only)

- A spawn whose swap bind persisted no longer retires that pane's binding when a later commit
  step fails; a pane on an SSH host keeps the early retire, since its dead owner lives there.
- The window resubscribes at once at most three times before a frame applies cleanly, then takes
  the loss path's backoff. A skipped frame of a newer type still advances its position.
- A throwing operation listener is logged; it no longer fails a committed mutation.
- Tests freeze the shared partition model a reader gets; the dev-build model check skips frames
  that only change live titles. Generation and model-check comments say what is true.
@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: 84acd642-09d2-4e86-b455-e8ec3ccda4ce
📥 Commits

Reviewing files that changed from the base of the PR and between 56fa317 and f8c4cf3.

📒 Files selected for processing: 12
  • src/main/ipc/pty/ipc/spawn-absent-binding-swap.ts
  • src/main/ipc/pty/ipc/spawn-begin.ts
  • src/main/ipc/pty/ipc/spawn-execute.ts
  • src/main/ipc/pty/ipc/spawn-state.ts
  • src/main/ipc/pty/ipc/spawn-types.ts
  • src/main/ipc/pty/pane/absent-pane-owner.ts
  • src/main/ipc/pty/pane/pane-owner-replacement.test.ts
  • src/main/ipc/pty/pane/pane-owner-replacement.ts
  • src/main/ipc/pty/pane/replaced-pane-owner.ts
  • src/main/ipc/pty/pane/stable-owner.ts
  • src/renderer/src/runtime/runtime-layout-client.test.ts
  • src/renderer/src/runtime/runtime-layout-client.ts
🚧 Files skipped from review as they are similar to previous changes: 1
  • src/main/ipc/pty/pane/absent-pane-owner.ts

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

📝 Walkthrough

The change adds PTY respawn handling that can retain an absent pane binding for a fresh-spawn swap, with incarnation cleanup and binding-generation tracking. It also adds record-based workspace layout frames, host-partition-aware runtime projection and publication, and renderer-side validation and application. Tests cover both layout-owner modes, record diffs, stream recovery, and pane-binding synchronization.

Priority: ➖ Normal

Merge Risk: 🟡 Moderate · up to f8c4c

The remaining import cycle can fail the full static-analysis quality gate and should be removed 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 46.48% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 71 functions across 54 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 summarizes the primary change: layout-owner builds now send one update per action containing only changed data.
Description check Passed The description is detailed and covers the required explanation, changes, rationale, testing, compatibility, visual proof, and checklist. The Linked Issue section is incomplete because it contains onl…
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 detailed and covers the required explanation, changes, rationale, testing, compatibility, visual proof, and checklist. The Linked Issue section is incomplete because it contains only Fixes #, but the overall description is otherwise 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: d43326c2-d6cb-4b1a-8ab4-c1331bbac919
📥 Commits

Reviewing files that changed from the base of the PR and between 4440641 and 56fa317.

📒 Files selected for processing: 61
  • src/main/ipc/pty-absent-pane-respawn.test.ts
  • src/main/ipc/pty-dead-owner-respawn.test.ts
  • src/main/ipc/pty-pane-owner-swap.test-fixture.ts
  • src/main/ipc/pty-pane-restart-replace.test.ts
  • src/main/ipc/pty-persisted-incarnation-repair.test.ts
  • src/main/ipc/pty/ipc/spawn-absent-binding-swap.ts
  • src/main/ipc/pty/ipc/spawn-commit-persist.ts
  • src/main/ipc/pty/ipc/spawn-execute.ts
  • src/main/ipc/pty/ipc/spawn-preflight.ts
  • src/main/ipc/pty/ipc/spawn-types.ts
  • src/main/ipc/pty/pane/absent-pane-owner.ts
  • src/main/ipc/pty/pane/adopt-stable.ts
  • src/main/ipc/pty/pane/pane-owner-replacement.ts
  • src/main/ipc/pty/pane/stable-owner.ts
  • src/main/ipc/pty/pane/stable-pane-absence-respawn.test.ts
  • src/main/persistence-invalid-workspace-layout-purge.test.ts
  • src/main/persistence/loading-store/primary-state-write-runtime.ts
  • src/main/persistence/loading-store/primary-state-writes.ts
  • src/main/persistence/loading-store/pty-binding-generations.ts
  • src/main/persistence/loading-store/pty-binding-persistence.ts
  • src/main/persistence/loading-store/pty-binding-session-update.ts
  • src/main/persistence/loading-store/pty-binding-span.ts
  • src/main/persistence/loading-store/store-runtime-state.ts
  • src/main/persistence/loading-store/workspace-session-write-listeners.spec.ts
  • src/main/persistence/loading-store/workspace-session-write-listeners.ts
  • src/main/persistence/loading-store/write-scheduling.ts
  • src/main/persistence/terminal-topology/layout-command-persistence.ts
  • src/main/persistence/terminal-topology/terminal-layout-rename-tabs.test.ts
  • src/main/runtime/folder-workspace-mixed-host-routing.test.ts
  • src/main/runtime/orca-runtime.ts
  • src/main/runtime/published-pane-live-titles.ts
  • src/main/runtime/rpc/methods/workspace-layout.test.ts
  • src/main/runtime/rpc/methods/workspace-layout.ts
  • src/main/runtime/runtime-store-contract.ts
  • src/main/runtime/workspace-layout-frame-model-check.test-fixture.ts
  • src/main/runtime/workspace-layout-frame-model-check.ts
  • src/main/runtime/workspace-layout-frame-observer.ts
  • src/main/runtime/workspace-layout-live-titles.test.ts
  • src/main/runtime/workspace-layout-operation-frames.test.ts
  • src/main/runtime/workspace-layout-projection.ts
  • src/main/runtime/workspace-layout-stream-events.test-fixture.ts
  • src/main/runtime/workspace-layout-stream.test.ts
  • src/main/runtime/workspace-layout-stream.ts
  • src/renderer/src/runtime/runtime-layout-client.test.ts
  • src/renderer/src/runtime/runtime-layout-client.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-changes.ts
  • src/renderer/src/runtime/workspace-layout-frame-records.test.ts
  • src/renderer/src/runtime/workspace-layout-frame-sync.ts
  • src/renderer/src/store/workspace-layout-cache.ts
  • src/shared/workspace-layout/workspace-layout-disk-fields.ts
  • src/shared/workspace-layout/workspace-layout-load-bindings.ts
  • src/shared/workspace-layout/workspace-layout-load-types.ts
  • src/shared/workspace-layout/workspace-layout-model.ts
  • src/shared/workspace-layout/workspace-layout-published.ts
  • src/shared/workspace-layout/workspace-layout-records.test.ts
  • src/shared/workspace-layout/workspace-layout-records.ts
  • src/shared/workspace-layout/workspace-layout-stream-frames.test.ts
  • src/shared/workspace-layout/workspace-layout-stream-frames.ts
  • tests/e2e/helpers/workspace-layout-oracle-feed.ts

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

Comment thread src/main/ipc/pty/pane/stable-owner.ts Resolved
E2E Test added 2 commits October 20, 2026 07:38
@Jinwoo-H
Jinwoo-H merged commit a2e0f20 into main Oct 20, 2026
56 checks passed
brennanb2025 added a commit that referenced this pull request Oct 20, 2026
Main's layout-owner change (#31109, dark) kept a dead process's binding for the
fresh bind to swap, through the old attach helpers this branch replaced. Its
hook now runs in the single attach step: stable-pane adoption holds the pane's
reservation through its fresh launch, so the IPC lane passes the swap hook to
adoption and the absent owner is kept instead of retired. Absence retirement
keeps this branch's incarnation fence.
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