You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[FEATURE]: V2 offline SQLite inspection, verified backups and vacuum #54618
Users need to inspect an existing SQLite database, create a verified recovery copy, and reclaim free pages without starting OpenCode migrations or deleting sessions.
I have prepared a filesystem-only v2 CLI prototype:
opencode db inspect <path>: read-only allocation/WAL/SHM and event-byte overview.
opencode db backup <path> <target>: a committed-WAL snapshot with integrity/FK checks; existing targets and aliases are rejected.
opencode db vacuum <path> <target> --apply: verified backup first, exclusive ownership, physical VACUUM and WAL truncate; logical rows are preserved.
Local v2 defaults to events.persist=false; that still preserves session projections. The v1 message.updated.1 growth reported in #33356 does not establish the same problem on current v2. Old event-compaction logic needs a separate v2 retention/replay design. Workerd uses Durable Object SQLite and needs its own storage-compatible approach.
The CLI prototype is prepared and tested on WSL. Next, I can verify native Windows/Node and provide measurements from anonymized copies of v2/migrated databases. Later cleanup of legacy tables needs migration parity and recovery tests; API/UI maintenance needs an admission/recovery design.
Before opening an upstream implementation PR, I would like feedback on whether this offline CLI belongs in core and on the command/capability interface. Storage API/UI and durable retention can be discussed separately.
The prototype preserves Chris Huber's attribution from #41711.
The v2 prototype is available in romanilyin#1 (draft).
Thanks for the detailed proposal and for keeping the attribution from #41711! As I understand it, you'd like v2 to have offline opencode db inspect, opencode db backup and opencode db vacuum commands. They would let users look at a SQLite database, make a checked recovery copy and reclaim free pages, without running migrations or deleting sessions. Maintainers will look at whether this belongs in core and give feedback on the command interface.
Data point for db vacuum --apply: the expensive half can run online
From a 17 GiB store on 2.1.4: VACUUM INTO '/tmp/copy.db' against the live database, over a read-only connection with the daemon still running, produced a consistent compact copy in 5.9 s — 17 203 MiB → 780 MiB, quick_check ok, row counts identical (133 sessions, 8 570 messages, 124 309 parts, 9 credentials), no exclusive lock needed.
So --apply could keep the exclusive window down to the cheap part: build and verify the copy online, then take ownership only to rename it into place and truncate the WAL. That also means the slow-looking step (rewriting ~780 MiB) does not have to be what forces a daemon stop on a store that is several GB of mostly free pages.
Thanks @GladSI — this is a useful measurement, especially the time needed to produce the compact copy. I agree that VACUUM INTO is worth considering for online compact backups.
For --apply, there is an extra correctness requirement: SQLite documents the output as a consistent snapshot. Writes committed after that snapshot would not be included. Taking ownership only for the final rename would therefore need a reliable way to detect and handle those writes, plus coordinated connection shutdown, WAL handling and crash recovery. Integrity checks and matching row counts alone would not establish that no newer data is lost.
I would keep the first implementation scoped to offline maintenance, and treat an online preparation/short cutover mode as a follow-up with concurrent-write and recovery tests. The prototype is in romanilyin#1. Maintainer feedback on whether the offline commands belong in core, and on their interface, would help me decide the next upstream step.
Activity
opencode-agent commentedon Oct 11, 2026
Thanks for the detailed proposal and for keeping the attribution from #41711! As I understand it, you'd like v2 to have offline
opencode db inspect,opencode db backupandopencode db vacuumcommands. They would let users look at a SQLite database, make a checked recovery copy and reclaim free pages, without running migrations or deleting sessions. Maintainers will look at whether this belongs in core and give feedback on the command interface.Related issues and PRs:
eventtable: opencode.db reaches 13GB+, mostlymessage.updated.1snapshots (no retention/compaction) #33356: unbounded growth of theeventtable (v1message.updated.1)GladSI commentedon Oct 25, 2026
Data point for
db vacuum --apply: the expensive half can run onlineFrom a 17 GiB store on 2.1.4:
VACUUM INTO '/tmp/copy.db'against the live database, over a read-only connection with the daemon still running, produced a consistent compact copy in 5.9 s — 17 203 MiB → 780 MiB,quick_check ok, row counts identical (133 sessions, 8 570 messages, 124 309 parts, 9 credentials), no exclusive lock needed.So
--applycould keep the exclusive window down to the cheap part: build and verify the copy online, then take ownership only to rename it into place and truncate the WAL. That also means the slow-looking step (rewriting ~780 MiB) does not have to be what forces a daemon stop on a store that is several GB of mostly free pages.romanilyin commentedon Oct 26, 2026
Thanks @GladSI — this is a useful measurement, especially the time needed to produce the compact copy. I agree that
VACUUM INTOis worth considering for online compact backups.For
--apply, there is an extra correctness requirement: SQLite documents the output as a consistent snapshot. Writes committed after that snapshot would not be included. Taking ownership only for the final rename would therefore need a reliable way to detect and handle those writes, plus coordinated connection shutdown, WAL handling and crash recovery. Integrity checks and matching row counts alone would not establish that no newer data is lost.I would keep the first implementation scoped to offline maintenance, and treat an online preparation/short cutover mode as a follow-up with concurrent-write and recovery tests. The prototype is in romanilyin#1. Maintainer feedback on whether the offline commands belong in core, and on their interface, would help me decide the next upstream step.