Environment
- OS: WSL2 Ubuntu 24.04 on Windows 11
- Runtime: Node v24.16.0, npm 11.13.0
- Database: SQLite (default backend)
- Agent: opencode (via the opencode provider in @codewithdan/agent-sdk-core)
Background Scenario
I created a task group with 3 child tasks, all with useWorktree enabled. On the first run, the target repository was a newly created empty repo (no commits), and the base branch specified by the group (Analysis) did not exist. As a result, all 3 child tasks failed during worktree creation (git worktree add reported fatal: invalid reference) and ended up in the failed state.
Issue: Task stuck in "running" state after worktree creation failure
Trigger: A task with useWorktree enabled whose worktree creation fails (in my case: empty repo + missing base branch). The stuck state persisted even after the commit and Analysis branch were created; only a server restart cleared it.
Symptom: The board shows the task as failed, but GET /api/tasks/:id/status returns isRunning: true. Re-running or retrying returns 409 agent already running for this task ("already in progress" in the UI).
Findings: startAgent registers an in-memory session placeholder (this.sessions.set) before creating the worktree. When worktree creation throws, the failure path calls terminateOnce('failed') but does not remove the placeholder, leaving the in-memory state ("running") out of sync with the database state (failed), so isRunning() stays true. This is unrelated to whether the repo/branch is ready; it is cleared only after a server restart, when the startup recovery resets the task to failed.
Environment
Background Scenario
I created a task group with 3 child tasks, all with
useWorktreeenabled. On the first run, the target repository was a newly created empty repo (no commits), and the base branch specified by the group (Analysis) did not exist. As a result, all 3 child tasks failed during worktree creation (git worktree addreportedfatal: invalid reference) and ended up in thefailedstate.Issue: Task stuck in "running" state after worktree creation failure
Trigger: A task with
useWorktreeenabled whose worktree creation fails (in my case: empty repo + missing base branch). The stuck state persisted even after the commit and Analysis branch were created; only a server restart cleared it.Symptom: The board shows the task as
failed, butGET /api/tasks/:id/statusreturnsisRunning: true. Re-running or retrying returns 409agent already running for this task("already in progress" in the UI).Findings:
startAgentregisters an in-memory session placeholder (this.sessions.set) before creating the worktree. When worktree creation throws, the failure path callsterminateOnce('failed')but does not remove the placeholder, leaving the in-memory state ("running") out of sync with the database state (failed), soisRunning()stays true. This is unrelated to whether the repo/branch is ready; it is cleared only after a server restart, when the startup recovery resets the task tofailed.