Skip to content

Layout-owner builds: a phone's tab move is always the server's own; no ghost editor tabs after restart - #31925

Merged
Jinwoo-H merged 19 commits into
mainfrom
w9-l280-moves-main-only
Oct 22, 2026
Merged

Jinwoo-H merged 19 commits into
mainfrom
w9-l280-moves-main-only

Conversation

@Jinwoo-H

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

Copy link
Copy Markdown
Contributor

ELI5

In the new layout mode (still switched off for everyone), the server now owns every tab a phone or a paired desktop can see. So when a phone drags a tab, the server moves it itself instead of falling back to the old desktop-window path. Four small gaps that kept that fallback alive are closed.

What Changed

Dark change: switched-on (layout-owner) builds only. One shared rule moves from the window into a shared file and behaves the same; the switched-off build is otherwise unchanged.

  • Moves never fall back to the window (ledger L280). main-layout-session-tab-move.ts loses the bridge that sent a client's move to the window when a group showed a row the server couldn't resolve. translateSessionTabMove now maps a "move to index N" past such a row, and a reorder must still name each shown row once; today's refusal codes (tab_not_found, invalid_tab_order, target_group_not_found) are unchanged.
  • Editor rows only under their tab id. The window no longer publishes a row for an open file that no tab group shows (mobile-session-snapshots.ts), the one row id the server could not map.
  • Browser startup repair moves into the server's load. A saved browser record with no tab used to get one from the window at startup, under an id the server never saw. The server's layout load now gives it the tab (end of the active group, as the window placed it, a deterministic id), and the window skips its own repair wherever the server owns the workspace — the same owner test sendLayoutApply uses (runtimeEnvironmentIdUnlessTwin, src/renderer/src/lib/resolve-owner.ts:214, layout-apply-send.ts:240). A directly dialed SSH workspace is the server's too (its layout loads under its ssh: host); a paired server's workspaces, SSH ones included, keep the window's repair. Two guarantees for direct SSH workspaces:
    • A host that can't be reached changes nothing. The repair and the L286 drop read only the saved partition. loadWorkspaceLayout(hostId, session, context) (src/shared/workspace-layout/workspace-layout-load.ts:138) takes no connection input and never contacts the host. So a direct SSH workspace whose host is down still gets the same deterministic repair, and loses only what the window's own rule drops. Test: workspace-layout-load-browser-repair.test.ts, "repairs and drops the same in a direct SSH partition, whose host it never contacts".
    • The skip only applies with the switch on. The window skips its repair only under ORCA_LAYOUT_OWNER_IS_MAIN (src/renderer/src/store/slices/browser/browser-hydration-actions.ts:65). With the switch off, a direct SSH workspace keeps today's window repair. The "directly dialed SSH" case in store-session-browser-hydration.test.ts expects the repaired tab with the switch off, and the comparison runs it in both modes.
      Not done through openBrowserTab: that command cannot attach a tab to an existing record (it appends a second record and mints a page). The repair is made on every load with the same id, so it is idempotent. It is not guaranteed to reach the saved file: a server command rewrites only the records it changed, while a whole save writes it. A switched-off build reading either form ends with exactly one tab (tests for both).
  • L286: no ghost editor tabs after a restart. Diff, conflict-review and check-details tabs keep their document in memory only. The window's restore drops them (and old html-preview tabs) unless their file was saved or their view is still held (tabs-hydration.ts); the server's load kept them, so its groups counted tabs nobody could see. Both now use one rule, src/shared/workspace-layout/saved-editor-tab-restore.ts. The server applies it only in loads that carry its in-memory views (the layout it publishes and every client or window command), where it matches what the window draws from the server's frames. The server's own edits (a phone's browser tab, an agent tab) load without views, so they keep every saved tab and never drop a live diff. The saved file may keep the dropped entry until a whole save rewrites it; a switched-off build restores the same tabs from either form, since its own restore drops them too.
  • L287: conflict-review and check-details rows for older clients. The window lists them as plain file rows; the server listed none, so older phones and paired desktops would lose them once the window's rows go. The server now lists the same rows (reviewTabRow).
  • Two switched-on tests keyed editor drafts by path while drafts are keyed by editorFileKey (an owned id in a layout-owner build); they failed on main too and now use it.

Why

Each gap is closed where it starts, so the server's layout is the one source for every tab a group shows and the fallback has nothing left to cover. Re-reading the window's list for those rows would have kept two sources.

Linked Issue

Internal (layout-owner refactor ledger rows L280, L286, L287).

Visual Proof

N/A: switched-off builds are unchanged; the switched-on changes are in the server's move and row handling, covered by the tests below.

Testing

Fail-first, red at base, green at head (switched on; the mocked-switch files also off):

  • main-layout-session-tab-move.test.ts: a move in a group showing a row the server holds no tab for is the server's own (window not asked); an order that doesn't name exactly the rows shown is refused.
  • workspace-layout-load-view-less-tabs.test.ts: a load with the server's views drops what the window drops, keeps a diff of a saved file and a tab whose view is held, and a dropped tab never counts in a client's move index; a load without views keeps every saved tab.
  • workspace-layout-projection.test.ts: the published layout loads with views even before any view is held (fails before the fix).
  • workspace-layout-load-browser-repair.test.ts: the repaired tab, its group (including a saved active group the load empties), a stable id across loads and restarts.
  • session-tab-rows-main-window-parity.test.ts: server and window rows are equal with conflict-review and check-details tabs added.
  • sync-runtime-graph-editor-diff-tabs.test.ts, store-session-browser-hydration.test.ts (local and directly dialed SSH workspace: no window repair; a paired server's workspace and its SSH workspace: window repair kept), tabs-hydration-main-load-drop.test.ts (a switched-off build reads the rewritten session the same).

Server specs (switched on, fresh build at each exact commit; base = main 01db1b8, head c1765f1 (pass at 5649cbe too); the last commit adds a test only):

Spec Base Head
paired-mobile-desktop-tab-composition pass pass
paired-desktop-server-layout-frames pass pass
headless-serve-focused-terminal-create pass pass
live-background-terminal-mount-authority pass pass

Per-test comparison over src/main/runtime src/main/persistence src/shared/workspace-layout src/renderer/src/runtime src/renderer/src/store, base main 01db1b8, head c1765f1 (the last commit adds a test only):

  • Switched on: 24745 base / 24762 head tests; 26 base failures, 25 head. One head-only failure, profile-state-backup-worker.test.ts, is a timing flake: it fails 2 of 3 runs alone at base too, in a file this PR does not touch. Two fixed since base: the converted stale draft-key fixtures.

  • Switched off: 24745 base / 24763 head tests; 2 base failures, 3 head. The one head-only failure is the same backup-worker flake.

  • 4 tests absent at head in both modes, all renamed by this PR: three parity tests whose describe now reads "main's diff, markdown-preview and review rows", and the old window-fallback move test, converted to "moves in a group showing a row main holds no tab for, without asking the window".

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

Review

Three Opus passes on the code. Pass 1: approve with nits (fixed: view check keyed by file like the window; comment example; rebutted: review rows are never dirty since a review tab holds no draft, and the repaired browser tab is not activated, a view choice left to the window). Pass 2 found the repaired browser tab could land in a saved active group the load had just emptied; fixed with the same group-owner map the group order uses, plus a test. Pass 3 on the final code: approve, no findings above nit. The full per-test comparison then caught a regression none of the reviews did: the server's own edits loaded without its views and would have deleted a live diff tab (editor-renames-across-partitions.test.ts went red). Fixed by dropping only in loads that carry the views; delta review: approve, and it traced that every publish and command path carries them and that a window-opened diff's view is stored before any load can see the tab. A commit adding SSH cases to a test had its own delta review: approve (traced: a directly dialed SSH workspace resolves to this app, a server's SSH workspace to that server).

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

Security: none. Cross-platform: none. SSH/remote: directly dialed SSH workspaces get the server's repair like local ones; a paired server's workspaces (SSH included) keep the window's; rows older peers see keep today's shape and ids, and gain the review rows the window already sent. Mobile: no wire change. Performance: one pass over the saved tabs at load.

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)

…its own hook status

With the layout-owner switch on, main gives agent tabs their generated titles from
the hook-server status it owns, on the desktop, headless serve and orcad: one
renameTabs per status batch, so one write and one frame. It keeps the window's
rules (setting, custom and quick-command titles, first title wins, dispatch labels).
The window stops sending generated titles for tabs main holds; a paired server's
tab, or one main has no tab-bar entry for, is still titled by the window as today.

The title rules move to src/shared (agent-row-primary-text, and the new
agent-generated-tab-title-rules) so both sides share them; switch-off behaviour
is unchanged.
…lf, and a tab move names the tab it follows so a stale index can't misplace it (layout-owner build, L193)
…ow's way, a twin's agent tab keeps its window title, and orcad subscribes titles through the store attach (layout-owner build)
…e never falls back to the window (layout-owner build)

- Main moves a client's tab itself in a workspace it owns; a row it holds no tab for (a combined
  diff) keeps no place, and an order must still name each row shown once (L280).
- The window publishes an editor row under its tab id only; a file no group shows gets none.
- Main's layout load gives a saved browser record with no tab its tab, as the window's hydration
  repair did, and the window no longer mints one for a workspace main owns.
- Main's layout load drops the saved tabs the window's restore drops (view-less diff, conflict and
  check tabs, old html previews), through one shared rule; the next save writes it back (L286).
- Main lists conflict-review and check-details tabs as the plain file rows the window lists, so
  older clients keep them once the window's rows are gone (L287).
…owner build)

- A transient tab stays at load while a view is held for its file, as the window's frame build
  keeps it, not only for its own tab id.
- The repaired browser tab goes to the saved active group only while it holds a tab, as
  selectHydratedActiveGroupId picks it; tests that the id is stable across loads and restarts,
  that a window-owned build restores it once, and that a paired server's record keeps the window's
  repair.
- Two switch-on tests keyed editor drafts by path; drafts are keyed by editorFileKey (an owned id
  in a layout-owner build), so they now use it.
…'s views, so main's own edits keep a live diff
@coderabbitai

coderabbitai Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

📝 Walkthrough

The change updates main-owned workspace layout loading and tab hydration. Saved content tabs are filtered using saved edit-file paths and editor-view availability, and missing browser tabs are created during layout loading. The old-client projection now includes eligible conflict-review and check-details rows. Move translation uses the client-visible order and validates reorder requests. Renderer fallback behavior also varies by layout owner and workspace type.

Priority: ➖ Normal

Merge Risk: 🔵 Low · up to 075e5

Feature builds can lose saved editor tabs after restart when no editor views are held; fix the load-context guard before enabling this layout-owner path.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 54.55% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 22 functions across 21 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly summarizes the two main changes: server-owned tab moves and removal of ghost editor tabs after restart.
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.
Description check Passed The pull request description is complete and follows the repository template. It explains the user impact, implementation, rationale, testing, review, compatibility considerations, and checklist statu…
Full details: Description check

Explanation

The pull request description is complete and follows the repository template. It explains the user impact, implementation, rationale, testing, review, compatibility considerations, and checklist status. Visual proof is correctly marked N/A with a reason, and the internal ledger reference is appropriate for the stated internal change.

✨ 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.

Caution

Some comments are outside the diff and can’t be posted inline due to GitHub limitations.

⚠️ Outside diff range comments (1)

🟡 Minor · Do not advertise editor views when the partition has none. · workspace-layout-projection.ts:44-51

src/main/runtime/workspace-layout-projection.ts:44-51
🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win

Do not advertise editor views when the partition has none.

getLayoutEditorViews(hostId) can return undefined after restart. This branch still supplies editorViewsOf, so the loader treats the partition as views-aware and can drop saved transient tabs with no held view. A later full save removes those tabs from the session.

Restore the base guard:

Suggested fix
-    ...(store.getLayoutEditorViews ? { editorViewsOf: (key: string) => views?.[key] } : {})
+    ...(views ? { editorViewsOf: (key: string) => views[key] } : {})

ℹ️ Review info
⚙️ Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: ffe7011b-dc33-426f-93da-50cd04083cab
📥 Commits

Reviewing files that changed from the base of the PR and between c1765f1 and 075e52c.

📒 Files selected for processing: 1
  • src/shared/workspace-layout/workspace-layout-load-browser-repair.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review.

@Jinwoo-H
Jinwoo-H merged commit ea60ec5 into main Oct 22, 2026
49 of 50 checks passed
Jinwoo-H added a commit that referenced this pull request Oct 22, 2026
…and create anchor use, after #31925 dropped its import (layout-owner build, L288, L289)

#31925 removed the L280 bridge in main's tab move, and with it the move's last use of
resolveSessionTabRow, so it dropped the import; this branch's split selection and create-anchor
lookup still resolve a row to main's tab through it. A row main's layout does not hold is now
refused by main's move (tab_not_found) as #31925 rules; the phone test asserts that.
Jinwoo-H added a commit that referenced this pull request Oct 22, 2026
…ost does and uses a store that announces its writes (layout-owner build)

Since #31925, main moves every tab of a workspace it owns and refuses a row its layout does not
hold, and since D3b a chat the host opens is saved in main's layout. The test now opens the chat
through the host's publish path and gives the runtime a profile-like store (partitions listed,
writes announced), so the reorder reaches main's layout and its commit reaches the rows.
Jinwoo-H added a commit that referenced this pull request Oct 22, 2026
…holds chats and moves every row now (L283)

Since D3b a chat the host opens is saved in main's layout, and since #31925 a phone cannot move a
row main does not hold, so the rebuilt-group stray this placed no longer reaches a phone; the
remaining strays are brief, and appending them gives the same order. withStrayIn and its callers
return to main's behaviour, with its unit test. The phone-order spec stays as a guard that a
windowless chat moved first stays first after a rebuild.
Jinwoo-H added a commit that referenced this pull request Oct 22, 2026
…lects the moved tab as the window does (dark, layout-owner build only) (#31924)

* fix(session-tabs): a tab main's groups lack keeps the place its writer listed it, so a headless phone lists a chat first (layout-owner build, L283)

On a host with no window, a rebuild writes its rows under a group id main's layout lacks. The row
writer's reorder treated every row of that group main does not hold (a chat, a browser page) as a
stray and appended it to the active group, so a chat the user moved first came back last, in both
the groups and the tab list. Strays now go after the id they follow in the writer's order (else
first), the same rule a group main does hold already used; the window publication path shares it.

* fix(session-tabs): a phone's split move and its create after a split tab go through main's layout on a windowless host (layout-owner build, L288, L289)

On a host with no window, a phone's split move only rewrote the runtime's own rows, and its new
terminal anchored after a split tab reached main's layout with no anchor. Every write of the rows
takes main's groups and order, so the split collapsed back into one group and the new tab landed
after the trailing tab. The split is now main's splitGroup command (the moved tab selected in its
new group, as a desktop drop), and the create passes the anchor's tab to main's createTerminalTab,
as a window's create does. An older phone sends no anchor and still gets the end.

* test(session-tabs): type the split move's async reply in the dispatch stub, and read an optional group map (L289)

* fix(session-tabs): a phone's split goes to main's layout only for a tab main holds, as the window sends it (layout-owner build, L289 review)

With the Store's write notices, today's runtime-only split already reached main's groups through
the session write; what it lost on a windowless host was the selection: the moved tab and its new
group did not become the active ones, as they do after a window's drop. The split stays main's
splitGroup for a tab main's groups hold, with the window's checks: a drop main's groups make a
no-op sends nothing (the window's pane-column rule, now in shared), and a refusal is dropped
silently. A row main does not hold (a chat or browser tab) splits as today, with no error. The
create anchor and its layout-owner hand-off move to their own module. The surface test fixture's
session writes now notify listeners, as the Store's do.

* chore(session-tabs): log when main refuses a phone's split, as the window logs its own refusals

* fix(session-tabs): a phone's terminal created after a chat or browser tab main holds lands after it, in its group (layout-owner build, L288 follow-up)

Since browser and chat tabs went main-first, main's layout holds them, but a windowless create
handed main the row id (agent-session:<id>), which is not main's tab id, so main put the new tab
at the end of its first group. The anchor is now resolved to main's own tab, as a window's create
names it; main's read of a workspace's layout is one method the tab-move path shares.

* fix(session-tabs): one move path: main's tab move selects a split tab in its new group and skips the window's no-op split (layout-owner build, L289)

A phone's split now goes only through main's tab move (#31812); this branch's own split routing is
gone. For a split only, main's tab move now does what the window's drop does: it sends nothing for
a drop that changes nothing (the window's pane-column check, reused), and after main applies the
split it selects the moved tab and makes its new group active. Refusals keep that path's codes.

* fix(session-tabs): resolve a create's anchor to main's tab inside the tab-move module, so only the old-client boundary's listed importers read old-client rows (L288 follow-up)

* perf(session-tabs): read main's layout for a create's anchor only when main places it, so switch-off and appending phones skip that load

* fix(session-tabs): restore the row-to-tab lookup the split selection and create anchor use, after #31925 dropped its import (layout-owner build, L288, L289)

#31925 removed the L280 bridge in main's tab move, and with it the move's last use of
resolveSessionTabRow, so it dropped the import; this branch's split selection and create-anchor
lookup still resolve a row to main's tab through it. A row main's layout does not hold is now
refused by main's move (tab_not_found) as #31925 rules; the phone test asserts that.

* test(session-tabs): the L283 phone-order test opens its chat as the host does and uses a store that announces its writes (layout-owner build)

Since #31925, main moves every tab of a workspace it owns and refuses a row its layout does not
hold, and since D3b a chat the host opens is saved in main's layout. The test now opens the chat
through the host's publish path and gives the runtime a profile-like store (partitions listed,
writes announced), so the reorder reaches main's layout and its commit reaches the rows.

* test(session-tabs): type the L283 test's profile-like store as the Store contract declares it

* revert(session-tabs): drop the stray-placement change; main's layout holds chats and moves every row now (L283)

Since D3b a chat the host opens is saved in main's layout, and since #31925 a phone cannot move a
row main does not hold, so the rebuilt-group stray this placed no longer reaches a phone; the
remaining strays are brief, and appending them gives the same order. withStrayIn and its callers
return to main's behaviour, with its unit test. The phone-order spec stays as a guard that a
windowless chat moved first stays first after a rebuild.
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