Skip to content

Add an inert read-only layout stream and the layout round-trip self-check - #26964

Merged
Jinwoo-H merged 3 commits into
mainfrom
layout-pr2-subscribe
Oct 9, 2026
Merged

Jinwoo-H merged 3 commits into
mainfrom
layout-pr2-subscribe

Conversation

@Jinwoo-H

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

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 12 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​450 $\color{#cf222e}{\Huge{\mathbf{−}}}$​407 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​43
Prod 14 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​559 $\color{#cf222e}{\Huge{\mathbf{−}}}$​202 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​357

ELI5

Today the window and main each keep their own copy of which tabs and panes exist. The rework gives that job to one owner, the runtime, and turns every window and phone into a viewer of it. Viewers need a way to receive the runtime's layout. This PR adds that feed, layout.subscribe, but nothing listens to it yet. It also adds a self-check that the layout module from the previous PRs reads and writes today's saved data without drifting. Nothing users see changes.

What Changed

  • layout.subscribe (new, read-only, inert). A client receives one snapshot of every workspace's layout, then a workspace event whenever one changes and a removed event when one goes. It can ask for only some workspaces. The method is served, but:

    • it is not advertised as a runtime capability;
    • it is not on the phone allowlist;
    • no client calls it yet.

    layout.unsubscribe ends a subscription.

  • An explicit published shape (workspace-layout-published.ts), not the internal model. Each workspace is addressed by its key alone; which host partition owns it stays internal to the host (a remote desktop would misread a server's local). Per workspace it carries:

    • the worktree id;
    • groups in the one tab order, and the group split tree;
    • each tab's display fields and the host that runs it;
    • for terminal tabs: the pane split tree, and each pane's id, its terminal and its title;
    • editor files and browser tabs.

    It leaves out runtime records (pane incarnations, sleeping agents, closed-tab records, default-tab marks), terminal spawn inputs, the legacy persistence values, content facts and any view's selection. The model can therefore change shape without breaking a wire contract.

  • How the stream works (workspace-layout-stream.ts). After each Store write it re-projects the sessions through the layout module's Loader, compares each workspace by value, and sends only what changed.

    • A burst of writes in one task is one projection.
    • It runs only while someone subscribes.
    • It publishes each workspace only from the partition that owns it, so a stray copy on another host is never shown.
    • One failing listener never costs the others an event.
    • Ids the Loader has to invent for stored data that lacks or repeats them (a headless host's group, a legacy row's pane, a repeated pane or tab id) are derived from what each stands in for, never from a counter. Removing an earlier workspace or tab does not change any other id, so no view remounts.
    • It replaces the unused terminal-topology publisher from refactor(terminal): project main's terminal layout after each save (no reader yet) #25682, which covered terminals only; that publisher, its projection and its slice type are deleted.
  • Round-trip self-check (workspace-layout-round-trip-check.ts). This is an idempotence check: Loader then Serializer, twice, and the second load must change nothing. It does not demand that old data load unchanged, since old writers deliberately disagree with it. The list of change kinds a first load may make is broad, so it only catches a field no Loader rule touches. To make new kinds visible anyway, the in-app check logs each new kind of first-load change with its count. It runs in three places:

    • in the app on every Store write in dev and e2e, logged as [workspace-layout] round-trip check: (and first-load changes:) and never thrown;
    • as a new roundTrip check in the layout oracle, on every partition at every step;
    • in every Loader unit case.

Why

This is PR 2 of the layout rework (design section 13). The model's internal shape is still moving: PR 1 just re-keyed pane data by pane id. Publishing an explicit projection lets later PRs change the model freely. Comparing by value instead of trusting object identity is needed because some persistence writers edit sessions in place.

The self-check found one real gap straight away. Main's "minimal row" mint stores the transient pendingActivationSpawn flag in saved rows. The window strips that flag and the disk-field table claimed nobody persisted it. The Loader drops it; it is now a documented, tested rule and in the baseline. PR 4 removes the mint itself.

Wire compatibility:

  • Adding a new method is safe for old clients, because they never call it.
  • A new client against an old host gets method_not_found. No client calls the method until it is advertised (PR 6), and that capability negotiation is where the skew is handled.
  • What existing methods publish is unchanged.

Linked Issue

Part of the workspace tab layout rework (STA-9417 family). No user-facing issue on its own: inert.

Visual Proof

N/A: no client calls the new method, and the self-check only logs.

Testing

  • workspace-layout-stream.test.ts:

    • nothing is watched until someone subscribes, and watching stops with the last subscriber;
    • only the owning partition's copy is published;
    • an unchanged write publishes nothing, and a burst is one event;
    • removal is published;
    • a failing listener is logged once, never reaches the write, and does not stop the other listeners;
    • removing an earlier workspace, then an earlier tab, leaves every other invented group, tab and pane id byte-identical (a load-order counter fails this test).
  • workspace-session-write-listeners.test.ts (ported from the old publisher):

    • a real Store through debounced set and patch, durable bind and retire, a failed write's rollback, and removal;
    • saved data and write order are identical with and without a subscriber, even a throwing one;
    • the exact sequence of published bindings matches;
    • the SSH workspace is published from its own partition (its tabs name that host).
  • workspace-layout-published.test.ts: order, fields, the per-tab host, and that internal records and per-view fields never appear.

  • rpc/methods/workspace-layout.test.ts:

    • not advertised and not phone-allowlisted;
    • the snapshot comes first, then only the asked-for workspaces, then end on unsubscribe.
  • workspace-layout-round-trip-watch.test.ts: runs only in dev, e2e or when asked; checks a settled burst once; skips unchanged partitions.

  • Loader normalization cases now also assert a clean round-trip check. New case: the spawn handoff flag is dropped and reported.

  • Oracles on this head (hidden, background launch):

    • window workspace-layout-oracle.spec.ts: 20/20 passed
    • headless workspace-layout-oracle-headless.spec.ts (orcad and Electron): 16/16 passed
  • pnpm tc, pnpm lint, pnpm run check:code-quality:changed: pass.

  • I manually tested these changes locally (inert: no client calls it)

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

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

  • Security: workspace permission, desktop-only.
  • SSH: each workspace is published from the partition that owns it.
  • Mobile: not allowlisted.
  • Performance: zero work with no subscriber. The dev/e2e check waits for writes to settle (1s) and skips unchanged partitions.

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)

…lf-check (inert)

- layout.subscribe streams each workspace's layout as an explicit published projection
  (tabs, groups, panes and their terminals), never the model itself: no runtime records,
  closed-tab records, spawn inputs or legacy persistence values. It is re-projected from the
  Store's sessions after each write, only while someone subscribes, and only from the
  partition that owns each workspace. Not advertised as a capability and not on the mobile
  allowlist, so nothing calls it yet.
- Replaces the unused terminal-topology publisher (#25682) it generalizes.
- The round-trip self-check: a partition must load and save to a fixed point, changing only
  the kinds of value the Loader's rules change. It runs on Store writes in dev and e2e (logged,
  never thrown) and as the oracle's new roundTrip check.
@coderabbitai

coderabbitai Bot commented Oct 9, 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: 23b32e07-4684-4d68-8cac-4c8a98533cc2

📥 Commits

Reviewing files that changed from the base of the PR and between 774427c and 8c19934.


📒 Files selected for processing (16)
  • src/main/persistence/loading-store/workspace-session-write-listeners.test.ts
  • src/main/runtime/workspace-layout-round-trip-watch.ts
  • src/main/runtime/workspace-layout-stream.test.ts
  • src/main/runtime/workspace-layout-stream.ts
  • src/shared/workspace-layout/workspace-layout-load-bindings.ts
  • src/shared/workspace-layout/workspace-layout-load-normalization.test.ts
  • src/shared/workspace-layout/workspace-layout-load-order.ts
  • src/shared/workspace-layout/workspace-layout-load-types.ts
  • src/shared/workspace-layout/workspace-layout-load-workspace.ts
  • src/shared/workspace-layout/workspace-layout-minted-ids.test.ts
  • src/shared/workspace-layout/workspace-layout-minted-ids.ts
  • src/shared/workspace-layout/workspace-layout-published.test.ts
  • src/shared/workspace-layout/workspace-layout-published.ts
  • src/shared/workspace-layout/workspace-layout-round-trip-check.ts
  • tests/e2e/AGENTS.md
  • tests/e2e/helpers/workspace-layout-oracle.ts

🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/e2e/AGENTS.md

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

Walkthrough

The change replaces per-worktree terminal topology publication with a workspace layout stream and subscription RPC methods. It adds a published layout projection and a round-trip checker that runs on Store writes under configured conditions and in the E2E layout oracle. It removes the terminal topology slice and publisher, and updates persistence tests to use workspace layouts or read session state directly.


Priority: ⬇️ Low

Merge Risk: 🔵 Low · up to 8c199

The new layout stream is inert and not used by any client. The remaining items are minor: the dev/e2e round-trip check can inspect an intermediate session during a write burst, and the e2e docs overstate the check's coverage. Neither blocks merging.

Pre-merge checks | Passed 4 | Failed 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 42.86% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 28 functions across 25 files. (1 skipped:… Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ 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 and concisely identifies both primary changes: the inert read-only layout stream and the layout round-trip self-check.
Description check Passed The description is detailed and follows the required template. It explains the user impact, implementation, rationale, testing, compatibility considerations, and checklist status. The linked issue is …

Full details: Docstring Coverage

Explanation

Docstring coverage is 42.86% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 28 functions across 25 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.

@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: 3


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 2699955a-16aa-4b93-914b-5ec776ccf322
📥 Commits

Reviewing files that changed from the base of the PR and between 35b145d and 774427c.

⛔ Files ignored due to path filters (1)
  • src/shared/rpc-contract/rpc-params-catalog.generated.ts is excluded by !**/*.generated.*
📒 Files selected for processing (25)
  • src/main/persistence/loading-store/workspace-session-write-listeners.test.ts
  • src/main/persistence/terminal-topology/terminal-sleep-quit-resume.test.ts
  • src/main/persistence/terminal-topology/terminal-topology-model.test.ts
  • src/main/runtime/orca-runtime.ts
  • src/main/runtime/rpc/methods/index.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/terminal-topology-projection.test.ts
  • src/main/runtime/terminal-topology-projection.ts
  • src/main/runtime/terminal-topology-publisher.test.ts
  • src/main/runtime/terminal-topology-publisher.ts
  • src/main/runtime/workspace-layout-round-trip-watch.test.ts
  • src/main/runtime/workspace-layout-round-trip-watch.ts
  • src/main/runtime/workspace-layout-stream.test.ts
  • src/main/runtime/workspace-layout-stream.ts
  • src/shared/rpc-contract/workspace-layout-params.ts
  • src/shared/terminal-topology-slice.ts
  • src/shared/workspace-layout/workspace-layout-disk-fields.ts
  • src/shared/workspace-layout/workspace-layout-load-normalization.test.ts
  • src/shared/workspace-layout/workspace-layout-published.test.ts
  • src/shared/workspace-layout/workspace-layout-published.ts
  • src/shared/workspace-layout/workspace-layout-round-trip-check.ts
  • tests/e2e/AGENTS.md
  • tests/e2e/helpers/workspace-layout-oracle.ts
💤 Files with no reviewable changes (5)
  • src/main/runtime/terminal-topology-projection.test.ts
  • src/main/runtime/terminal-topology-publisher.test.ts
  • src/main/runtime/terminal-topology-publisher.ts
  • src/shared/terminal-topology-slice.ts
  • src/main/runtime/terminal-topology-projection.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.

}
}
const stop = store.onWorkspaceSessionWritten?.(() => {
timer ??= setTimeout(check, SETTLE_MS)

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

Reset the timer after each write.

Line 45 starts the timer on the first write. A second write 900 ms later leaves only 100 ms before the check. If another write completes that update, the checker can report the intermediate session instead of the settled session. Reset the timer when the intended check is after a burst settles.

Proposed change
--- "a/src/main/runtime/workspace-layout-round-trip-watch.ts"
+++ "b/src/main/runtime/workspace-layout-round-trip-watch.ts"
@@ -42,7 +42,8 @@
     }
   }
   const stop = store.onWorkspaceSessionWritten?.(() => {
-    timer ??= setTimeout(check, SETTLE_MS)
+    if (timer) clearTimeout(timer)
+    timer = setTimeout(check, SETTLE_MS)
   })
   return () => {
     stop?.()
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
timer ??= setTimeout(check, SETTLE_MS)
if (timer) clearTimeout(timer)
timer = setTimeout(check, SETTLE_MS)

Comment thread tests/e2e/AGENTS.md Outdated
`workspace-layout-oracle.spec.ts` (window attached) and `workspace-layout-oracle-headless.spec.ts` (orcad and Electron `orca serve`, no window) drive layout journeys through the commands users, the CLI and paired clients send, and after every step decide pass/fail with no reviewer:

- **rules**: the runtime's layout (main's session over the read-only `session:get` IPC; a headless runtime's saved profile) against `workspace-layout-rules.ts`: a terminal in two panes, a pane in two tabs, a tab outside exactly one group, tab rows and tab bar disagreeing, two tab orders, an id changing for the same pane, tab or group. A sampler also runs the rules every 100 ms between steps; breaches that heal before a step settles are recorded as `(transient)`. (The unit model test checks every write exactly, via `store.onWorkspaceSessionWritten`.)
- **roundTrip**: each partition, through the layout module's Loader then Serializer, must reach a fixed point (a second load changes nothing) and change only what the Loader's documented rules change (`workspace-layout-round-trip-check.ts`). The same check runs in the app on every Store write in dev and e2e, logged as `[workspace-layout] round-trip check:`.

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

Describe the watcher’s actual coverage.

The watcher coalesces Store writes and checks the session when its timer fires. It does not check every intermediate write. Change “on every Store write” to describe checks after a burst of writes.

…ted listeners

- Every id the Loader invents is derived from what it stands in for (a workspace's group from
  its key, a pane from its row or tab and position, a repeated tab id from its terminal), so
  removing an earlier workspace or tab no longer re-ids later ones.
- The published layout no longer names its partition: the workspace key is the address and
  routing stays with the host; each tab still names the host that runs it.
- One throwing stream listener no longer costs the others the event.
- The self-check says plainly it is an idempotence check, and logs each new kind of first-load
  change with its count.
@Jinwoo-H
Jinwoo-H merged commit 0703073 into main Oct 9, 2026
48 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