fix(worktree): claim non-prompt tasks before worktree creation to prevent duplicate-worktree race - #540
Merged
carlospedreira merged 2 commits intoJun 26, 2026
Conversation
…vent duplicate-worktree race
Contributor
Author
|
@carlospedreira Heads up: potential merge conflict with #538 ( |
carlospedreira
approved these changes
Jun 26, 2026
mirzazekicapi
pushed a commit
to mirzazekicapi/dotbot
that referenced
this pull request
Jun 26, 2026
PR andresharpe#528 (fix andresharpe#516) landed Issue B upstream using the correct ownership fix: delete Write-TaskInputInterviewAnswer and Get-TaskInputProductDir entirely, enrich questions_resolved on the task instead. Took upstream version. PR andresharpe#540 (fix andresharpe#536) and PR andresharpe#541 (fix andresharpe#537) auto-merged cleanly. All v4-runtime issues now covered by upstream -- branch has zero unique changes. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Linked issue
Closes #536
Summary of changes
Non-prompt auto-dispatch tasks (
script,mcp,task_gen) claimed in-progress status after worktree creation. Two concurrent runners could both observe the same task astodovia the lock-freeGet-NextWorkflowTask, both callgit worktree addto the same path, and the second would fail withfatal: '...' already exists.Root fix: Added a pre-worktree claim guard for non-prompt tasks mirroring the existing prompt-task guard. Calls
Invoke-TaskMarkInProgress(HTTP POST with server-side mutex) before any worktree I/O.no_op=truein the response signals the task was already claimed — the guard fetches a replacement task and breaks to the outer loop so fulltask_gen/prompt-template recovery runs on it. Removed the post-worktreeSet-TaskInProgressForExecutorDispatchcall, now superseded.Additional hardening (from code review):
$processData.task_id/$env:DOTBOT_CURRENT_TASK_IDafter the guard in case$taskwas replaced during retrycontinuewhen all claim attempts exhausttask_gen/prompt_templaterecoveryTest-ProcessDispatch.ps1assertion to matchInvoke-TaskMarkInProgressinstead of the removed function nameTesting notes
pwsh tests/Test-ProcessDispatch.ps1: the "legal executor status transitions" assertion now validates the claim guard is present.git worktree add; after, the second detectsno_op=trueand picks up a different task.-Slotnot set) still claims and executes non-prompt tasks normally; the guard is unconditional and must not regress the single-runner path.Checklist