Repository navigation
A paired desktop draws a layout-owner server's workspaces from its layout stream (switch-on builds only) - #31181
Conversation
…apply Co-Authored-By: Claude <[email protected]>
…ver workspaces and indexes handles; ids translate with session.tabs handles
…aces between frames and the mirror
…only paired servers (L18)
…he snapshot; e2e hook and spec
…focused one; a known-kind guard without a cast
…s draw only gated workspaces
📝 Walkthrough
Priority: ➖ Normal Merge Risk: 🔵 Low · up to
|
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
6d6883f0-8238-4f1f-82ed-33af4b114caa
📒 Files selected for processing: 32
.github/workflows/layout-owner-e2e.ymlsrc/main/runtime/rpc/methods/workspace-layout-paired-desktop.test.tssrc/main/runtime/rpc/methods/workspace-layout.test.tssrc/main/runtime/rpc/methods/workspace-layout.tssrc/renderer/src/app-shell/reconcile-hydrated-server-layout-frames-switch.test.tssrc/renderer/src/app-shell/reconcile-hydrated-workspace-tab-models.tssrc/renderer/src/env.d.tssrc/renderer/src/runtime/layout-frame-stream.tssrc/renderer/src/runtime/runtime-layout-client.test.tssrc/renderer/src/runtime/runtime-layout-client.tssrc/renderer/src/runtime/server-layout-frame-ids.test.tssrc/renderer/src/runtime/server-layout-frame-ids.tssrc/renderer/src/runtime/server-layout-frames-handover.test.tssrc/renderer/src/runtime/server-layout-frames.test-fixture.tssrc/renderer/src/runtime/server-layout-frames.test.tssrc/renderer/src/runtime/server-layout-frames.tssrc/renderer/src/runtime/web-runtime-session-snapshot.tssrc/renderer/src/runtime/web-session-tabs-sync/active-session-subscription.tssrc/renderer/src/runtime/web-session-tabs-sync/apply-snapshot.tssrc/renderer/src/runtime/web-session-tabs-sync/frame-drawn-server-workspaces.test.tssrc/renderer/src/runtime/web-session-tabs-sync/frame-drawn-server-workspaces.tssrc/renderer/src/runtime/web-session-tabs-sync/frame-drawn-workspace-status-patch.tssrc/renderer/src/runtime/web-session-tabs-sync/global-session-events.tssrc/renderer/src/runtime/web-session-tabs-sync/global-session-inventory-event.tssrc/renderer/src/runtime/web-session-tabs-sync/initial-terminal-seeder.tssrc/renderer/src/runtime/web-session-tabs-sync/load-initial.tssrc/renderer/src/runtime/web-session-tabs-sync/mirror-terminal-orphan-recovery.tssrc/renderer/src/runtime/web-session-tabs-sync/mirrored-terminal-handle-index.tssrc/renderer/src/runtime/web-session-tabs-sync/tracking-lifecycle.tssrc/renderer/src/runtime/workspace-layout-frame-drawn-workspaces.tssrc/renderer/src/runtime/workspace-layout-frame-sync.tstests/e2e/paired-desktop-server-layout-frames.spec.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.
| case 'snapshot': | ||
| server.clear() | ||
| desktop.clear() | ||
| position = { epoch: frame.epoch ?? '', seq: frame.seq ?? 0 } | ||
| return { | ||
| ...frame, | ||
| workspaces: frame.workspaces.map(({ key, layout }) => ({ | ||
| key, | ||
| layout: show(key, layout).layout | ||
| })) | ||
| } |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
A snapshot that fails translation leaves the translator half-filled, and later frames gate workspaces that the frames never draw.
tabIdRule throws for a tab kind it does not know. A newer paired server can send such a kind. In the snapshot branch, server.clear() and desktop.clear() run first. Then show adds each workspace in turn until one throws. The workspaces before that point stay in server.
How the failure develops:
- In
subscribeRuntimeLayout,deliversets the status tolivebefore it callsonFramefor a snapshot. Onlyrecordsframes are wrapped intry. The exception therefore escapes to the transport callback, and the stream stayslive. - The sync's
receivenever runs, so its cache does not hold these workspaces. - On the next
recordsframe,translatesucceeds for any change that does not touch the unknown kind. It also succeeds for a frame that names none of the partial keys. regate()inserver-layout-frames.tsthen gates the partial keys fromtranslator.keys(), andsetFrameDrawnServerWorkspacesstops the mirror from writing them.- The frame sync has no cache entry for these keys, so
flushdraws nothing for them. - Result: the workspace freezes on the desktop until a later resync, and the cycle can repeat on every reopen.
Fix: if any workspace in a snapshot fails, keep the translator empty. Then a records change for those keys throws inside recordChange before regate() runs, and the stream resubscribes as intended. Also, in runtime-layout-client.ts Line 183, wrap the snapshot's onFrame call. On error, call lose, so the stream reports lost and openServerFrames hands its workspaces back to the mirror.
🐛 Proposed fix
--- "a/src/renderer/src/runtime/server-layout-frame-ids.ts"
+++ "b/src/renderer/src/runtime/server-layout-frame-ids.ts"
@@ -264,17 +264,24 @@
return {
translate: (frame) => {
switch (frame.type) {
- case 'snapshot':
- server.clear()
- desktop.clear()
- position = { epoch: frame.epoch ?? '', seq: frame.seq ?? 0 }
- return {
- ...frame,
- workspaces: frame.workspaces.map(({ key, layout }) => ({
- key,
- layout: show(key, layout).layout
- }))
- }
+ case 'snapshot':
+ server.clear()
+ desktop.clear()
+ position = { epoch: frame.epoch ?? '', seq: frame.seq ?? 0 }
+ try {
+ return {
+ ...frame,
+ workspaces: frame.workspaces.map(({ key, layout }) => ({
+ key,
+ layout: show(key, layout).layout
+ }))
+ }
+ } catch (error) {
+ // No partial snapshot: a key held here would be gated with nothing drawn for it.
+ server.clear()
+ desktop.clear()
+ throw error
+ }
case 'workspace':
return { ...frame, layout: show(frame.key, frame.layout).layout }
case 'removed':📝 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.
| case 'snapshot': | |
| server.clear() | |
| desktop.clear() | |
| position = { epoch: frame.epoch ?? '', seq: frame.seq ?? 0 } | |
| return { | |
| ...frame, | |
| workspaces: frame.workspaces.map(({ key, layout }) => ({ | |
| key, | |
| layout: show(key, layout).layout | |
| })) | |
| } | |
| case 'snapshot': | |
| server.clear() | |
| desktop.clear() | |
| position = { epoch: frame.epoch ?? '', seq: frame.seq ?? 0 } | |
| try { | |
| return { | |
| ...frame, | |
| workspaces: frame.workspaces.map(({ key, layout }) => ({ | |
| key, | |
| layout: show(key, layout).layout | |
| })) | |
| } | |
| } catch (error) { | |
| // No partial snapshot: a key held here would be gated with nothing drawn for it. | |
| server.clear() | |
| desktop.clear() | |
| throw error | |
| } |
ELI5
When a desktop is paired to an Orca server whose own background process decides tab and pane layout, the desktop now draws that server's tabs from the server's layout stream instead of copying them from the older "session tabs" feed. This only happens in the internal test build with the new layout model turned on, and only with a server that says it supports it. Nothing changes in any build we ship.
What Changed
layout.intents.v1, the desktop opens one layout stream per server and draws that server's workspaces from it. Each workspace has one source at a time.Mechanism:
server-layout-frames.tsopens one stream per paired server that advertises the capability and isn't disconnected. It follows every paired server, not the focused one, and draws only the workspaces each server owns. A new runtime, pairing or connection replaces the stream. A server that is removed or stops advertising has its stream closed and its workspaces handed back (ledger L19).server-layout-frame-ids.tsis the one place server ids become desktop ids, matching the ids the mirror already uses:web-terminal-<id>;runtime:<env>;So switching source does not remount anything.
Handover, mirror to frames: the mirror stops writing a workspace's layout before the stream's first frame for it is shown. The store goes straight from the mirror's tree to the stream's tree.
Handover, frames to mirror: when the stream is lost or refused, the workspace goes back to the mirror with a fresh snapshot. The stream's tree stays until that snapshot replaces it. From then on the stopped stream draws nothing there, even while it reconnects, and a workspace that rejoins a stream is drawn again in full.
frame-syncnow takes a source (local or a server); only the local stream's positions answer this window's own layout replies.The client reopens a lost server stream with the same backoff as the local one.
layout.getRemoteSnapshotsnow returns only servers that are still paired (ledger L18).Which handle source survives (decision recorded in ledger L239, permanent): frames carry no terminal handle. A server mints a terminal's handle only while it builds its session.tabs rows, so a pure frame build cannot produce it. The desktop keeps its session.tabs subscription for these workspaces. The mirror's layout write is switched off, but its statuses and its per-surface handles keep flowing.
remote:<env>@@<handle>for its (host tab, leaf) surface. The join goes through the translation module's one id mapping, not a second lookup.pending-handledoes today.Still on the mirror until H5c (ledger L240): the mirror keeps its host-to-local tab id mappings and its close and focus intent records running for these workspaces. Today's session.tabs mutations still need them until desktop writes go to the server's main.
Owner-visible note (switch-on only): the first handover renames an open server file's editor id once, from its bare path to its owner-qualified id, exactly as a desktop restart already does today. Its draft carries over and the editor remounts once. The id-stable fix is owner question Q15.
Why
Linked Issue
Part of the terminal-layout final design (paired desktop to a server). No separate issue.
Visual Proof
N/A: no change in any shipped build. The path exists only in a build made with the layout-owner switch on, against a server that advertises the capability.
Testing
Unit:
layout.getRemoteSnapshotsfiltering.Remote stream reopen: the loss tests now run for both transports.
E2E (switch-on desktop and switch-on
orca serve, added to the switch-on leg):tests/e2e/paired-desktop-server-layout-frames.spec.ts. It proves:remote:handles and typing works;Static gate, and the switch-on main runtime and persistence suites at head and merge base.
I manually tested these changes locally
Automated tests added/updated, or explained why not below
AI Disclosure
Written with an AI coding agent; reviewed by an independent AI review pass and a delta review after fixes.
Review
One independent review found that a stopped stream could still draw a workspace already handed back. That is fixed, and the new test fails without the fix. The delta review found no regressions; its one low point (redraw a workspace that rejoins the gate) is also fixed, with a test that fails without the fix.
Agent skill upstream boundary
Notes
src/main/ipc/runtime.tsruntime:subscribe), which ends a stream with its own end frame, so no local transport carries frames that could drop without a close signal. Adds L239 (permanent) and L240 (H5c).Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)