Skip to content

Locking and worktrees

How vteam keeps concurrent runs apart and isolates changes.

vteam uses advisory file locking via atomic mkdir (POSIX guarantees this is atomic). Each lock directory contains an info.json with the holding PID and timestamp.

  • Stale detection: A lock is considered stale only if the holding process is dead (checked via kill -0), so a long run keeps its lock however long it takes. A lock directory without its info file (a crash right after mkdir) is stale after 30 minutes. Stale locks are renamed aside and checked again before being deleted, and a process only releases a lock it still owns.
  • Not distributed: Locks are local to the filesystem. If you run vteam from multiple machines against the same repo (e.g., via NFS), locks won’t protect against concurrent runs.
  • Crash recovery: If vteam crashes while holding a lock, the lock may persist. The next run or vteam clean breaks it once the holding process is dead.
  • Same agent concurrency: Two runs of the same agent are serialized by the lock. Different agents (improver + coder) can run concurrently.
  • Task claiming: Picking a task (list → select → set active) runs under locks/task-claim.lock in the project’s state directory, shared by all agents, so two agents with overlapping taskFilters never get the same task. The lock is held only while picking, not for the whole run. Like every lock it is local: agents on different machines syncing one aven database can still race.
  • Isolation: Agents with worktree: true work in a git worktree under the state directory, branched from origin/<baseBranch>. Your main working tree is never touched.
  • Crash cleanup: If the coder crashes after creating a worktree but before cleanup, the worktree and its branch persist. Run vteam clean to remove orphans.
  • Stale branches: Task branch names include the run ID (vteam/<title-slug>-<runId>), so a retried task never reuses an earlier attempt’s branch. If a local branch with the same name exists, it is deleted before a new worktree is created.
  • Pushing: vteam pushes with --force-with-lease against the commit it started from. A new branch must not exist on the remote yet. A PR branch must still be where vteam checked it out, so if someone pushes to the PR while the coder runs, the push is rejected instead of overwriting their commits, and the task goes back to todo. Network errors (connection reset, broken pipe, remote hung up, timeouts) are retried twice, after 5s and 15s. Before each retry vteam checks whether the dropped push actually reached the remote.
  • Disk space: Each worktree is a full checkout. On large repos, this can be significant. Worktrees are cleaned up after each run.
  • Requires gh (GitHub) or glab (GitLab) CLI installed and authenticated.
  • If the CLI is missing, the branch is still pushed; you just need to create the PR manually.
  • Labels are auto-created in the repository if they don’t already exist.
  • Set "autoPR": false in the agent’s agent.json to skip PR creation entirely.