SQLite auto_vacuum is disabled, database files grow indefinitely
Describe the bug
The SQLite database has auto_vacuum = 0 (NONE) by default. Deleted rows leave behind free pages that are never reclaimed, causing the database file to grow indefinitely over time. Long-running instances accumulate significant disk usage from deleted session data, compacted messages, and old worktree snapshots.
Steps to reproduce
- Use OpenCode for extended period with many sessions
- Delete old sessions
- Check database file size — it never shrinks
Expected behavior
Enable incremental auto-vacuum so free pages are reclaimed over time. Add checkpoint() and vacuum() utility functions for periodic maintenance.
System info
- OpenCode version: v1.15.3
- OS: Linux
This issue might be a duplicate of an existing issue. Please check:
- #16777: Also identified
auto_vacuum = OFFas a root cause alongside database bloat in long-running instances (now closed)
If that issue didn't fully address the vacuum/disk reclamation aspect, it may be worth referencing it or requesting it be reopened/linked.
Adding another real-world data point to reinforce the urgency of this issue.
Environment: Windows 11, OpenCode latest, E:\opencode-data
Scale: opencode.db grew to 36 GB before disk exhaustion forced a full database recreation (lost all session history).
Root cause confirmed: the part table's data column accumulates full JSON-serialized tool outputs — every bash, grep, read invocation — and never releases them. With heavy use of task() (sub-agent delegation), child sessions proliferate and compound the problem. auto_vacuum = OFF means even if data were pruned, the file would never shrink.
Impact: E drive ran out of space at 36 GB, SQLite WAL write failed, OpenCode couldn't persist new events → entire database was recreated from scratch. All session history, compaction snapshots, and project state were lost.
This is not a theoretical concern — it's a data loss vector in production use. The fix is straightforward: PRAGMA auto_vacuum = INCREMENTAL set before table creation (or via a one-time migration). Would be happy to help test a PR.