fix(store): checkpoint WAL on close and startup to prevent orphan accumulation#387
Open
jjserenity wants to merge 1 commit into
Open
fix(store): checkpoint WAL on close and startup to prevent orphan accumulation#387jjserenity wants to merge 1 commit into
jjserenity wants to merge 1 commit into
Conversation
…umulation Add WAL checkpoint on store close and after WAL-mode enable at startup. This ensures graceful shutdown leaves a clean WAL, and crash recovery merges stale WAL on next open. Both use PASSIVE mode (non-blocking, no ftruncate). Best-effort — silently skip if concurrent reader holds a lock. Fixes DeusData#277
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #277
Problem
codebase-memory-mcpprocesses can accumulate as orphan processes (e.g., from unclean stdio shutdown on Windows). Each orphan holds a SQLite WAL read lock, preventing checkpoint from ever landing. New index writes go to WAL but never merge into the main.db. The WAL grows unbounded, and queries return stale data.The existing
cbm_store_checkpoint()API uses safeSQLITE_CHECKPOINT_PASSIVEmode but is never called anywhere — zero call sites.Changes
Single file:
src/store/store.c(+10 lines)cbm_store_close(): Checkpoint WAL viasqlite3_wal_checkpoint_v2(..., PASSIVE)beforesqlite3_close_v2. This ensures graceful shutdown (SIGTERM,delete_project, normal exit) leaves a clean WAL that won't require recovery on next open.configure_pragmas(): AfterPRAGMA journal_mode=WAL, runPRAGMA wal_checkpoint(PASSIVE)to merge any stale WAL from a previous crash. Best-effort — silently skipped if another process holds a lock (SQLITE_BUSY).Rationale
ftruncate()s, compatible with PR fix(store): use PASSIVE checkpoint to avoid file-shrink under concurrent readers #316's existing choice.delete_project→ checkpoint runs insidecbm_store_closebefore file unlink, so WAL is merged before deletion.Tested
-Wall -Wextra -Werror)