opencode icon indicating copy to clipboard operation
opencode copied to clipboard

SQLite auto_vacuum is disabled, database files grow indefinitely

Open BYK opened this issue 5 months ago • 2 comments

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

  1. Use OpenCode for extended period with many sessions
  2. Delete old sessions
  3. 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

BYK avatar Jun 09 '26 14:06 BYK

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

  • #16777: Also identified auto_vacuum = OFF as 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.

github-actions[bot] avatar Jun 09 '26 14:06 github-actions[bot]

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.

skywalker-35 avatar Jun 14 '26 15:06 skywalker-35