Skip to content

Concurrent instances on the same project cause silent crash (SQLite WAL lock contention) #36775

Closed

Description

@PaxGooroo

Summary

Running two OpenCode instances simultaneously on the same project directory causes one of them to crash silently with no user-facing error. The root cause is concurrent write contention on the shared SQLite database (~/.local/share/opencode/opencode.db).

Steps to reproduce

  1. Open a terminal in your project directory and start opencode (instance A)
  2. Open a second terminal in the same directory and start opencode (instance B)
  3. Use both instances concurrently (e.g., one running a long task, the other starting a new session)
  4. One of the instances dies silently — no error message to the user

Observed behavior (from logs)

On 2026-07-13, two instances had been running for hours:

Run ID Started Sessions Status
85243909 17:52 UTC quick-wolf, silent-wizard Orphaned at 22:01
cec74255 18:57 UTC quick-meadow Orphaned at 21:58

At 22:00:56 UTC, two new instances spawned simultaneously:

  • b2b3534d (survived, auto-upgraded 1.17.19→1.17.20)
  • 8a5c1dc2 (crashed after 12 log lines, 0 sessions created, dead on arrival)

The 8a5c1dc2 instance only logged bootstrapping/init and then went silent — no session creation, no error message, no recovery.

Log evidence

2026-07-13T22:00:56.058Z  creating instance  run=b2b3534d  directory=/home/carole/Cyril/Obsidian
2026-07-13T22:00:56.225Z  creating instance  run=8a5c1dc2  directory=/home/carole/Cyril/Obsidian
2026-07-13T22:00:56.391Z  bootstrapping     run=b2b3534d
2026-07-13T22:00:56.579Z  bootstrapping     run=8a5c1dc2
2026-07-13T22:00:56.605Z  init              run=b2b3534d
2026-07-13T22:00:56.726Z  init              run=8a5c1dc2   ← last entry for this instance

Instance 8a5c1dc2 logged exactly 12 entries total, then disappeared completely.

Root cause hypothesis

SQLite in WAL mode supports concurrent readers but only one writer at a time. Both OpenCode instances continuously write to the database (session messages, permission evaluations, project refresh). When the auto-upgrade (1.17.19→1.17.20) triggered a schema migration on b2b3534d, the lock contention killed 8a5c1dc2.

Expected behavior

OpenCode should either:

  1. Detect that another instance is already running on the same project and refuse to start (with a clear message)
  2. Or implement proper inter-process locking (e.g., a .lock file) to coordinate writes

Environment

  • OS: Debian Linux
  • OpenCode version: 1.17.18→1.17.20 (auto-upgraded during the incident)
  • Working database: SQLite 3.x WAL mode (~23MB)

Activity

  1. github-actions commented on Jul 13, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of existing issues. Please check:

  2. PaxGooroo commented on Jul 13, 2026

    @PaxGooroo
    Author

    Update : doublon partiel identifié a posteriori.

    Cette issue chevauche plusieurs rapports existants :

    Contexte specifique de mon environnement (Debian 13 Trixie, KDE Plasma, 12 Go RAM, Tailscale pour DNS) :

    • Les erreurs "Cannot connect to API" (19:07, 19:59, 20:00 UTC) sont probablement liees a une micro-coupure DNS Tailscale
    • Le lock SQLite WAL a pete quand l'auto-upgrade (1.17.19 vers 1.17.20) s'est declenche alors que 2 instances ecrivaient simultanement
    • L'instance orpheline (8a5c1dc2) ne laisse aucune trace d'erreur exploitable — juste 12 lignes de log puis le silence

    Je ferme en faveur des issues existantes, mais je peux fournir les logs complets si besoin sur #35801 ou #36688.

  3. PaxGooroo commented on Jul 13, 2026

    @PaxGooroo
    Author

    Closed as duplicate — chevauche #35801, #36688, #36709. Voir commentaire ci-dessus pour le contexte environnemental (Debian 13, KDE, Tailscale).

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions