Repository navigation
Description
Problem Description
When two devops repos worktrees add runs start at about the same time, the second run warns that it did not reclaim a merged worktree that the first run already removed. The end state is correct, because the worktree is gone. The warning is false, and it tells the person or the agent that something failed.
The cause: prune_worktrees (src/devops_cli/git/worktree_inventory.py) decides every worktree before it removes one, and each decision reads GitHub (get_commit_pulls). The reads take seconds. Two runs decide the same merged worktree as removable. The first run removes it. The git worktree remove of the second run then fails with "is not a working tree", and the loop reports the item as failed. reclaim_merged_worktrees (src/devops_cli/git/worktree_add.py) turns each failed item into reclaim_error, and devops repos worktrees add prints it as a warning.
Reproduction Steps
- Have one clean worktree under
.data/agent/worktrees/at the head of a merged pull request (herew-2395, merged as chore(deps): update ollama to 0.40.12 #2397). - Start
uv run devops repos worktrees add <issue> --type feat --slug <slug>for two different issues at the same time, from two shells. - Read the output of the run that finishes second.
Seen on 2026-10-28 at origin/main bb46660, when four agents started their worktrees at once.
Expected vs Actual Behavior
Expected: a worktree that is gone when the run removes it counts as removed by another run. The run prints no warning for it.
Actual: Merged worktrees were not reclaimed: /workspaces/devops-cli/.data/agent/worktrees/w-2395: fatal: '/workspaces/devops-cli/.data/agent/worktrees/w-2395' is not a working tree
Environment Diagnostics
devops-cli at origin/main bb46660, Python 3.14, git in the devcontainer, rootless Podman on WSL2.
Logs, Traces, or Terminal Output
Merged worktrees were not reclaimed: /workspaces/devops-cli/.data/agent/worktrees/w-2395: fatal: '/workspaces/devops-cli/.data/agent/worktrees/w-2395' is not a working tree
Created worktree /workspaces/devops-cli/.data/agent/worktrees/w-815 on branch feat/815-ollama-slot-wait-metric.
git worktree list after both runs shows no w-2395.
Pre-Submission Checklist
- I have verified that no sensitive credentials, private keys, or internal tokens are contained in this issue report.
- I have checked existing issues and pull requests to ensure this is not a duplicate.
Proposed design
Problem statement
Two parallel devops repos worktrees add runs both decide the same merged worktree is removable. The first run removes it. The second run's git worktree remove fails with "is not a working tree". The code reports this as a failed item, and reclaim_merged_worktrees turns it into a reclaim_error warning. The end state is correct because the worktree is gone, but the warning falsely tells the user or agent that a step failed.
Acceptance criteria
- Criterion 1: When
git worktree removefails with "is not a working tree", the item is reported with status "removed" instead of "failed".
Verification: A unit test intests/test_repos_worktrees_reclaim.pysimulates a worktree whose directory was deleted beforeprune_worktreesruns and asserts the item's status is "removed" andfailed_countis 0. - Criterion 2:
reclaim_merged_worktreesdoes not setreclaim_errorwhen the only failure is "is not a working tree".
Verification: A test callsreclaim_merged_worktreesin a scenario where the worktree was already removed and asserts the returnedReclaimResult.erroris None. - Criterion 3:
devops repos worktrees addprints no "Merged worktrees were not reclaimed" warning for a worktree already removed by a parallel run.
Verification: A test or manual run of two paralleladdcommands shows no warning line in the second run's output. - Criterion 4: All existing worktree tests continue to pass.
Verification:uv run devops ci test tests/test_repos_worktrees_reclaim.py tests/test_repos_worktrees_add.py tests/test_repos_worktrees.pypasses.
Key questions
- Where should the fix go: in
prune_worktreesor inreclaim_merged_worktrees?: Inprune_worktreesinsrc/devops_cli/git/worktree_inventory.py, because it is the source of the "failed" status. Other callers such asdevops repos worktrees prunealso benefit from the fix. (proposed) [sources: src/devops_cli/git/worktree_inventory.py:486] - What status should the item receive when
git worktree removesays the path is not a working tree?: "removed", because the end state is identical to a successful removal: the worktree record is gone and the directory is gone. (proposed) [sources: src/devops_cli/git/worktree_inventory.py:486] - What is the exact git error message that identifies the race?: The stderr contains "is not a working tree", as shown in the issue's log output:
fatal: '/workspaces/devops-cli/.data/agent/worktrees/w-2395' is not a working tree. [sources: src/devops_cli/git/worktree_inventory.py:486] - Does the fix require a change to
WorktreePruneItemorWorktreePruneReport?: No. Thestatusfield is a free-form string and "removed" is already a valid status. Thefailed_countandremoved_countfields in the report already handle the two cases. [sources: src/devops_cli/git/worktree_inventory.py:62]
Fit
Fits in one pull request.
Suspected block
None.
Dependencies
None.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsReady
Activity
dan-petty commentedon Oct 28, 2026
Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones on the board.
A race condition produces a false error warning in an existing command.The end state is correct, but the false warning misleads agents and humans into thinking a step failed.It removes a confusing false alarm that agents and humans must interpret in every parallel run.The fix is to treat the 'is not a working tree' error as success in the reclaim loop.Both concern automatic removal of merged worktrees, but #2338 adds the feature while the candidate fixes a false warning when two runs remove the same worktree.dan-petty commentedon Oct 28, 2026
Status set to Ready at 73d1807 (see proposed design in issue body).
chore(main): release 0.12.0 (#2552)