Skip to content

fix(layout-owner): paired desktops see server-created and server-closed tabs (C3, C4) - #52149

Merged
Jinwoo-H merged 16 commits into
layout-owner-v2from
layout-owner-c3-c4-server-frames
Nov 29, 2026
Merged

Jinwoo-H merged 16 commits into
layout-owner-v2from
layout-owner-c3-c4-server-frames

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

A paired desktop learns about a server's tabs only from the server's layout frames. Before this PR, some things the server did never reached the desktop, and some left stale state behind:

  1. A terminal created on the server (for example by the CLI on a windowless orca serve host) never showed on the desktop until the user opened that workspace. The desktop drew a server workspace from frames only once it held groups for it, while the session.tabs mirror was already switched off for that workspace.
  2. Closing a tab on the server left its terminal binding on the desktop. The frame removed the row and the pane tree, but kept the tab's PTY binding and scrollback.

This PR fixes both. It also fixes the cost and the stale-state gaps that review and the new tests found.

Files Added Deleted Net
Test 13 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​2154 $\color{#cf222e}{\Huge{\mathbf{−}}}$​30 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​2124
Prod 15 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​684 $\color{#cf222e}{\Huge{\mathbf{−}}}$​193 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​491

Before / after

Before After
CLI creates a terminal in a server workspace the desktop never opened not shown shown: the server's frames draw every workspace the desktop mirrors from it
Server closes a tab, a pane of a split, a tab mid-start, or the focused tab binding, scrollback, pending startup and the global focused tab are left behind all retired
Server closes and recreates a tab with the same id (live, or while the desktop was disconnected) the dead PTY stays on the row and its binding the old PTY and its pane's scrollback go
Server removes a workspace its rows, pane trees and bindings stay they go
A server tab the desktop never mounted ptyId null, no binding, so it cannot be parked and reports no live terminal bound to its live terminal, as the old mirror did
Connect with 1,900 server workspaces (frame flush) 1,348 ms at this PR's first head (7.6 s at 3,700) 116-133 ms (200-235 ms at 3,700)
One workspace's frame after connect, at 1,900 – about 5 ms
View report work per store write, at 1,900 10-12 ms (median of 20) 3-4 ms: each workspace's view is cached by its own inputs
A tab moved, or a workspace renamed, into a workspace another build of the same flush drew its pane tree and browser pages were deleted kept

The numbers come from a scratch benchmark on a loaded shared Mac, so they are noisy; ranges are from three runs.

Mechanism

  • A server's frames draw every workspace the desktop mirrors from it (server-layout-frames.ts), opened or not, because they are its only source.
  • Each keyed map is copied once per build (keyedDraft). Before, every key copied the whole map, so a build was O(N²).
  • One reconcile step (frame-dropped-terminal-tab-records.ts), run on every frame build. It compares the window's per-tab state against the frame by tab id and pane leaf. A tab the frame dropped takes its PTY binding, scrollback, pending startup and the global focused-tab id with it. A pane that left takes its PTY and its scrollback. A workspace main removed is built from no layout, so its records go (workspace-layout-frame-sync.ts). Tab-level checks look only at the framed workspaces, unless a tab actually left. The tab and pane-tree half of a build is buildLayoutFrameTerminalPatch (frame-terminal-rows.ts).
  • What is still shown elsewhere stays (frame-records-shown-outside.ts). A tab or browser tab one build drops, but which another build of the same flush already shows, keeps its pane tree, binding and pages.
  • Removal is scoped. A removed workspace is wiped only if the frame source owns it. The removed set clears on start, when the sync isn't live, and on hand-back, which also forgets what was shown. A workspace the server itself removed is not resynced to the mirror.
  • Server rows carry their live binding (frame-row-live-bindings.ts), except for tabs the window's own in-flight split or close holds. For server sources, each row gets its active pane's terminal, and ptyIdsByTabId gets its live panes, whether or not the pane is mounted. A pane with a start status counts as unbound. Restore flags stay on the row, because a remote binding with every pane live already settles them for parking.
  • No new bridge between the window's copy and main's copy.

Census rows

  • C3 (L313): expected-fail marks removed from headless-serve-cli-terminal-retention-parity and from headless-paired-remote-terminal-retention-memory (cold-activates).
  • C4 (L307): expected-fail mark removed from paired-remote-terminal-serve-restart-binding.
  • The cold-activation oracle reads the row binding again. It now also checks, before any tab is force-mounted, that unvisited tabs report their live terminal and stay parked across switching away and back.

How it was tested

Switch on (ORCA_LAYOUT_OWNER=main, ORCA_SERVER_LAYOUT_OWNER=main, ORCA_E2E_WEB_CLIENT=1, all exported and logged), darwin, hidden windows:

  • e2e, 20 of 20 passed on the final code: headless-serve-cli-terminal-retention-parity, headless-paired-remote-terminal-retention-memory (both tests), paired-remote-terminal-serve-restart-binding, the four new specs from test(layout-owner): switch-on edge-case tests against #52149 (C3, C4) #52196 (paired-server-frames-disconnect-and-restart, -close-and-reopen, -many-workspaces, paired-two-desktops-and-phone-tabs), headless-serve-desktop-activation, terminal-cold-activation-deferral, terminal-pane-close-layout-consistency, terminal-tab-close-restart-persistence and local-cli-terminal-retention.
  • Units: the test(layout-owner): switch-on edge-case tests against #52149 (C3, C4) #52196 unit tests pass (frame-dropped-terminal-tab-records, server-layout-frames-lifecycle). vitest related on every changed source file passes with the switch on and off.
  • typecheck:ci, oxlint and the ratchet runner are clean.

Layout-writer ratchet

The new frame-applier files have baseline entries: frame-terminal-rows.ts (2, moved out of workspace-layout-frame-store-patch.ts, which drops from 12 to 10), frame-dropped-terminal-tab-records.ts (3) and frame-row-live-bindings.ts (2). Each one applies main's frame to the window's own records; none writes layout of its own. The total goes from 548 to 553.

Performance

Every keyed map is copied once per build instead of once per key, so connecting is O(workspaces). Following the owner's call, the desktop still builds, saves and view-reports every server workspace it mirrors. The view report caches each workspace's view by its own inputs, so a store write rebuilds only the workspaces it touched: 3-4 ms per write at 1,900 workspaces, down from 10-12 ms.

Visible changes

  • Bug fixes only. A server-created tab now shows on the paired desktop before its workspace is opened. Server-side closes, recreates and removals no longer leave dead bindings, scrollback or a dangling focused tab. Server tabs the desktop never mounted now park and report their live terminal.

…rames and retire bindings of tabs frames drop

A paired desktop's frames drew a server workspace only after the desktop held groups for it, while
the session.tabs mirror already skipped it, so a tab created on the server (by the CLI on a
windowless host) never showed until the user opened the workspace. Frames now draw every workspace
the desktop mirrors from that server.

A tab a frame drops also takes its window-side PTY binding and local scrollback with it, as a
window close does; before, a server-side close left the desktop holding a dead binding.

Census rows C3 (L313) and C4 (L307): expected-fail marks removed.
… from its pane tree

A frame-drawn row stays unbound until its pane mounts; the server's binding is on the pane tree.
The check that activation attaches the original terminal is unchanged.
@greptile-apps

greptile-apps Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

Confidence Score: 4/5 · The PR still needs the existing fix for sleeping terminals that retain live bindings before merging.RetriggerView in GreptileConfidence Score: 4/5

[Medium impact] The changes reach paired-server workspace display and terminal state across mirrored workspaces.

The PR still needs the existing fix for sleeping terminals that retain live bindings before merging.

Findings

  1. P1 Sleeping terminals still look live ▶

Summary

Server frames now draw unopened mirrored workspaces and remove records for closed tabs, panes, and workspaces.

  • Paired desktops draw server tabs from every mirrored workspace.
  • Server tab and pane changes clear stale terminal state on paired desktops.
  • Frame builds and server view reports reuse work across workspaces.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Server layout frame] --> B[Translate IDs and terminal handles]
  B --> C[Track changed and removed workspaces]
  C --> D[Build workspace records]
  D --> E[Retire dropped terminal records]
  E --> F[Import live server bindings]
  F --> G[Update desktop store]
  G --> H[Report workspace view]
Loading

Reviews (10) · Last reviewed commit: "chore(layout-owner): the view report tak..." · Reviewed by Greptile

…y and reconcile window tab state by identity

- Unopened server workspaces get terminal rows and pane trees only; the full build runs when one is
  opened or activated, and saves and view reports skip them.
- Frame builds copy each keyed map once (was a copy per key).
- One reconcile step retires the window's per-tab state that no longer matches main's frame: a
  dropped tab's bindings, scrollback, pending startup and focus; a closed or rebound pane's
  terminal and scrollback; a removed workspace's rows and pane trees.
- Server frame rows carry their live terminal before the pane mounts, as the session.tabs mirror did.
- Cold-activation oracle reads row bindings again and checks parking across a switch before any
  tab is force-mounted.
…er-c3-c4-server-frames

# Conflicts:
#	.github/workflows/layout-owner-switch-on.yml
Comment on lines +48 to +50
const panes = live.get(row.id)
if (!panes) {
return

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Sleeping terminals still look live

When a server terminal stops or sleeps while its tab is unmounted on this desktop, the early return leaves its old binding in ptyIdsByTabId. Tabs with no live panes have no entry in live. Row merging preserves the old ptyId, and cleanup only retires panes whose leaf IDs disappeared. A sleeping pane keeps its leaf ID, so the desktop continues to report a live terminal and can treat stale titles as current activity.

Reconcile empty live-pane lists too: clear ptyIdsByTabId when none remain, while keeping any history hint on the row separate from live state.

… keep the O(N) build and the reconcile

Owner decision: no lazy listing of unopened server workspaces and no save or view-report skips for
now. Kept: one copy per keyed map, the dropped-tab scan over framed workspaces only, the identity
reconcile, removed-workspace retirement and the live row bindings.
…bs keep their bindings, scoped removal, cached view report

- A tab moved (or a workspace renamed) into a workspace an earlier build of the same flush drew keeps
  its pane tree and browser pages when its old workspace builds.
- Server row bindings skip tabs the window's own split or close holds.
- A removed workspace is wiped only if the source owns it; the removed set clears on start, when not
  live and on hand-back (which also forgets what was shown); a server-removed workspace is not
  resynced to the mirror.
- The view report caches each workspace's view by its inputs and reads active groups per drawn key.
- A terminal moved to another pane of its tab stays live; reconcile writes are annotated.
…er-c3-c4-server-frames

# Conflicts:
#	.github/workflows/layout-owner-switch-on.yml
… for workspaces it dropped

A replacement stream holds no workspaces until its first snapshot: hand-back before then, or a
first snapshot that omits an inherited workspace, returns it to the mirror.
@Jinwoo-H
Jinwoo-H merged commit 846efbf into layout-owner-v2 Nov 29, 2026
72 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