anomalyco / anomalyco/opencode

Concurrent opencode run processes race on shared project upsert

Open
#44,892 1 comment 0 reactions 1 assignee View on GitHub

@kitlangton is already working on this.

Since Aug 25, 2026.

Dominant language
TypeScript
Stars
209k
Forks
27.5k
PR merge metrics
PR metrics pending

Description

Problem

Launching six independent opencode run processes concurrently against six distinct Git worktrees caused five processes to fail immediately while registering projects in the shared SQLite store. One process proceeded normally.

Each failure reported an Unexpected error around the same upsert:

Failed query: insert into "project" (...) values (...) on conflict ("project"."id") do update set ...

The parameters contained a very large shared sandboxes array and reused a project identity whose current worktree pointed at an old orchestration scratch workspace. The five commands targeted different current worktrees, but concurrent startup made project registration a single shared failure point.

Reproduction

  1. Use one OpenCode data directory with an established project that has accumulated many worktree/sandbox paths.
  2. Start several opencode run --dir <distinct-worktree> processes at the same time.
  3. Observe most processes fail during project upsert before creating a session or invoking a model.

Observed on a custom build identifying as:

0.0.0-fix/41117-v2-shell-env-202608071721

Impact

  • Direct coding-agent fanout is not reliable.
  • Independent tasks serialize on or race through one project-row mutation.
  • The error omits the underlying SQLite cause and any retry guidance.
  • Operators must stagger launches manually or isolate data directories, defeating simple parallel subagent orchestration.

Expected

  • Concurrent project registration for distinct worktrees succeeds transactionally.
  • Project/sandbox accumulation is bounded and does not rewrite a large historical array on every process startup.
  • Transient SQLite contention uses a bounded busy timeout/retry policy.
  • Failures expose the underlying SQLite code/message and an actionable retry.

Acceptance

  • Add a multi-process test launching project initialization concurrently for distinct worktrees under one data directory.
  • Assert all processes reach session creation without losing registered worktrees.
  • Bound or normalize project sandbox history so one upsert does not scale with every historical orchestration scratch path.

AI assistance

OpenAI GPT-5.6 Sol via OpenCode coordinated the parallel dispatch, captured the five identical startup failures, searched existing trackers, and drafted this report. Chris Huber directed the workflow and remains responsible.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.