GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Concurrent `opencode run` processes fail mid-session with "Failed to execute statement" (SQLITE_BUSY not retried, no error code) · Issue #65020 · anomalyco/opencode

Concurrent opencode run processes fail mid-session with "Failed to execute statement" (SQLITE_BUSY not retried, no error code) #65020

New issue
Copy link
New issue
Copy link
Closed as not planned
Closed as not planned
Concurrent opencode run processes fail mid-session with "Failed to execute statement" (SQLITE_BUSY not retried, no error code)#65020
Copy link
Labels
area/sessions-storageSessions, history and stored dataplatform/linuxLinuxtype/bugSomething is brokenversion/v2OpenCode 2.x

Description

@linsaftw
linsaftw
opened on Nov 19, 2026
Issue body actions

Version: opencode v2.3.0, Linux x86_64, local ext4/btrfs-class disk (not a network filesystem)

Problem

Running many opencode run --format json processes at once against the same opencode.db makes a large share of them die mid-session with:

{"type":"error","sessionID":"ses_…","error":{"type":"unknown","message":"Failed to execute statement"}}

The message carries no SQLite error code, so callers cannot tell a transient SQLITE_BUSY from a real failure and cannot retry sensibly.

Observed

  • 100 short-lived worker processes launched by an orchestrator, cap raised from 20 to 50 concurrent.
  • Within ~90 s of the cap change, 17 of the first ~35 launched workers failed or had to be requeued; the supervisor classified them as sqlite_other. Several exhausted their retries.
  • At 20 concurrent the same workload had no failures.
  • Database: opencode.db ≈ 5.5 GB with a WAL file (~17 MB) and -shm; all processes share the default data dir.
  • Failures hit processes that were already running (not only boot), so this is different from core: concurrent first start on a new opencode.db fails with "database is locked" / CREATE TABLE error #53879 (first-start CREATE TABLE race). It looks closer to the write contention described in SQLite DB corruption + SQLITE_BUSY lock storm when many agents run concurrently with $HOME on a shared/parallel filesystem #56282, but happens on a local disk.

Likely causes

  1. Each process opens its own connection and writes message/part rows on every streamed step, so N processes = N concurrent writers on one WAL database. WAL allows only one writer; the rest rely on the busy handler.
  2. Busy handling appears to be absent or too short. A write that cannot acquire the lock immediately surfaces as a generic "Failed to execute statement".
  3. With a multi-GB DB, checkpoints and the WAL index are slower, widening the window in which writers collide.

Suggested fixes

  • Set PRAGMA busy_timeout (for example 5–10 s) on every connection, and PRAGMA synchronous=NORMAL with WAL.
  • Retry statements that fail with SQLITE_BUSY / SQLITE_BUSY_SNAPSHOT with bounded jittered backoff instead of failing the session.
  • Use BEGIN IMMEDIATE for write transactions so a lock conflict fails at the start of the transaction, where it is safe to retry, instead of at upgrade time, which is not retryable.
  • Batch part updates (write the final part, or coalesce streamed deltas) so a step costs one write transaction, not many.
  • Include the SQLite result code and extended code in the error (SQLITE_BUSY, SQLITE_LOCKED, …) so wrappers can classify it.
  • Optionally allow a per-run database (OPENCODE_DB=… or an ephemeral session store) for headless run invocations that do not need to share history.

Repro sketch

for i in $(seq 1 50); do
  opencode run --format json -m <any-fast-model> "reply with OK" >/tmp/o$i.log 2>&1 &
done
wait
grep -l 'Failed to execute statement' /tmp/o*.log | wc -l

(Failure count rises with concurrency and with database size.)

Related: #56282, #53879

