Skip to content

A paired desktop draws a layout-owner server's workspaces from its layout stream (switch-on builds only) - #31181

Merged
Jinwoo-H merged 14 commits into
mainfrom
fd/h5b-desktop-layout-stream
Oct 20, 2026
Merged

Jinwoo-H merged 14 commits into
mainfrom
fd/h5b-desktop-layout-stream

Conversation

@Jinwoo-H

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

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 9 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1813 $\color{#cf222e}{\Huge{\mathbf{−}}}$​51 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1762
Prod 23 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1361 $\color{#cf222e}{\Huge{\mathbf{−}}}$​74 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1287

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

  • Before: a paired desktop always rebuilt a server's tabs, groups and panes from the session.tabs feed (the "mirror").
  • After (switch-on builds only): for a server that advertises 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.ts opens 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.ts is the one place server ids become desktop ids, matching the ids the mirror already uses:

    • terminal tabs web-terminal-<id>;
    • hosts runtime:<env>;
    • editor files owned by the server.

    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-sync now 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.getRemoteSnapshots now 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.

  • Each pane binds remote:<env>@@<handle> for its (host tab, leaf) surface. The join goes through the translation module's one id mapping, not a second lookup.
  • A bound pane without a handle yet shows as pending, as pending-handle does today.
  • Desktop terminal ids are exactly the mirror's, so the handover never reattaches a terminal.

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

  • Mixed versions are the normal state. The desktop only takes this path for a server that advertises the capability, and an older server keeps today's mirror.
  • Translating ids at the frame boundary keeps every terminal-attach and routing path unchanged. Drawing raw server ids would have changed all of them.
  • Taking handles from session.tabs keeps the frame build pure and needs no new server work; session.tabs stays main's client projection after the flip (A2).

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:

    • id translation, including a round trip for every id kind and refusal of an unknown tab kind;
    • records re-diffed under desktop ids, and rebinding when a handle arrives;
    • per-server streams: which servers get one, removal (L19), replacement, a server whose ownership arrives after its snapshot;
    • the handover both ways: no empty tree, zero reattaches;
    • handle arrival order: frame first (pending, then one bind in place), handle first, handle replaced;
    • a server's frames never release a local layout reply;
    • two desktops bind the same handles;
    • the mirror gate: layout not written, statuses still applied, id mappings and intents kept, resync on handback;
    • layout.getRemoteSnapshots filtering.
  • 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:

    • the workspace is drawn from frames and its tree equals the server's;
    • terminals bind remote: handles and typing works;
    • after a serve restart both sides show the same tree;
    • a server-created tab shows. It passed twice locally.
  • 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

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

  • SSH and folder workspaces: unchanged. Only workspaces a capable paired server owns move.
  • Mobile: unchanged.
  • Compatibility: new desktop with an old server, and old desktop with a new server, keep today's mirror path.
  • Ledger: closes L18, L19. L20 and L39 are recorded as not due before the flip: the local target is dispatched in-process in main (src/main/ipc/runtime.ts runtime: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).
  • Writes from the desktop to a server's main (layout.apply), view facts per connection, and the old shortcuts stepping aside are H5c.

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 and others added 14 commits October 20, 2026 10:11
…ver workspaces and indexes handles; ids translate with session.tabs handles
…focused one; a known-kind guard without a cast
@coderabbitai

coderabbitai Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

📝 Walkthrough

The change adds paired-server layout streams and translates server-published layouts for desktop rendering. It coordinates frame ownership with mirrored session-tab updates, terminal-handle binding, and workspace restoration. Remote snapshot reads now exclude environments that are no longer listed. Tests cover stream recovery, frame handover, layout synchronization, terminal operation, and end-to-end behavior across a server restart.

Priority: ➖ Normal

Merge Risk: 🔵 Low · up to 4d439

With the new layout-owner switch on, a newer paired server that sends an unrecognized tab kind can leave the desktop holding a partial layout. Affected workspaces may stop updating until a resync. This path is limited to switch-on builds and mixed server versions. Make snapshot translation all-or-nothing before relying on this path.

Pre-merge checks: Passed 3 · Failed 2

Failed Failed checks: 2 warnings

Check name Status Explanation Resolution
Description check Warning The description thoroughly covers the user-visible change, implementation, rationale, testing, compatibility, visual proof, and checklist. However, the required Linked Issue section does not provide a… Add the actual linked issue reference in the Fixes # section. If this is a maintainer change covered by an existing design or tracking issue, reference that issue explicitly instead of stating that no separate issue exists.
Docstring Coverage Warning Docstring coverage is 60.98% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 82 functions across 31 files. (1 skipped:… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 3 passed
Check name Status Explanation
Title check Passed The title clearly states the primary change: paired desktops draw workspaces from a layout-owner server's layout stream. It also identifies that the behavior applies only to switch-on builds.
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 thoroughly covers the user-visible change, implementation, rationale, testing, compatibility, visual proof, and checklist. However, the required Linked Issue section does not provide an actual issue reference and instead states that there is no separate issue.

Resolution

Add the actual linked issue reference in the Fixes # section. If this is a maintainer change covered by an existing design or tracking issue, reference that issue explicitly instead of stating that no separate issue exists.

Full details: Docstring Coverage

Explanation

Docstring coverage is 60.98% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 82 functions across 31 files. (1 skipped: 1 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

  • 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: 6d6883f0-8238-4f1f-82ed-33af4b114caa
📥 Commits

Reviewing files that changed from the base of the PR and between 99e91c1 and 4d439cf.

📒 Files selected for processing: 32
  • .github/workflows/layout-owner-e2e.yml
  • src/main/runtime/rpc/methods/workspace-layout-paired-desktop.test.ts
  • src/main/runtime/rpc/methods/workspace-layout.test.ts
  • src/main/runtime/rpc/methods/workspace-layout.ts
  • src/renderer/src/app-shell/reconcile-hydrated-server-layout-frames-switch.test.ts
  • src/renderer/src/app-shell/reconcile-hydrated-workspace-tab-models.ts
  • src/renderer/src/env.d.ts
  • src/renderer/src/runtime/layout-frame-stream.ts
  • src/renderer/src/runtime/runtime-layout-client.test.ts
  • src/renderer/src/runtime/runtime-layout-client.ts
  • src/renderer/src/runtime/server-layout-frame-ids.test.ts
  • src/renderer/src/runtime/server-layout-frame-ids.ts
  • src/renderer/src/runtime/server-layout-frames-handover.test.ts
  • src/renderer/src/runtime/server-layout-frames.test-fixture.ts
  • src/renderer/src/runtime/server-layout-frames.test.ts
  • src/renderer/src/runtime/server-layout-frames.ts
  • src/renderer/src/runtime/web-runtime-session-snapshot.ts
  • src/renderer/src/runtime/web-session-tabs-sync/active-session-subscription.ts
  • src/renderer/src/runtime/web-session-tabs-sync/apply-snapshot.ts
  • src/renderer/src/runtime/web-session-tabs-sync/frame-drawn-server-workspaces.test.ts
  • src/renderer/src/runtime/web-session-tabs-sync/frame-drawn-server-workspaces.ts
  • src/renderer/src/runtime/web-session-tabs-sync/frame-drawn-workspace-status-patch.ts
  • src/renderer/src/runtime/web-session-tabs-sync/global-session-events.ts
  • src/renderer/src/runtime/web-session-tabs-sync/global-session-inventory-event.ts
  • src/renderer/src/runtime/web-session-tabs-sync/initial-terminal-seeder.ts
  • src/renderer/src/runtime/web-session-tabs-sync/load-initial.ts
  • src/renderer/src/runtime/web-session-tabs-sync/mirror-terminal-orphan-recovery.ts
  • src/renderer/src/runtime/web-session-tabs-sync/mirrored-terminal-handle-index.ts
  • src/renderer/src/runtime/web-session-tabs-sync/tracking-lifecycle.ts
  • src/renderer/src/runtime/workspace-layout-frame-drawn-workspaces.ts
  • src/renderer/src/runtime/workspace-layout-frame-sync.ts
  • tests/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.

Comment on lines +267 to +277
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
}))
}

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.

🩺 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, deliver sets the status to live before it calls onFrame for a snapshot. Only records frames are wrapped in try. The exception therefore escapes to the transport callback, and the stream stays live.
  • The sync's receive never runs, so its cache does not hold these workspaces.
  • On the next records frame, translate succeeds for any change that does not touch the unknown kind. It also succeeds for a frame that names none of the partial keys.
  • regate() in server-layout-frames.ts then gates the partial keys from translator.keys(), and setFrameDrawnServerWorkspaces stops the mirror from writing them.
  • The frame sync has no cache entry for these keys, so flush draws 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.

Suggested change
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
}

@Jinwoo-H
Jinwoo-H merged commit b8a5c8f into main Oct 20, 2026
49 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