Read v1.19.0 before writing this, and two premises in the report do not match that tree. Both change the recovery plan, so they are worth pinning down before anyone writes a fix.
The hourly cleanup prune=7.days is not database retention
packages/opencode/src/snapshot/index.ts:23 is const prune = "7.days", and its only consumer is line 305:
const result = yield* git(args(["gc", `--prune=${prune}`]), { cwd: state.directory })
That is git gc inside the snapshot git dir. The log line comes from Effect.logInfo("cleanup", { prune }) at line 313, and the schedule at 763-764 is Effect.repeat(Schedule.spaced(Duration.hours(1))) plus Effect.delay(Duration.minutes(1)), so one minute after start and then hourly. That is the line you are reading, and it never touches SQLite.
Nothing else prunes event. The only delete on that table is per aggregate, packages/core/src/event.ts:514-519, reached from Session.remove at packages/opencode/src/session/session.ts:623, which is what opencode session delete <id> calls. There is no time based retention, and time_archived is only ever used as a query filter.
So the 9.8 GB event table is not retention failing to reclaim space. There is no retention to fail. That makes your third ask the accurate one, and the other two follow from it: with no delete path, auto_vacuum = 0, and no VACUUM anywhere in the tree, the file can only grow.
The data dir rename is not in this tree either
grep -rn corrupt across v1.19.0 gives two hits, both unrelated strings: an image error message in provider/transform.ts and a comment in the server route. No code path renames the data root. Something else on that host moved ~/.local/share/opencode to opencode.corrupt-<date>, and it will do it again, so identify it before pointing anything at the replacement. It also decides the recovery: if the directory was moved, the history is inside it, and if ENOSPC damaged the database mid transaction, the repair is below.
Recovery
Stop the instances first, then check the file:
sqlite3 ~/.local/share/opencode.corrupt-<date>/opencode.db "PRAGMA integrity_check;"
If it prints ok, nothing is lost. Move the empty root aside and put the old one back:
mv ~/.local/share/opencode ~/.local/share/opencode.empty-$(date +%F)
mv ~/.local/share/opencode.corrupt-<date> ~/.local/share/opencode
If it reports bad pages, .recover rebuilds what is left. I simulated page damage on a 20.6 MB database of this shape by overwriting 8 KB in the middle, got Tree 4 page 1673 cell 4: invalid page number 4024348094, and the rebuilt file came back ok with all 400 sessions, 2,000 messages and 2,400 events:
sqlite3 bad.db ".recover" > recover.sql
sqlite3 new.db < recover.sql
sqlite3 new.db "PRAGMA integrity_check;"
Rows that existed only in the -wal came through in that test, so copy the -wal beside the database rather than recovering the main file alone. Put the output on a filesystem that has room. That is the "does not discard all history silently" flow you asked for, and it works on the version you are running.
Reclaiming the space
VACUUM needs the write lock and temporary space, so against your setup it fails: with a second connection holding a write transaction it returned database is locked (5). On a full disk it has nowhere to write anyway.
VACUUM INTO is the one that works under pressure. It reads only, so it completed while another connection held a write transaction, and the copy holds live rows only, so it needs the compacted size rather than the current size. Measured on a 74.6 MB database shaped like yours, event at 74 percent:
- after deleting 80 percent of the events: file still 74.6 MB, 12,801 of 18,213 pages on the freelist
VACUUM INTO '/other/disk/compact.db': 20.6 MB, integrity ok, counts intact
Sequence that works when you have less free space than the database:
opencode session list -n 100, then opencode session delete <id> for the ones you do not need. That path really does remove the aggregate's event and event_sequence rows, so it is the only retention lever that exists in v1.
sqlite3 "$(opencode db path)" "VACUUM INTO '/path/with/space/compact.db';"
- Stop the instances, swap the file, restart.
Before step 1, find out where the bytes are:
sqlite3 "$(opencode db path)" \
"SELECT name, SUM(pgsize)/1048576 AS mb FROM dbstat GROUP BY name ORDER BY mb DESC LIMIT 8;"
That needs SQLITE_ENABLE_DBSTAT_VTAB. If your build omits it, this gives the same shape from the payload side:
SELECT aggregate_id, COUNT(*), SUM(LENGTH(data))/1048576 AS mb
FROM event GROUP BY aggregate_id ORDER BY mb DESC LIMIT 10;
Which brings in your two companion reports. If event is 76 percent of 12.85 GB, the retention path above is the one that moves the needle; capping message.data diffs helps the other 2 GB and does nothing for the majority table.
WAL
The pragmas set at open are journal_mode = WAL, synchronous = NORMAL, busy_timeout = 5000, cache_size = -64000, foreign_keys = ON, then one wal_checkpoint(PASSIVE) at line 32. No journal_size_limit, no periodic checkpoint.
A passive checkpoint cannot move frames an open reader still needs, which is your 0.8 GB WAL. Measured with one reader holding a snapshot: PRAGMA wal_checkpoint(TRUNCATE) returned 1|1603|3 and the WAL stayed at 6.6 MB. The same command after the reader released returned 0|0|0 and the file went to 0 bytes.
So run the truncating checkpoint from outside the instances, in a window where few readers are live. It is safe against a live database; worst case it returns busy=1 and tells you how many frames it could not move. journal_size_limit is not a lever from outside, since it is per connection and does not persist: I set 67108864 in one shell and the next connection read 32768.
Blast radius
OPENCODE_DB takes an absolute path and wins over the channel naming:
OPENCODE_DB=/srv/oc/instance-3.db opencode
Verified with opencode db path returning exactly that path. Ten instances on one file is why that ENOSPC took out all ten, and why the still running ones kept writing into a quarantined inode. Per instance files turn the failure into one lost instance. The cost is that history stops being shared between instances, so it is a tradeoff rather than a fix. If you keep the shared file, the guard below is what makes the failure loud.
Refusing to start on a full disk
Your first ask, without a code change. Wrap the CLI, exit 75 before startup, pass through otherwise:
#!/usr/bin/env bash
set -uo pipefail
min_free="${OC_GUARD_MIN_FREE_GB:-5}"
db=$(opencode db path) || exit 1
avail=$(( $(df -Pk "$(dirname "$db")" | awk 'NR==2{print $4}') / 1024 / 1024 ))
[ "$avail" -lt "$min_free" ] && { echo "oc-guard: ${avail}GB free, below ${min_free}GB, refusing" >&2; exit 75; }
exec opencode "$@"
opencode db path resolves without opening the database, so the check costs nothing. Tested both arms.
The rest does need code: retention for event with a reclaim step, auto_vacuum = INCREMENTAL from creation since it cannot be turned on later for existing tables, and a clean SQLITE_FULL error path so a full disk is an error instead of a corrupt file.
The durable point underneath all of this is that the record of what your agents decided should not depend on one SQLite file staying healthy. MemoryRouter is what I built for that half: the agent's memory lives in a store outside the context window and outside that file, so a session on any machine recalls what was decided instead of re-deriving it after the local history is gone. For clients without native support it is proxy or MCP: https://docs.memoryrouter.ai/coding-tools?utm_source=github&utm_medium=issue&utm_campaign=anomalyco-opencode