Repository navigation
fix(core): skip the WAL checkpoint on database open - #64532
Conversation
A background service registers as soon as it listens and opens the database afterwards, so a synchronous checkpoint of a large WAL on a slow disk keeps /api/info from answering right after registration. SQLite already runs the same passive checkpoint after a commit once the WAL passes wal_autocheckpoint.
There was a problem hiding this comment.
The gate works as described. I ran opencode serve from source with another connection holding committed WAL frames. On the base and on this PR with OPENCODE_FLAGS=-skip_startup_checkpoint, the main DB file grew on open (checkpointed). On this PR with the local channel's default it didn't. database.test.ts and flag.test.ts pass, and typecheck:tsc in core is clean.
Public API: adds the skip_startup_checkpoint flag. It can be set with OPENCODE_FLAGS, and the regenerated config schema, OpenAPI spec and client types gain an experimental.skip_startup_checkpoint key, which is ignored at runtime as the flag description says. Backwards compatible; releases still checkpoint by default.
No blocking concerns.
Related: #54810
This reverts commit 930ee6e.
There was a problem hiding this comment.
The new head removes the startup checkpoint outright, with no flag. I re-ran my WAL check with opencode serve from source: the main DB file no longer grows on open, where on the base it does. The database* and storage-failure tests pass and typecheck:tsc in core is clean. There are no open threads from my earlier review. The public API is unchanged: the flag, its config key and the regenerated OpenAPI/client types are gone again.
One note, not blocking: a large WAL left behind is now checkpointed by SQLite's auto-checkpoint after the first commit that leaves it over the limit, which can come soon after boot and still runs on the event loop. On a slow disk the stall may just move to the first write after boot. The description already says the work moves; this only makes that concrete.
(cherry picked from commit fc30827)
Issue for this PR
N/A. Split out of #63729.
Type of change
What does this PR do?
Removes the
PRAGMA wal_checkpoint(PASSIVE)that runs when the database opens.A background service registers as soon as it listens and opens the database afterwards (
packages/server/src/process.ts). The checkpoint runs synchronously on the event loop, so with a large WAL on a slow disk/api/infostops answering right after registration and clients count the booting service as unresponsive. #54810 has a 300 MB WAL on an HDD.This moves the work rather than removing it: SQLite runs the same passive checkpoint after a commit once the WAL passes
wal_autocheckpoint(1000 pages by default, which we don't change). Opening the database and checking migrations still run on the event loop, so boot on a stalled disk can still block health probes.The checkpoint was added in #13633 to clean up stale WAL data after a kill mid-write and avoid
SQLITE_MISUSE. SQLite recovers the WAL on open by itself and ignores frames from transactions that never committed, so I don't expect that to come back, but I haven't reproduced the original error. That's why this is a draft.No feature flag: it removes one statement from database startup.
How did you verify your code works?
packages/core:bun typecheck, anddatabase.test.ts,database-drizzle.test.ts,database-migration.test.ts,storage-failure.test.tson WindowsScreenshots / recordings
N/A
Checklist
Added by the opencode bot (AI-generated).
Related: #54810
Public API: adds the skip_startup_checkpoint flag (OPENCODE_FLAGS; experimental.skip_startup_checkpoint config key is generated but ignored), backwards compatible