GeezerVison is showing github.com — [BUG] SQLite WAL grows unbounded (10–15 GB) while Desktop is running — disk fills to 0, recovers only on full quit · Issue #37495 · anomalyco/opencode
[BUG] SQLite WAL grows unbounded (10–15 GB) while Desktop is running — disk fills to 0, recovers only on full quit #37495DescriptionSummary
opencode Desktop opens multiple independent SQLite connections to the same opencode.db (one per TUI backend + one from the Electron controller). Because each connection holds a long-lived read transaction, the WAL can never be checkpointed past the oldest reader. wal_autocheckpoint silently fails, PRAGMA wal_checkpoint(TRUNCATE) returns 1 (BUSY), and the WAL grows without bound during normal use until the disk is full. Closing the Desktop kills all connections → checkpoint finally runs → space returns.
This matches the symptom users are reporting: "opencode eats all available disk space while running, even when idle. After quitting, free space comes back."
Environment
- opencode Desktop: v1.18.1 (Linux build,
/opt/OpenCode/ai.opencode.desktop)
- OS: Linux x86_64, ext4 on NVMe
- Window manager: multiple windows/tabs of opencode Desktop open simultaneously
- DB:
~/.local/share/opencode/opencode.db (SQLite in WAL mode)
PRAGMA wal_autocheckpoint: 1000 (default, correctly set — but ineffective, see below)
Reproduction
- Launch opencode Desktop.
- Open 2+ windows (or wait — even a single Desktop launch spawns 3 TUI backends + 1 Electron utility in my case).
- Use the app normally for ~30–60 min (any session activity: streaming tokens, tool calls, MCP polling).
- Observe
opencode.db-wal growing continuously; df shows free space dropping.
- After hours/days of uptime with heavy MCP/plugin usage, the disk reaches 0 free.
- Quit opencode Desktop completely → free space returns (WAL truncates on connection close).
Observed on my machine (single Desktop launch)
$ lsof ~/.local/share/opencode/opencode.db
COMMAND PID NAME
opencode 1798003 ~/.local/share/opencode/opencode.db ← TUI backend
opencode 1837890 ~/.local/share/opencode/opencode.db ← TUI backend
opencode 1842501 ~/.local/share/opencode/opencode.db ← TUI backend (RSS 3.3 GB)
ai.opencode.desktop 1855509 .../opencode.db ← Electron utility
4 concurrent connections to the same database file, each holding an open read transaction.
Root cause
SQLite's WAL mode has a fundamental constraint:
A read transaction prevents the WAL from being checkpointed past the point at which the read transaction was opened. Checkpoint can only reclaim frames older than the oldest active reader.
With N ≥ 2 always-open connections that never release their read snapshots simultaneously:
- Every token-stream chunk, tool output, and status update writes a new frame to the WAL (event-sourcing pattern:
message.part.updated, message.updated, session.updated events dominate — I have 28,881 / 12,059 / 3,668 historical rows respectively).
wal_autocheckpoint=1000 tries to fire every 1000 pages → blocked by concurrent readers → silently no-ops.
- WAL grows linearly with session activity.
- On Desktop quit: all 4 processes die, all connections drop, SQLite's shutdown hook runs
wal_checkpoint(TRUNCATE) → WAL merges into main db + truncates to ~0 → space returns.
Direct evidence — checkpoint returns BUSY
$ sqlite3 ~/.local/share/opencode/opencode.db 'PRAGMA wal_checkpoint(TRUNCATE);'
1|950|930
↑
1 = SQLITE_BUSY (checkpoint could not complete because of concurrent readers)
$ du -h ~/.local/share/opencode/opencode.db-wal
2,4G ~/.local/share/opencode/opencode.db-wal ← unchanged after the "TRUNCATE"
WAL growth observed
| Time |
WAL size |
Δ |
| 16:09 |
462 MB |
— |
| 16:30 |
2.4 GB |
+1.9 GB / 21 min |
Extrapolating linearly to a multi-day session with heavy MCP usage → 10–15 GB. Matches the user-reported symptom.
Expected behavior
- WAL should be bounded (a few hundred MB at most) thanks to
wal_autocheckpoint.
PRAGMA wal_checkpoint(TRUNCATE) issued from any external tool should succeed and reclaim the space.
- The Desktop should be able to run for days without filling the disk.
Actual behavior
- WAL grows unbounded during runtime.
- Auto-checkpoint is ineffective.
- Manual
TRUNCATE returns BUSY while the app is running.
- Disk fills to 0; only a full Desktop quit reclaims the space.
Suggested fixes (any one of these would resolve it)
- Pool DB access through a single process (Desktop controller owns the only write connection; backends talk to it via IPC). This is the correct long-term fix and matches how Tauri/Electron apps typically handle SQLite.
- Use
PRAGMA wal_checkpoint(RESTART) on a timer from the primary writer, after ensuring no long-lived read transactions are held (open read cursors with BEGIN DEFERRED and commit promptly).
- Switch to
journal_mode=DELETE (regression in write throughput, but bounds disk usage to the main db file).
- At minimum, expose a "compact now" action in the Desktop UI that closes & reopens all connections, runs
wal_checkpoint(TRUNCATE), and reports reclaimed space.
- Investigate why 3 TUI backends are spawned per Desktop launch — appears to be a separate bug (window/tab lifecycle leak).
Workarounds for affected users
- Keep only one opencode Desktop window open. Each additional window multiplies the contention.
- Periodically quit & relaunch Desktop after long sessions (frees the WAL).
- External checkpoint won't work while the app is running (BUSY), so don't bother scripting it.
- Delete stale
.bak files that accumulate independently (not a runtime issue, but worth cleaning):
ls -lah ~/.local/share/opencode/opencode.db.bak.*
# rm after verification
Diagnostic script
Anyone wanting to verify on their machine:
echo "=== concurrent DB connections ==="
lsof ~/.local/share/opencode/opencode.db | tail -n +2 | awk '{print $1, "pid="$2}' | sort -u
echo "=== WAL size ==="
du -h ~/.local/share/opencode/opencode.db-wal
echo "=== try checkpoint (1 = BUSY = bug present) ==="
sqlite3 ~/.local/share/opencode/opencode.db 'PRAGMA wal_checkpoint(TRUNCATE);'
echo "=== autocheckpoint setting ==="
sqlite3 ~/.local/share/opencode/opencode.db 'PRAGMA wal_autocheckpoint;'
If the checkpoint returns 1|...|..., the bug is reproducing on your machine too.
Related
Priority: High — silently destroys disk capacity for any user with long sessions and plugins.
/cc @thdxr
Plugins
No response
OpenCode version
1.18.3
Steps to reproduce
- Launch opencode Desktop.
- Open 2+ windows (or wait — even a single Desktop launch spawns 3 TUI backends + 1 Electron utility in my case).
- Use the app normally for ~30–60 min (any session activity: streaming tokens, tool calls, MCP polling).
- Observe
opencode.db-wal growing continuously; df shows free space dropping.
- After hours/days of uptime with heavy MCP/plugin usage, the disk reaches 0 free.
- Quit opencode Desktop completely → free space returns (WAL truncates on connection close).
Screenshot and/or share link
No response
Operating System
Manjaro Linux
Terminal
No response Activitygithub-actions commented on Jul 17, 2026 This issue might be a duplicate of existing issues. Please check:
B67687 commented on Aug 3, 2026 Concrete evidence from a real incident (2026-08-02, opencode v1.18.11 on Linux)
Same failure signature as this issue: our SQLite store grew to 5.45GB main DB + 5.48GB WAL (~11GB total) because a runaway agent loop kept writing session state into the shared store and the WAL was never checkpointed.
Sequence:
- An agent loop hit a transient
AI_APICallError: Internal Server Error (provider error, deepseek-v4-flash via opencode-go) at 10:10:07 and entered a silent infinite retry loop (~94% CPU, 2 hours, zero log output).
- The loop kept writing into the shared SQLite store (WAL mode). WAL never checkpointed because the writer never paused.
- Every new opencode instance in the same project then opened the pathological DB and aborted natively (SIGABRT, 'core dumped') right after the boot line 'booting location services' — storage/session-list init, where the giant WAL gets read. No log line, no journal, no apport entry.
Intermittency matched DB state at launch (WAL size / stale writer locks).
Remediation (manual, destructive-safe): killed runaway PID, PRAGMA wal_checkpoint(TRUNCATE), VACUUM (reclaimed ~1.7GB freelist on a 5.45GB DB with 1,330,391 pages, page_size 4096), rotated logs. DB back to 3.6GB, integrity ok, WAL ~4KB.
What would help
Happy to provide more data (DB schema stats, exact crash sequence) if useful. clayleopardlabs commented on Aug 3, 2026 Data point: this WAL growth is not only a Desktop/multi-connection issue. On a CLI-only (npm install, single process) setup, opencode.db-wal reached 104 MB with no Desktop involved, after a couple of days of normal use with plugins. Single-process WAL growth from the write-heavy event pattern (message.updated, message.part.updated, session.updated) happens too, just slower than the 4-connection Desktop case. Worth noting in the root cause discussion so the fix isn't scoped only to Desktop connection pooling. 4Liberty commented on Sep 27, 2026 Matches what we measured, with one useful nuance: the WAL file is stale size, not live data.
After several days of uptime the WAL file was 12.96 GB while PRAGMA wal_checkpoint(PASSIVE)
from a second connection reported only 479 frames (~2 MB) of live WAL. A
PRAGMA wal_checkpoint(TRUNCATE) on that same connection shrank the file to 0 bytes and
reclaimed ~12.1 GB while the service kept serving - no full quit needed. It recurs: within
about an hour of normal interactive load the file was ~500 MB with ~139 MB of live frames.
So the durable fix is bounding the file itself, e.g. journal_size_limit on the service's
database connections, or truncating after a completed checkpoint while the service runs. thdxr commented on Oct 11, 2026 Thanks for the report! OpenCode 2.0 is now out and development is focused on V2, so we're closing issues filed against OpenCode 1. Please upgrade (opencode upgrade --major, details: https://anoma.ly/notes/opencode-2-0), and if this is still relevant on 2.0, reopen this issue or open a new one with your 2.0 version.
— from 𝕺𝖕𝖊𝖓𝕮𝖔𝖉𝖊
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|