Skip to content

feat(space): add a prune action for stale worktree registrations - #8910

Draft
brennanb2025 wants to merge 3 commits into
mainfrom
feat/space-prune-stale-registrations
Draft

brennanb2025 wants to merge 3 commits into
mainfrom
feat/space-prune-stale-registrations

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Jul 15, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Follow-up to #8409. That PR stopped surfacing prunable worktree registrations (git registry entry whose directory was deleted without git worktree prune) as live workspaces — including in the Space page, which no longer renders them as dead "Missing" rows. But those registrations still pin their branches as checked out, and there was no in-app way to clean them up.

This adds that affordance. It was flagged on #8409 by a reviewer who hit it on macOS: a reboot cleared 16 worktree directories under /private/tmp while their registrations remained, blocking 15 branches, with git worktree prune in a terminal the only remedy.

With this change, the Space scan counts prunable registrations (instead of only dropping them) and shows a small notice when any exist:

⚠ 3 stale worktree registrations from deleted directories. [ Prune ]

Prune runs git's own git worktree prune for each affected repo. Git only drops registrations whose directory is gone and preserves locked ones (Orca locks worktrees for active agent sessions), so nothing live is touched; branches and their commits are untouched by design.

Screenshots

The new UI is a single notice on the Space page when prunable registrations exist, with a Prune button:

Space stale-registrations notice with Prune button

Full page — notice in context (2 stale registrations here; rows still show only the live worktrees):

Space page with the stale-registrations notice

After clicking Prune — the notice is gone, git's registry is reconciled, and the pruned branches survive:

Space page after pruning

Captured from a Playwright + Electron run on this branch (rebased onto main after #8409 merged).

Implementation

  • Scan: staleRegistrationCount added to WorkspaceSpaceRepoSummary / WorkspaceSpaceAnalysis; the existing prunable filter now counts what it omits.
  • Git op: pruneWorktrees() (local + WSL, read-cache invalidation) and a dedicated relay git.pruneWorktrees op for SSH. The generic git.exec relay channel is deliberately read-only, so remote prune needs its own op. An older deployed relay that predates it rejects with "Method not found" → the IPC surfaces a clear "reconnect to update, or run git worktree prune there" message instead of a protocol error.
  • IPC worktrees:pruneStaleRegistrations prunes every store repo matching the id (multi-host-safe), then notifies worktree-change; the store action refreshes the scan. Web/paired clients get an explicit unsupported-here error, matching the existing forgetLocal pattern.
  • UI: a notice + Prune button styled like the panel's sibling notices, with busy state and success/error toasts.

Testing

  • pnpm typecheck
  • pnpm lint
  • pnpm test for the touched areas (space analysis, git worktree paths, worktree IPC, store slice, web preload)
  • Validated end-to-end in Electron

New coverage:

  • Real-git integration: prune removes a stale registration, keeps its branch, and leaves a locked+missing registration intact (worktree-list-paths.test.ts).
  • IPC routing: local repo → pruneWorktrees; SSH repo → provider; old relay ("Method not found") → clear error (worktrees.test.ts).
  • Scan counts prunable registrations (workspace-space-analysis.test.ts).

Electron validation: fixture repo with a live worktree + stale registrations; the banner showed the count, a real click on Prune cleared it, git's registry went from N+live to just main + live, and every stale-* branch survived. Local review screenshots (uncommitted) are under validation-screenshots/.

Prunable registrations are omitted from Space rows (#8409), but they
still pin their branches as checked out with no in-app remedy — a macOS
reboot that clears /private/tmp can leave a whole batch behind. Count
them during the Space scan and surface a notice with a Prune button
that runs git's own `worktree prune` per affected repo (locked
registrations survive; branches and commits are untouched).

The relay gains a dedicated git.pruneWorktrees op since generic
git.exec is deliberately read-only; an older deployed relay without it
gets a clear error instead of a protocol failure.
@coderabbitai

coderabbitai Bot commented Jul 15, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 752b2c23-51d7-4e86-ac50-dc345f3e33fe

📥 Commits

Reviewing files that changed from the base of the PR and between fe4bc46 and b933fb2.

📒 Files selected for processing (4)
  • src/main/ipc/worktrees.test.ts
  • src/main/ipc/worktrees.ts
  • src/main/providers/ssh-git-provider.test.ts
  • src/main/providers/ssh-git-provider.ts
🚧 Files skipped from review as they are similar to previous changes (3)
  • src/main/providers/ssh-git-provider.ts
  • src/main/ipc/worktrees.ts
  • src/main/ipc/worktrees.test.ts

📝 Walkthrough

Walkthrough

Adds stale worktree registration counts to workspace-space analysis and implements pruning through local Git execution, SSH relay RPCs, desktop IPC, and preload APIs. The workspace-space slice and panel now invoke pruning, display progress and results, and refresh analysis. Web clients report the operation as unavailable. Tests cover Git pruning behavior, IPC routing and errors, analysis counts, and updated data fixtures.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: adding a prune action for stale worktree registrations.
Description check ✅ Passed The description is detailed and covers summary, screenshots, implementation, and testing, but it omits the template's AI Review Report, Security Audit, and Notes sections.
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.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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: Pro

Run ID: 05a7b96d-edee-4286-884c-bbb7a90af47d

📥 Commits

Reviewing files that changed from the base of the PR and between 6e2a4a8 and 14494b4.

📒 Files selected for processing (21)
  • src/main/git/worktree-list-paths.test.ts
  • src/main/git/worktree.ts
  • src/main/ipc/workspace-space.test.ts
  • src/main/ipc/worktrees.test.ts
  • src/main/ipc/worktrees.ts
  • src/main/providers/ssh-git-provider.ts
  • src/main/workspace-space-analysis.test.ts
  • src/main/workspace-space-analysis.ts
  • src/preload/api-types.ts
  • src/preload/index.ts
  • src/relay/git-handler.ts
  • src/renderer/src/components/status-bar/WorkspaceSpaceManagerPanel.tsx
  • src/renderer/src/i18n/locales/en.json
  • src/renderer/src/i18n/locales/es.json
  • src/renderer/src/i18n/locales/ja.json
  • src/renderer/src/i18n/locales/ko.json
  • src/renderer/src/i18n/locales/zh.json
  • src/renderer/src/store/slices/workspace-space.test.ts
  • src/renderer/src/store/slices/workspace-space.ts
  • src/renderer/src/web/web-preload-api.ts
  • src/shared/workspace-space-types.ts

Comment thread src/main/providers/ssh-git-provider.ts Resolved
@Smurries

Smurries commented Aug 7, 2026

Copy link
Copy Markdown

This is the fix for #10951, and the multi-host shape of git.pruneWorktrees looks right. One question about coverage:

The relay op is described as handling local, WSL and SSH hosts. Does it also route for Remote Orca Server runtime environments? That's a different transport (paired websocket relay, not an SSH target), and it's the case where the client has no local git at all to prune against — a monitor-only client paired to several servers holds zero owned repos/projects/worktreeMeta, so every worktree row it shows belongs to a remote. If Remote Orca Server hosts don't route through this op, the configuration that needs the Prune button most is the one that won't get it.

Related: does the prune also drop the matching workspaceSessionsByHostId records? Clearing the sidebar row while the persisted per-worktree session survives leaves the resurrection surface in #12920 / #12447 in place, and adds to the blast radius in #12918. On one client here that's 79 orphan session records across three paired servers, one of which has never dropped a single record in three days.

Detail and evidence in #10951. Happy to test a build against a 3-server fleet (Linux servers, Windows client, Tailscale) if that's useful.

@OrcaWin
OrcaWin marked this pull request as draft October 27, 2026 09:47
@OrcaWin

OrcaWin commented Oct 27, 2026

Copy link
Copy Markdown
Collaborator

Moving this PR to draft because it has been untouched for more than 80 days (latest recorded PR activity or commit timestamp: 2026-08-07T07:50:54Z; checked on 2026-10-27). This keeps the review queue focused on active work while preserving the proposal. Please mark it ready for review when work resumes.

This branch has not been deployed

No deployments
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.

4 participants