Skip to content

Non-atomic task claim causes duplicate worktree creation under concurrency #536

Description

@IBondarenko-iwg

What happened

Multiple task-runner processes running concurrently can simultaneously read the same task as todo in Get-NextWorkflowTask, both pass the claim check, and both attempt git worktree add to the same path. The second call fails fatally, leaving the task in failed or stuck in-progress.

fatal: 'C:\Users...\worktrees<project>\task-<id>-<name>' already exists

Root cause: Get-NextWorkflowTask reads task state without a cross-runner lock. Lock-TaskMutex in Invoke-TaskStatusHandler covers only the HTTP status write — not the read → claim → worktree-creation sequence. Two runners can both observe status = todo before either completes the transition to in-progress.

What you expected

Each task claimed by exactly one runner. Concurrent runners pick distinct tasks; no two runners attempt the same worktree path.

Steps to reproduce

  1. Create N ≥ 5 todo script tasks in .bot/workspace/tasks/standalone/.
  2. Launch one pinned runner per task simultaneously:
    foreach ($id in $taskIds) {
        Start-Job {
            & pwsh -File Invoke-DotbotProcess.ps1 -Type task-runner -TaskId $using:id -Continue
        }
    }
  3. Observe task-runner logs — multiple runners report fatal: '...' already exists for the same worktree path.
  4. Inspect task files — affected tasks land in failed.

Environment

OS: Windows 11
dotbot: current main
PowerShell: 7.x

Severity

high

Logs / screenshots

[task-runner] git worktree add 'C:...\task-t_4aB2cD3e-stress-task-3' HEAD
fatal: 'C:...\task-t_4aB2cD3e-stress-task-3' already exists
[task-runner] worktree creation failed for task t_4aB2cD3e

Metadata

Metadata

Labels

needs-triageNew issue awaiting triage by the steering grouptype:bugSomething is broken

Projects

Status
Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions