Skip to content

Save-divergence detector: skip empty workspaces, see dropped tab-bar entries and kept pane trees (dark, layout-owner build only) - #30125

Merged
Jinwoo-H merged 4 commits into
mainfrom
e2pre/save-divergence-detector-gaps
Oct 17, 2026
Merged

Jinwoo-H merged 4 commits into
mainfrom
e2pre/save-divergence-detector-gaps

Conversation

@Jinwoo-H

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

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​199 $\color{#cf222e}{\Huge{\mathbf{−}}}$​5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​194
Prod 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​205 $\color{#cf222e}{\Huge{\mathbf{−}}}$​33 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​172

ELI5

Orca is moving ownership of the tab and pane layout from the window to the main process. Behind a build switch that is off in shipped builds, a checker watches every window save and reports any layout change main learned only from that save. This PR makes the checker quieter where it was wrong and lets it see two kinds of change it was blind to. It only reports; it never changes, delays, or fails a save.

What Changed

Nothing changes for users: the checker is compiled in only when the layout-owner build switch is on, and shipped builds have it off.

With the switch on, three changes to the checker:

  1. An empty workspace is no longer reported as added or removed. Main's loader makes a workspace for every key a save names, so a save that writes empty lists for a workspace was reported as "workspace added". A workspace now counts as added or removed only if it holds a tab, a group, a group tree, a file, a browser tab, an editor view or a pane record. A stored closed-tab record does not count by itself: the loader places it into whichever workspace a key names. Two things stay reported on purpose:
    • "terminal row owner changed", even for an empty workspace. On relaunch, main skips the first terminal of a workspace whose saved terminal row is empty (the user closed its last terminal), so a save that adds or drops an empty row changes what a relaunch opens.
    • A closed-tab record the save adds or drops, including in a workspace only one copy names. Only a record main already had, newly placed by the loader, is skipped (it is compared against the stored closed-tab records by tab id and worktree id).
  2. A dropped terminal tab-bar entry is reported. If a save removes a terminal tab's tab-bar entry but keeps the tab's terminal row, main's loader rebuilds the entry from the row, so the model showed no change. The checker now compares the stored tab-bar entries before and after the save. A save that carries no tab bar at all for a workspace (a window that has not drawn main's first tab there yet) is not reported.
  3. A pane tree main keeps over the window's is reported. Before the save is written, main replaces the save's pane trees with its own for every tab it has a stored tree for, so a pane change the window made by itself (for example a repair of two panes on one terminal) was invisible. The save entry points now pass the window's pane trees to the checker, which reports every such tab whose tree differs from main's: under the workspace whose tab or terminal row names it, else under "(no workspace)". A save that sends no tree (root: null) for such a tab counts too, since main keeps its tree then as well.

The pane-tree, tab-bar and one-sided closed-tab checks live in a new file, window-save-raw-session-divergence.ts, because they read the stored session rather than main's layout model.

Why

The checker gates the next step of the layout move: it must be quiet across the full end-to-end suite before saves stop carrying layout. The last full sweep had reports that were only empty keys (noise that hides real ones) and two blind spots (a removed tab-bar entry, a pane repair). Alternatives considered:

  • Fixing it in main's loader instead. The loader marks every workspace key with a terminal row list as "owns its terminal rows", while main's own rule marks a workspace only once it has held a terminal. The loader cannot do better from disk: today's window writes an empty row list for every workspace it shows, so "never had a terminal" and "the user closed its last terminal" look the same in the saved file. Changing the loader would also change shipped builds: main loads and re-saves the session in shipped code paths (for example browser tabs on a headless server, agent session tabs, orphan terminal adoption), and the re-save writes an empty row list back only for workspaces the loader marks. So the loader stays as it is, and the checker reports these flips; they go away once window saves stop carrying layout.
  • Diffing pane trees after the save: impossible, main has already dropped the window's trees by then. So the window's trees are passed in from the save entry points, inside the existing switch-on branch.
  • Detecting the dropped tab-bar entry from main's model: impossible, the loader rebuilds it, so the raw stored entries are compared instead.

Linked Issue

N/A (internal layout-owner work).

Visual Proof

N/A: no UI change; the code runs only in layout-owner builds and only writes log lines.

Testing

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below

Failing first. New unit tests in window-save-divergence.test.ts. Against main's checker, 4 fail (empty workspace, closed-tab-only workspace, dropped tab-bar entry, kept pane tree). Against the earlier revisions of this PR, 5 more fail (empty row flip, closed-tab record added under a new key, pane tree of a tab no workspace places, save with no pane tree, closed-tab record moved to another worktree). All pass now.

Gates. pnpm tc pass; pnpm run check:code-quality:changed pass; layout-writer ratchets OK (main 211, renderer 651); focus-read ratchet OK (1095); pnpm run audit:anti-slop pass; vitest src/main/persistence/, src/main/ipc/session*, src/main/ipc/renderer-shutdown*: 1808 passed.

Switch-off bundle (unminified, base vs this branch). Renderer and preload identical apart from the build commit stamp and chunk hash names. Main differs in three lines only: the switch-off saveFromWindow takes one more parameter it does not use, and its two callers pass the save to it. No checker code is in the switch-off bundle.

Checker before/after (switch-on e2e build, same specs, base = this branch's base):

Spec Before After
workspace-layout-oracle (20 tests) 0 0
terminal-duplicate-pty-renderer-reveal 0 2 "pane tree kept over the save's" (new, expected: the window repairs two panes on one terminal; main does not)
wsl-host-fake-transport 3 "workspace added" + row owner 3 row owner only
paired-client-project-removal-stops-host-terminals 1 "workspace added" + row owner 1 row owner only
default-branch-visibility 2 "workspace added" + row owner 2 row owner only
workspace-layout-oracle-latency 1 (a second base run: 2) "workspace added" + row owner at shutdown 4 row owner only (3 also "defaultTabsAppliedByWorkspace changed"); how many stale shutdown saves land varies run to run (an earlier run of this branch: 3)
setup-guide-sidebar 1 workspace added 0 (an earlier run of this branch: 1 workspace added + 1 "pane tree kept", from a test-made tab with non-UUID pane ids written straight into the window store)
agent-send-picker-reveal, floating-mobile-emulator-tab, floating-workspace-pane-height, paired-cmd-j-host-qualified-tabs 9 6 to 9 (tests that write tabs into the window store; the floating shutdown save does not always land)
9 pane and tab specs (split, close, resize, divider, drag, relaunch, restart restore; 23 tests) 0 0

Totals for the final run: 17 reports before, 20 after (an earlier run of this branch: 22). By kind: "workspace added" 13 -> 5, "terminal row owner changed" 11 -> 13, new "pane tree kept" 2, "defaultTabsAppliedByWorkspace changed" 0 -> 3 (timing, see above). No "tab-bar entry removed" report appeared. The row-owner reports on empty workspaces are kept on purpose (see What Changed and Why).

AI Disclosure

Review

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: no platform code. SSH and paired servers: a paired server's partition is still skipped; SSH partitions are checked as before. Performance: switch-off has no checker code; switch-on adds one pass over the stored tab-bar entries and the saved pane trees per save.

After the last fix (closed-tab worktree check), wsl-host-fake-transport, paired-client-project-removal-stops-host-terminals and workspace-layout-oracle were re-run: 4 row-owner reports, the same as the run in the table.

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)

…entries and kept pane trees (dark, layout-owner build only)

- A workspace key that names nothing (or only places a stored closed-tab record) is no longer
  reported as "workspace added/removed" or "terminal row owner changed".
- A save that drops a terminal tab's tab-bar entry while keeping its row is reported, read from
  the stored session before the Loader rebuilds the entry.
- A pane tree main keeps over the window's (windowSaveForMain) is reported, so a window-side
  pane repair shows up.
@coderabbitai

coderabbitai Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: e365d48c-5f4d-4cfb-bd54-55c6656f1444
📥 Commits

Reviewing files that changed from the base of the PR and between f3c4050 and ce2e536.

📒 Files selected for processing: 2
  • src/main/persistence/window-save-divergence.test.ts
  • src/main/persistence/window-save-raw-session-divergence.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.

📝 Walkthrough

The save watcher now combines layout-model differences with findings from the saved session, including dropped terminal tab-bar entries and differing pane trees. Session and shutdown-checkpoint save paths pass terminal layout data to the watcher. Tests cover workspace and closed-tab differences, tab-bar entries, and pane-tree comparisons.

Priority: ⬇️ Low

Merge Risk: 🔵 Low · up to ce2e5

A layout-owner build can miss a closed-tab divergence report when the same save adds or removes workspace content. The checker does not alter saves, so saved data is unaffected, but this diagnostic gap remains.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 62.50% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 16 functions across 5 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 accurately identifies the main checker changes, including empty-workspace handling, dropped tab-bar entries, and preserved pane trees. It is specific but longer than necessary.
Description check Passed The description follows the required template and clearly explains the change, rationale, testing, scope, compatibility considerations, and checklist status. The N/A linked issue is justified as inter…
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 follows the required template and clearly explains the change, rationale, testing, scope, compatibility considerations, and checklist status. The N/A linked issue is justified as internal layout-owner work, and the empty AI Disclosure section is permitted for internal contributors.

  • 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: 7fd0f326-3904-4d43-978b-8920889cb675
📥 Commits

Reviewing files that changed from the base of the PR and between 09f12fa and 11f7305.

📒 Files selected for processing: 5
  • src/main/ipc/renderer-shutdown-checkpoint.ts
  • src/main/ipc/session.ts
  • src/main/persistence/window-save-divergence.test.ts
  • src/main/persistence/window-save-divergence.ts
  • src/main/persistence/window-save-raw-session-divergence.ts

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

… tree and one-sided closed tabs (dark, layout-owner build only)

@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

Caution

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

⚠️ Outside diff range comments (1)

🟡 Minor · Report closed-tab changes during a workspace content… · window-save-divergence.ts:164-169

src/main/persistence/window-save-divergence.ts:164-169
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Report closed-tab changes during a workspace content transition.

If a workspace loses its last tab and gains a closed-tab record in the same save, this early return reports only workspace removed. closedTabsOfOneSidedWorkspaces does not recover the closed-tab finding because both models still contain the workspace key. Include diffClosedTabs(before, after) when both layouts exist, even if only one has content.


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: f5ad042c-f027-4cfb-9702-b79caa7012db
📥 Commits

Reviewing files that changed from the base of the PR and between 11f7305 and 11584f8.

📒 Files selected for processing: 3
  • src/main/persistence/window-save-divergence.test.ts
  • src/main/persistence/window-save-divergence.ts
  • src/main/persistence/window-save-raw-session-divergence.ts

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

@Jinwoo-H
Jinwoo-H merged commit 45f7429 into main Oct 17, 2026
60 of 62 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