Skip to content

Main drops the layout of workspaces the catalog no longer validates (dark, layout-owner build only) - #30177

Merged
Jinwoo-H merged 3 commits into
mainfrom
e2-6/p10-degraded-repo-purge-in-main
Oct 18, 2026
Merged

Jinwoo-H merged 3 commits into
mainfrom
e2-6/p10-degraded-repo-purge-in-main

Conversation

@Jinwoo-H

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

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​242 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​242
Prod 10 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​148 $\color{#cf222e}{\Huge{\mathbf{−}}}$​9 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​139

ELI5

When a workspace's worktree is gone (deleted outside Orca) or its project is no longer registered, the window already throws away that workspace's saved tabs when it loads. In the build where the main process owns the layout, main kept those tabs, so a stale workspace could come back through main's layout updates. Now main throws them away by the same rule the window uses. Shipped builds are unchanged.

What Changed

Before (layout-owner build only): the window dropped tabs of an invalid workspace when it loaded the saved session, but main's stored layout still held them. Once window saves stop carrying layout, nothing would ever remove them from main.

After (layout-owner build only): main removes the stored layout of a workspace the catalog no longer validates, at two points:

  • At load, right after the existing sweep of rows owned by unregistered projects. With no worktree listing yet, the only invalid workspaces are ones that name no registered project.
  • After each worktree listing main serves for a project. A complete scan that no longer finds a worktree drops that worktree's layout. The window loads its session only after this listing, so both sides end up with the same set.

Mechanism:

  • The validity rule moved, unchanged, from the window into a shared file (src/shared/worktree/degraded-repo-worktree-validity.ts). The window's four load paths import it from there; main calls the same function. There is one copy of the rule.
  • Main removes workspaces through the existing removeWorkspaceSessionStateForWorktree, which writes the partition and notifies the layout stream, so the window receives a removed frame for each dropped workspace.
  • What always stays, matching the window: the floating workspace, every folder workspace key, a registered project whose listing failed or could not prove deletion (a disconnected SSH project lists from saved metadata, which is never a complete scan), and every workspace a paired host owns (its catalog lives on that host).
  • Extra guards on the listing path: a listing older than a create or remove that landed after its scan began is ignored; a project id registered on two hosts is skipped (one host's scan cannot speak for the other's worktrees); worktrees hidden from the sidebar still count as present, so hiding a worktree never closes its tabs.

The window's own load filter stays in place.

Why

Main is becoming the single owner of layout. A rule that exists only in the window stops working once window saves no longer carry layout, so main has to apply it itself. Sharing the one function, rather than writing a main-side copy, keeps the two from drifting. Running the purge on main's own listings (instead of waiting for the window to report what it dropped) needs no new message between window and main, and main already knows whether each scan was complete.

Alternatives considered: a new layout command to remove a workspace (larger, and a wire change older peers would drop); matching the window's hidden-worktree handling exactly (it would close a worktree's tabs as soon as it was hidden mid-session).

Linked Issue

Internal layout-owner work (prep for the step that stops window saves from carrying layout).

Visual Proof

N/A: the change is compiled out of shipped builds, and in the layout-owner build it only removes tabs of workspaces that no longer exist.

Testing

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

New src/main/persistence-invalid-workspace-layout-purge.test.ts (switch on):

  • At load: a deregistered project's workspace is gone; a key naming no registered project is gone; a registered project with no listing, a disconnected SSH project, a folder workspace and the floating workspace are kept; a paired host's workspaces are kept.
  • After a listing: a worktree a complete scan no longer finds is dropped and the layout stream sends removed for it; a scan that cannot prove deletion, a stale listing, and a project id two hosts register all keep everything.
  • Pending (skipped until window saves stop carrying layout): a later window save naming a dropped workspace does not bring it back.

Failing first, before the change: without the module the test file cannot load; with the module but before wiring it into load, the "key naming no registered project" case fails. The deregistered-project case already passes before this change because of the existing load sweep.

Gates: pnpm tc pass; pnpm run check:code-quality:changed pass; layout-writer ratchet pass (main 212, renderer 651); focus-read ratchet pass (1082); anti-slop lint pass; vitest (--maxWorkers=4) 122 files, 1070 passed, 1 skipped across the new test, the deregistered-residue test, the window hydration tests, src/main/ipc/worktrees, src/main/persistence/loading-store, src/main/persistence/restoring-sessions, the layout stream, tabs and terminal store tests.

Switch-off bundle (unminified, base af056df vs head): main bundle identical except the commit stamp; preload identical; renderer identical except one source-region comment in one chunk that names the moved file's new path. Chunk hashes differ only because of that comment.

Layout-owner build, save-divergence detector, same specs on base and head (golden-quit-relaunch-session, worktree-lifecycle, golden-worktree-create-switch, local-worktree-visibility-runtime-active, worktree-delete-shortcut, folder-setup): base 9 passed, 0 reports; head 9 passed, 0 reports. Positive control (cli-file-open-position) 1 report on both builds, so the detector was live.

Platforms: macOS. SSH: covered by the unit cases above (disconnected SSH project kept; SSH listings in main are never complete scans).

Review

Layout-writer baseline: this adds one main writer (invalid-workspace-layout-purge.ts, 1 call of removeWorkspaceSessionStateForWorktree). Removing invalid workspaces in main needs a session write; the alternative was a new layout command.

Flip capability list: none. No new layout command or field.

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: keys are compared as stored, no path handling added. SSH: loss of contact never drops a layout. Mobile: unchanged. Backwards compatibility: no wire change. Performance: one pass over a partition's workspace keys per listing, only in the layout-owner build.

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)

@coderabbitai

coderabbitai Bot commented Oct 18, 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: 3d995d5b-ac9a-4cb6-aef9-eccbaa9c71b3
📥 Commits

Reviewing files that changed from the base of the PR and between 6c45958 and 815e55f.

📒 Files selected for processing: 11
  • config/main-layout-writer-baseline.txt
  • src/main/ipc/worktrees/listing/host-qualified-worktree-listing.ts
  • src/main/ipc/worktrees/listing/register-detected-worktree-handlers.ts
  • src/main/persistence-invalid-workspace-layout-purge.test.ts
  • src/main/persistence/loading-store/store.ts
  • src/main/persistence/restoring-sessions/invalid-workspace-layout-purge.ts
  • src/renderer/src/store/slices/browser/browser-hydration-actions.ts
  • src/renderer/src/store/slices/editor/actions/hydrate-editor-session.ts
  • src/renderer/src/store/slices/tabs/tabs-session-actions.ts
  • src/renderer/src/store/terminals/workspace-terminal-hydration.ts
  • src/shared/worktree/degraded-repo-worktree-validity.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 change adds workspace-layout purging during store loading and after worktree listings. The load-time purge checks workspace keys against registered repositories and preserves specified workspace categories. The listing-triggered purge checks a repository only when the result is present, non-aborted, current, and uniquely registered on one host. Main-process store and listing paths invoke the purges. Hydration imports now use the shared worktree validity module.

Priority: ➖ Normal

Merge Risk: ⚪ Minimal · up to 815e5

The change purges persisted layouts for workspaces that are no longer valid, and only in the layout-owner build. The supplied evidence shows safeguards for ambiguous or stale cases, and no merge-blocking risk was identified.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 9 functions across 10 files. (1 skipped: … 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 and concisely describes the main change: main removes workspace layouts that the catalog no longer validates in the layout-owner build.
Description check Passed The description is complete and focused. It explains the user impact, implementation, rationale, alternatives, testing, compatibility considerations, and checklist status. The Linked Issue section nam…
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 is complete and focused. It explains the user impact, implementation, rationale, alternatives, testing, compatibility considerations, and checklist status. The Linked Issue section names internal work but does not provide an issue reference; this is acceptable for the stated maintainer-style exception.

Full details: Docstring Coverage

Explanation

Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 9 functions across 10 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.

@Jinwoo-H
Jinwoo-H merged commit b8264e8 into main Oct 18, 2026
46 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