Activity

  1. opencodejr
    added
    area/sessions-storageSessions, history and stored data
    platform/linuxLinux
    type/bugSomething is broken
    version/v2OpenCode 2.x
    on Nov 19, 2026
  2. opencodejr commented on Nov 20, 2026

    @opencodejr
    opencodejrBot
    on Nov 20, 2026
    Contributor
    More actions

    Thanks for the detailed report. I couldn't reproduce this on v2.3.0 here. None of the runs failed with Failed to execute statement or any other error event, and the server log had no database is locked / SQLITE_BUSY entries.

    What I tried:

    • 50, 70 and 100 concurrent opencode run --format json -m <model> "reply with OK" processes sharing one data dir and one opencode.db (WAL, local disk).
    • A local OpenAI-compatible mock model streaming 200 or 1000 small deltas per reply.
    • A database of about 13 MB, and the same database grown to 2.6 GB.

    Some runs at 70 and 100 hung, but that was caused by a file-watcher limit in my sandbox (EMFILE), not the SQLite error.

    My runs were short and my large database was mostly filler, so they may not create the same lock pressure as your setup. These would help:

    • The server log lines around a failure. Logs are under <data dir>/opencode/log/ (for example ~/.local/share/opencode/log/). Search for locked, BUSY or Failed to execute and paste the full lines with any stack or cause.
    • Roughly how long each worker's session runs, and whether workers run tools (shell, edits) or only reply.
    • Whether it still happens after PRAGMA wal_checkpoint(TRUNCATE) on the database while no opencode process is running, or with a fresh data dir (XDG_DATA_HOME=...) at 50 concurrent.
    • CPU count and disk type (NVMe/SSD/HDD), and the output of opencode --version.

    Related: #47566 (same symptom on V1, closed), #56282 (lock storm on a shared filesystem) and #53879 (race on first start). The open PR #59521 retries SQLite statements on lock timeout.

  3. opencodejr
    closed this as not plannedon Nov 20, 2026
  4. opencodejr commented on Nov 20, 2026

    @opencodejr
    opencodejrBot
    on Nov 20, 2026
    Contributor
    More actions

    I'm closing this for now. I couldn't reproduce the Failed to execute statement failures on v2.3.0 with up to 100 concurrent opencode run processes sharing one database, and we didn't get the details that could show what's different on your setup.

    If it still happens, these would help most:

    • The server log lines around a failure (search for locked, BUSY or Failed to execute)
    • How long each worker's session runs, and whether it runs tools
    • Your CPU count and disk type

    Related: #56282, #53879, and the open PR #59521, which retries SQLite statements on lock timeout.

    Replying here with those details reopens this issue.

  5. WhiteWarrior625 commented on Nov 25, 2026

    @WhiteWarrior625
    WhiteWarrior625
    on Nov 25, 2026
    More actions

    Seeing this on 1.19.6 (Windows) with 11 concurrent opencode serve processes, one per session from a desktop client, sharing one 11.7 GB opencode.db. The sessions are long agent sessions that run tools. Three died within a minute of each other with:

    level=ERROR message="prompt_async failed" cause="Cause([Die(effect/sql/SqlError: Failed to execute statement (cause: effect/sql/SqlError/LockTimeoutError: Failed to execute statement (cause: SQLiteError: database is locked)))])"
    

    The machine was under heavy load at the time (about 650 MB free RAM, about 80% CPU, about 20 concurrent git processes from snapshots). The limit being hit looks like the hard-coded PRAGMA busy_timeout = 5000; 2.4.1 has the same value.

    Repro that needs no model: on an empty WAL database, hold a write lock from another connection (BEGIN IMMEDIATE) for 15 s and run OPENCODE_DB=<that file> opencode session list. Stock 1.19.6 exits 1 after about 6.5 s (the migration's CREATE TABLE fails). The same binary with only that pragma changed to 120000 waits and exits 0 once the lock is released. A retry like #59521, or a configurable busy timeout, would fix this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/sessions-storageSessions, history and stored dataplatform/linuxLinuxtype/bugSomething is brokenversion/v2OpenCode 2.x

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.