Repository navigation
refactor(terminal): project main's terminal layout after each save (no reader yet) - #25682
Conversation
…on write Adds a by-value projection of each worktree's persisted terminal topology and a publisher hooked on the two persistence funnels (scheduleSave and durable mutations). Changed slices are pushed to the local window on session:terminal-topology-changed with a monotonic publishSeq; a startup pull (session:get-terminal-topology-slices) and publishSeq on pty:spawn and session:close-terminal-surface replies are in place. No renderer consumer yet, so behavior and saved state are unchanged. Observer failures are counted and logged once and never reach the save.
…r pulls Writes now cost nothing extra until the first session:get-terminal-topology-slices pull (or subscribe()) takes the baseline; markDirty before that is a no-op.
|
Important Review skippedReview was skipped as selected files did not have any reviewable changes. ⚙️ Run configuration
You can disable this status message by setting the Use the checkbox below for a quick retry:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configuration
📒 Files selected for processing (5)
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 adds shared types and projection helpers for worktree terminal-topology slices. It adds workspace-session write listeners and notifies them during write scheduling and admitted mutation callbacks. A publisher reconciles projected slices, assigns publication sequence numbers, and sends changed or removed worktree slices to a sink. Tests cover projection, listener behavior, publication sequencing, and failure handling. Priority: ⬇️ Low Merge Risk: 🔵 Low · up to A temporary topology-publication failure can leave a snapshot stale until another write. The write path remains protected, but the publication gap warrants owner awareness before merging. Security Architecture ReviewSecurity architecture risk: 🔵 Low · up to The change has a limited recovery risk when delivery fails. It is not connected to a live reader in this revision, and no new attacker-accessible path was established. Retained concerns
Security review detailsSecurity Blast Radius
Trust Boundaries and Controls
Resilience and Maintainability Implications
Hardening Proposals
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/main/runtime/terminal-topology-publisher.ts (1)
72-78: 🎯 Functional Correctness | 🔵 Trivial | 💤 Low valueDo not return
lastSeqon the sinkless read path.With no sink,
readSlicesprojects live state and stamps every slice withthis.lastSeq.setSink(null)clearspublishedbut keepslastSeq. A worktree that changed after the last push can therefore come back with apublishSeqthat equals an earlier push for different content. A reader keeps the highestpublishSeqper worktree, so a later push could carry a value it treats as already seen. This path is reachable only during the no-window gap, and that gap has no IPC reader today. Increment the sequence for each slice on this path, or document that this path is unsequenced.Proposed fix
return [...this.readOwners()].map(([worktreeId, owner]) => ({ ...projectTerminalTopologySlice(owner.session, owner.hostId, worktreeId), - publishSeq: this.lastSeq + publishSeq: ++this.lastSeq }))
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
8c1b2e24-898e-4feb-a6ca-af9fc9a9070f
📒 Files selected for processing (18)
src/main/ipc/pty/ipc/spawn.tssrc/main/ipc/session.tssrc/main/persistence/loading-store/primary-state-write-runtime.tssrc/main/persistence/loading-store/primary-state-writes.tssrc/main/persistence/loading-store/store-runtime-state.tssrc/main/persistence/loading-store/workspace-session-write-listeners.test.tssrc/main/persistence/loading-store/workspace-session-write-listeners.tssrc/main/persistence/loading-store/write-scheduling.tssrc/main/runtime/orca-runtime.tssrc/main/runtime/runtime-notifier-contract.tssrc/main/runtime/runtime-store-contract.tssrc/main/runtime/runtime-workspace-session-controller.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/window/runtime-window-lifecycle.tssrc/shared/terminal-topology-slice.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.
There was a problem hiding this comment.
ℹ️ No blocking issues — the change is correctly dormant and the save-funnel census checks out. Two latent contract gaps in the publisher are worth tightening before the reader lands; both are inline.
Reviewed changes
- New snapshot type and projection —
src/shared/terminal-topology-slice.tsandsrc/main/runtime/terminal-topology-projection.ts: a per-worktree view of main's topology (tabs with topology/creation fields only, layoutroot/ptyIdsByLeafId/titlesByLeafId, sleeping records, per-reporevision), read only from the partition that owns the worktree. - Dormant publisher —
src/main/runtime/terminal-topology-publisher.ts: coalesces session writes viaqueueMicrotask, diffs by value (isDeepStrictEqualagainststructuredCloned snapshots), pushes changed and removed slices with a monotonicpublishSeq, and stays off until the first pull/subscribe. - Runtime wiring —
src/main/runtime/orca-runtime.ts: constructs the publisher, registersstore.onWorkspaceSessionWritten(() => markDirty()), binds the sink fromsetNotifierto the local window, and exposessettleTerminalTopology/getTerminalTopologySlices. - Save-funnel observer —
workspace-session-write-listeners.tsplus hooks inwrite-scheduling.ts(domain-filtered) andprimary-state-writes.ts(runDurableMutationfinally, covering rollback); listener throws are caught and logged once so a save is never affected. - Local IPC —
session:get-terminal-topology-slicespull,session:terminal-topology-changedpush, and an optionalpublishSeqon thepty:spawnandsession:close-terminal-surfacereplies. - Tests — projection and publisher unit tests (batching, in-place change detection, removal, seq ordering, dormant mode) and an inertness test asserting saved state and write order are identical with/without the observer, including a throwing observer.
I also verified independently and via a census of main-process writers that no path mutates in-snapshot topology without passing through scheduleSave or runDurableMutation: the two documented bypasses (async scrollback swap, offline profile documents) touch fields the projection never reads, and the load-time sweep reaches scheduleSave before the listener is registered, so it is an inert no-op.
deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏
| if (!this.dirty) { | ||
| return | ||
| } | ||
| this.dirty = false |
There was a problem hiding this comment.
flush() clears dirty before the guarded reconcile runs. If readOwners() or a projection throws — the PR body documents ambiguous-folder owner resolution as exactly this trigger — the whole reconcile aborts after dirty is already false, and no retry is armed. That burst's topology changes are never pushed (and reconcile is all-or-nothing, so healthy worktrees in the same pass are dropped too); publishing only resumes on the next write, which may never come once the layout has settled.
Technical details
# A projection/owner-read throw consumes `dirty` and loses the burst
## Affected sites
- `src/main/runtime/terminal-topology-publisher.ts:58-64` — `flush()` sets `dirty = false` before `guard(() => this.reconcile(true))`.
- `src/main/runtime/terminal-topology-publisher.ts:84-109` — `reconcile` iterates all owners in one pass and aborts on the first throw.
- `src/main/runtime/terminal-topology-publisher.ts:116-126` — `guard` swallows the throw.
## Required outcome
- A transient projection/owner-read failure should not silently lose the changes it prevented from being published; publishing should not require an unrelated later write to resume.
## Suggested approach
- Keep `dirty` set until `reconcile` succeeds, or re-arm a bounded retry on failure. A naive unconditional re-queue could spin while the ambiguity persists, so gate it.…r and save hook Drop the window sink, pull handler and publishSeq replies; no listener attaches in production. Filter sleeping records by worktree id only, and guard observer failures once inside the publisher. Co-Authored-By: Claude <[email protected]>
There was a problem hiding this comment.
ℹ️ No critical issues — this delta narrows the PR to an unwired publisher plus the dormant save hook. One failure-ordering gap is inline; the earlier
flush()concern remains open.
Reviewed changes
- Runtime wiring removed —
OrcaRuntimeServiceno longer constructs the publisher, binds a sink fromsetNotifier, or exposessettleTerminalTopology/getTerminalTopologySlices; the IPC pull/push channels, notifier/store contracts, and window-lifecycle send are gone. The publisher is now an unwired class whose sink arrives via the constructor. - Publisher API reworked — dropped
setSink,subscribe,readSlices, andfailureCount;WorkspaceSessionOwnermoved here fromRuntimeWorkspaceSessionController, and the "dormant until a reader subscribes" state is gone. - Save hook simplified —
notifyWorkspaceSessionWrittenno longer short-circuits on an empty listener set and no longer catches listener throws; the publisher's ownflushguard logs the first failure instead. - Sleeping-record projection narrowed — only records whose
worktreeIdmatches the worktree are included; the paneKey tab-prefix fallback was removed. - Tests reworked to the new API: first-flush publishing, per-burst coalescing, in-place edits, removal, monotonic
publishSeq, and a throwing sink/projection.
deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏
| for (const snapshot of removed) { | ||
| this.published.delete(snapshot.worktreeId) | ||
| this.send({ publishSeq: ++this.lastSeq, snapshot }) | ||
| } | ||
| for (const snapshot of changed) { | ||
| const entry = { publishSeq: ++this.lastSeq, snapshot } | ||
| this.published.set(snapshot.worktreeId, entry) | ||
| this.send(entry) | ||
| } |
There was a problem hiding this comment.
reconcile commits the published entry (or deletes it for a removal) before send runs, and send is no longer individually guarded. A throwing sink therefore aborts the rest of the pass and, worse, records the failed slice as already published — a removal is deleted from published outright — so it is never re-sent unless that worktree changes again. The logs a throwing sink or projection once test drives this exact path but only asserts the warning count, so it passes with the slice silently lost.
Technical details
# A throwing sink marks the undelivered slice as published
## Affected sites
- `src/main/runtime/terminal-topology-publisher.ts:79-87` — `published.delete` / `published.set` run before `this.send(...)`, and `send` throws straight into `flush`'s guard.
## Required outcome
- A slice whose `send` throws must not be recorded as delivered, so a later flush can retry it, and one failing send must not drop the other worktrees in the same pass.…heck (#26964) * feat(layout): read-only layout.subscribe stream and the round-trip self-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. * fix(layout): know the spawn handoff main's minimal row mint stores * fix(layout): name-based invented ids, no partition on the wire, isolated 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
Later in this refactor, the app window will stop keeping its own copy of the terminal layout and will follow main's copy instead. To do that, main first needs a way to notice every time the saved layout changes and to describe one workspace's layout as a single snapshot. This PR adds those two pieces only. Nothing is connected to them yet, so nothing changes for users and no extra work runs.
What Changed
scheduleSaveand the durable-mutation runner, including its rollback path) now tell any registered observers that the workspace sessions changed. Observers register withonWorkspaceSessionWritten. No observer is registered in the app today, so the hook loops over an empty set.src/shared/terminal-topology-slice.tsandsrc/main/runtime/terminal-topology-projection.tsturn one worktree's saved session into a snapshot: its tabs, split layouts, which terminal sits in each pane, pane titles, sleeping agent records for that worktree, and a revision number. Display-only fields are left out.src/main/runtime/terminal-topology-publisher.tstakes the snapshot source and a send function in its constructor. When told something changed, it batches the burst, compares each worktree's snapshot by value with what it last sent, and sends only the changed ones (plus an empty snapshot for a worktree that lost all its rows), each with an increasing sequence number. If building or sending a snapshot throws, it logs once and carries on; the error never reaches the save.Before/after for users: none.
Why
The alternative was to first route every place in main that changes the terminal layout through one new module, so that module could announce changes. Checking each of those writers showed they all already go through one of the two save paths, so hooking those two paths sees every change without that rerouting. Keeping the publisher unconnected lets it be reviewed and tested on its own, and the change that actually turns it on stays small.
Linked Issue
Maintainer PR. Part of the terminal layout refactor (Linear STA-9417, STA-9259).
Visual Proof
N/A: no behavior or UI change; nothing in the app uses the new code yet.
Testing
pnpm tcand oxlint on the changed files pass after merging currentmain.Save-hook test on a real Store: the same sequence of writes (bind a pane, split, write to an SSH host's rows, a failed write that rolls back, remove the worktree) is run with no observer, with a publisher attached, and with an observer that throws. The saved state is identical in all three, and the throwing observer is logged once. The attached publisher sees each committed change, including the rollback and the removal, in increasing sequence order.
Publisher and snapshot unit tests: first flush, one push per burst, catching in-place edits while ignoring equal or display-only rewrites, the empty snapshot on removal, sequence ordering, and a throwing send function.
npx vitest run --config config/vitest.config.tson the three new test files: 12 tests pass.I manually tested these changes locally
Automated tests added/updated, or explained why not below
Not manually tested in the app: no code path in the app reaches the publisher yet.
Review
Agent skill upstream boundary
docs/reference/agent-skill-sharing-upstream-boundary.mdand copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.Notes
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)