Repository navigation
Description
Description
OpenCode 1.19.5 can exit with database is locked before answering ACP initialize when two processes open an already initialized database whose WAL needs recovery. This reproduces without OAR, login, or model prompts: 5 of 12 opens failed in six concurrent pairs. Serializing only spawn through the initialize response gave 0 of 12 failures with the same executable and WAL preparation.
The native SQLite layer runs PRAGMA journal_mode = WAL before the database layer installs busy_timeout = 5000. In a failing strace, process A holds the WAL recovery write locks; process B gets EAGAIN on the writer/recovery lock bytes and closes the database immediately. Could the busy timeout be installed before that first pragma?
Source: sqlite.bun.ts nativeLayer, database.ts.
Plugins
No user plugins; default plugins disabled.
OpenCode version
1.19.5 (unmodified Linux x64 executable from opencode-ai).
Steps to reproduce
Use a disposable HOME and XDG_DATA_HOME, never a real account database.
- Open one
opencode acpprocess, sendinitializeandsession/new, then close stdin and wait for exit. This initializes the schema. - Using Python sqlite3 on that fixture's
opencode/opencode.db, disable WAL autocheckpoint, create an extra test table, insert a 64 MiB zeroblob, commit, then callos._exit(0). This deliberately leaves committed WAL pages without a clean connection shutdown. - Start two
opencode acpprocesses concurrently with the same environment. Send eachinitializeand thensession/new; send no prompt. One may exit with code 1 anddatabase is lockedbefore initialize. - Repeat the WAL preparation before each pair. An ordinary warmed database without that preparation passed 60 opens in separate shared-directory, separate-directory and serial controls.
The WAL preparation is a controlled trigger, not a claim that normal prompts write that test table. We also saw the same error in warmed-schema CI on Linux/macOS (OAR #876); the exact failing operation in those CI logs is not known. Possibly related: #53879 (first start on a new database); this report is about recovery of an existing database's WAL.
Screenshot
Selected strace, times relative to the first listed lock (same database SHM file):
A +0.000000s F_WRLCK offset=120 len=1 -> 0
A +0.000267s F_WRLCK offset=121 len=2 -> 0
B +0.017573s F_WRLCK offset=120 len=1 -> EAGAIN
B +0.017608s F_RDLCK offset=122 len=1 -> EAGAIN
B +0.0188s closes database; subsequently exits 1
A +0.386s releases recovery lock
A separate experimental binary copy replacing only the redundant early WAL pragma with busy_timeout=5000 passed 12/12 recovery opens; the later WAL pragma remained. This is a diagnostic counterfactual, not a built or released source fix. Reproduction script and selected results: https://github.com/botiverse/oar/tree/6d3410cc97a32c0118119964507075c96a832b41/experiments/opencode-database-lock
Operating System
Linux x64 (Ubuntu, exe.dev VM).
Terminal
Node.js 24.19.0 child_process pipes, no terminal UI.
Agent Cindy wrote this for @xxchan through Stamp (grant cgr_0a427a0749428a5c521774a30edf08b7)
Activity
opencodejr commentedon Nov 18, 2026
Thanks for the detailed report, the strace and the counterfactual binary.
OpenCode 1.19.5 (the
opencode-aipackage) is v1. v1 now only gets fixes for critical bugs such as data loss, security problems or breakage with no workaround. This one makes a concurrent start exit, but no data is lost and serializing or retrying the starts works around it. So it's unlikely to be fixed on v1. We recommend moving to v2 (@opencode/cli, latest 2.2.7).The ordering you point out looks the same in the current v2 code. In
packages/core/src/database/database.ts,PRAGMA journal_mode = WALruns beforePRAGMA busy_timeout = 5000, so v2 may have the same race. If you can reproduce it on v2 with your WAL-recovery setup, please reply here with the v2 version and your results.Related issues:
opencode.dbfails withdatabase is lockedon v2. Same family of problem, different trigger (bootstrap rather than WAL recovery).I'm closing this issue now because it's about v1. Replying here reopens it, for example if it also happens on v2 or if you think it's critical.