Repository navigation
Add an inert read-only layout stream and the layout round-trip self-check - #26964
Conversation
…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.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configuration
📒 Files selected for processing (16)
🚧 Files skipped from review as they are similar to previous changes (1)
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 4 remain after this review. 📝 WalkthroughWalkthroughThe 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 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 |
|
There was a problem hiding this comment.
Actionable comments posted: 3
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
2699955a-16aa-4b93-914b-5ec776ccf322
⛔ Files ignored due to path filters (1)
src/shared/rpc-contract/rpc-params-catalog.generated.tsis excluded by!**/*.generated.*
📒 Files selected for processing (25)
src/main/persistence/loading-store/workspace-session-write-listeners.test.tssrc/main/persistence/terminal-topology/terminal-sleep-quit-resume.test.tssrc/main/persistence/terminal-topology/terminal-topology-model.test.tssrc/main/runtime/orca-runtime.tssrc/main/runtime/rpc/methods/index.tssrc/main/runtime/rpc/methods/workspace-layout.test.tssrc/main/runtime/rpc/methods/workspace-layout.tssrc/main/runtime/runtime-store-contract.tssrc/main/runtime/terminal-topology-projection.test.tssrc/main/runtime/terminal-topology-projection.tssrc/main/runtime/terminal-topology-publisher.test.tssrc/main/runtime/terminal-topology-publisher.tssrc/main/runtime/workspace-layout-round-trip-watch.test.tssrc/main/runtime/workspace-layout-round-trip-watch.tssrc/main/runtime/workspace-layout-stream.test.tssrc/main/runtime/workspace-layout-stream.tssrc/shared/rpc-contract/workspace-layout-params.tssrc/shared/terminal-topology-slice.tssrc/shared/workspace-layout/workspace-layout-disk-fields.tssrc/shared/workspace-layout/workspace-layout-load-normalization.test.tssrc/shared/workspace-layout/workspace-layout-published.test.tssrc/shared/workspace-layout/workspace-layout-published.tssrc/shared/workspace-layout/workspace-layout-round-trip-check.tstests/e2e/AGENTS.mdtests/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) |
There was a problem hiding this comment.
🎯 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.
| timer ??= setTimeout(check, SETTLE_MS) | |
| if (timer) clearTimeout(timer) | |
| timer = setTimeout(check, SETTLE_MS) |
| `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:`. |
There was a problem hiding this comment.
🎯 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.
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 aworkspaceevent whenever one changes and aremovedevent when one goes. It can ask for only some workspaces. The method is served, but:layout.unsubscribeends 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'slocal). Per workspace it carries: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.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:[workspace-layout] round-trip check:(andfirst-load changes:) and never thrown;roundTripcheck in the layout oracle, on every partition at every step;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
pendingActivationSpawnflag 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:
method_not_found. No client calls the method until it is advertised (PR 6), and that capability negotiation is where the skew is handled.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:workspace-session-write-listeners.test.ts(ported from the old publisher):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:endon 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):
workspace-layout-oracle.spec.ts: 20/20 passedworkspace-layout-oracle-headless.spec.ts(orcad and Electron): 16/16 passedpnpm 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
Notes
workspacepermission, desktop-only.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)