Repository navigation
Conversation
…eck_merge item_release only released the DB claim lease -- it never touched the worktree at all. done (when it goes straight to completed) and check_merge (once a PR merges) were the only paths that ever called cleanup_worktree, so any item abandoned via a plain release, or moved to completed by hand outside the done flow, orphaned its .worktrees/task/<id> forever. Confirmed live: 24 stale worktrees currently sitting under .worktrees/task/, several from items released without going through done. Wire cleanup_worktree into item_release the same way item_done already does: DB read+release under the backend lock, cleanup attempt outside it. cleanup_item_worktree already refuses a dirty tree, so this is safe to call unconditionally on a successful release. Add item_release_removes_its_own_clean_worktree and item_release_leaves_a_dirty_worktree_in_place, mirroring the existing item_done coverage.
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthrough
ChangesRelease Worktree Cleanup
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/mcp_server/item.rs`:
- Around line 515-529: The item_release flow currently releases the claim before
cleanup, allowing a concurrent item_claim to reuse and lose the worktree. Update
item_release and the surrounding claim/cleanup logic so cleanup_worktree runs
while the claim remains held, then release the claim afterward; add a concurrent
test covering this ordering and preventing the claimed worktree from being
removed.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 2f984065-808f-4712-9fe2-86cb4c7c0bbd
📒 Files selected for processing (2)
src/mcp_server/item.rssrc/mcp_server/tests/action_tests.rs
Addresses CodeRabbit review on PR #388: releasing the claim before cleanup_worktree opened a window where a concurrent claim could grab the item and start working in the worktree just before cleanup deleted it. Check ownership first, clean up, then release last -- same order item_done's no-PR path already uses.
Summary
Item #335 (git-shim/worktree lifecycle reliability). Two sub-issues were filed under this item:
git worktreedenying read-only ops (list,prune --dry-run) identically to mutating ones — already fixed in currentclassify_pure(theworktreematch arm already special-cases read-only subcommands). No change needed here.claim done/releasenot reliably cleaning up worktrees — this PR's fix.item_releaseonly ever released the DB claim lease; it never touched the worktree directory at all.item_done(when it goes straight tocompleted) anditem_check_merge(once a PR merges) were the only two paths that calledcleanup_worktree— so any item abandoned via a plainrelease, or moved tocompletedby hand outside thedoneflow, orphaned its.worktrees/task/<id>forever. Confirmed live on this machine: 24 stale worktrees currently sitting under.worktrees/task/, several from items released without ever going throughdone.Fix
Wire
cleanup_worktreeintoitem_releasethe same wayitem_donealready does it: resolve the item + release the claim under the backend DB lock, then attempt cleanup outside it.cleanup_item_worktreealready refuses a dirty tree (uncommitted changes), so this is safe to call unconditionally on every successful release.Testing
item_release_removes_its_own_clean_worktreeanditem_release_leaves_a_dirty_worktree_in_place, mirroring the existingitem_donecoveragecargo test --bin agentflare item_— 81 passed, 0 failed, 1 ignored (unrelated manual benchmark)cargo fmt --checkcleancargo clippy --workspace --all-targets --all-features -- -A unsafe_code -A clippy::pedantic -D warningscleanSummary by CodeRabbit
Bug Fixes
Tests