Skip to content

fix: allow retrying partial worktree removal - #3315

Open
akbash-bot wants to merge 1 commit into
herdrdev:masterfrom
akbash-bot:akbash/3314-retry-worktree-removal
Open

fix: allow retrying partial worktree removal#3315
akbash-bot wants to merge 1 commit into
herdrdev:masterfrom
akbash-bot:akbash/3314-retry-worktree-removal

Conversation

@akbash-bot

@akbash-bot akbash-bot commented Aug 27, 2026

Copy link
Copy Markdown
Collaborator

Issue

A blocked worktree removal can unregister the checkout in Git while leaving its directory behind. Retrying from Herdr then stays on a fatal error instead of allowing cleanup.

Problem

Git reports that the leftover path is no longer a working tree. The removal dialog treated that response as terminal, so it could not reach Herdr's guarded forced cleanup.

How did we fix it?

Herdr now asks for explicit force confirmation when this retry state occurs. The API still returns worktree_remove_failed with Git's original message. The confirmed retry continues to use the existing checks that reject registered or unrelated directories.

Verification

The new deferred-removal regression failed before the change and passes afterward. All 21 targeted worktree-removal tests pass. Formatting and Clippy pass, and 3,534 of 3,535 broad tests pass. The remaining live-handoff test cannot recognize the isolated external Cargo target path in this environment, although its log shows the replacement server started.

refs #3314

@coderabbitai

coderabbitai Bot commented Aug 27, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 2812d4a7-14f3-472a-9575-86997011864e

📥 Commits

Reviewing files that changed from the base of the PR and between 7b675f4 and 0b02595.

📒 Files selected for processing (2)
  • src/app/api/worktrees.rs
  • src/app/api/worktrees/deferred.rs

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

The worktree removal error path now requests force confirmation for unregistered checkouts that are not valid working trees. A new test verifies the API response, state transition, cleanup, and absence of workspace changes or events.

Changes

Worktree removal recovery

Layer / File(s) Summary
Removal error confirmation flow
src/app/api/worktrees/deferred.rs, src/app/api/worktrees.rs
The handler requests force confirmation for non-forced not-working-tree errors. The test verifies the worktree_remove_failed response, state transition, cleanup, and unchanged workspaces and events.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to 0b025

Retrying a partially removed worktree now reaches explicit force confirmation while preserving safeguards against deleting registered or unrelated directories. No actionable merge-blocking risk remains after normal checks.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
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.
Title check ✅ Passed The title clearly summarizes the main change: enabling retries for partial worktree removal.
Description check ✅ Passed The description directly explains the failed retry scenario, the force-confirmation fix, API behavior, safeguards, and verification results.
  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@kangal-bot kangal-bot added the ai-review Trigger automated AI reviews for pull requests admitted by the PR gate label Aug 27, 2026
@akbash-bot
akbash-bot force-pushed the akbash/3314-retry-worktree-removal branch from 0b02595 to c70825e Compare August 27, 2026 19:39
@greptile-apps

greptile-apps Bot commented Aug 27, 2026

Copy link
Copy Markdown

Greptile Summary

This PR allows an interrupted worktree removal to be retried when Git has already unregistered the checkout but left its directory behind.

  • Recognizes Git’s “not a working tree” failure as requiring explicit force confirmation.
  • Preserves the existing API error code and original Git message.
  • Adds a regression test covering deferred API removal state, response behavior, and absence of premature workspace or event mutations.

Confidence Score: 5/5

The PR appears safe to merge because the new retry state remains explicitly confirmed and the existing forced-cleanup guards continue to reject registered or unrelated directories.

The change only enables confirmation after a recognized partial-removal error; operation identity and path matching protect modal state, and filesystem cleanup remains gated by registration and repository-identity checks.

Important Files Changed

Filename Overview
src/app/api/worktrees/deferred.rs Extends deferred removal error handling to request explicit force confirmation for recognized partial-removal errors while retaining existing response semantics and path/state matching.
src/app/api/worktrees.rs Adds focused regression coverage verifying the response, pending-operation cleanup, modal transition, and preservation of workspace and event state.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Deferred worktree removal] --> B{Git result}
  B -->|Success| C[Remove workspace and emit events]
  B -->|Dirty checkout| D[Return dirty_worktree_requires_force]
  B -->|Not a working tree| E[Return worktree_remove_failed]
  D --> F[Show explicit force confirmation]
  E --> F
  F --> G[Confirmed forced retry]
  G --> H{Path still registered or unrelated?}
  H -->|Yes| I[Reject cleanup]
  H -->|No, valid repository leftover| J[Remove leftover directory]
Loading

Reviews (1): Last reviewed commit: "fix: allow retrying partial worktree rem..." | Re-trigger Greptile

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai-review Trigger automated AI reviews for pull requests admitted by the PR gate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants