mirror of
https://github.com/DeusData/codebase-memory-mcp.git
synced 2026-11-11 09:25:35 +08:00
cbm_store_begin_bulk() was switching the SQLite journal mode from WAL to MEMORY for write throughput. If the process crashed mid-bulk-write the in-memory rollback journal was lost, leaving the database file in a partially-written, unrecoverable state. WAL mode is inherently crash-safe: uncommitted WAL entries are discarded on the next open. The performance benefit of bulk mode is preserved via synchronous=OFF and an enlarged cache_size, both of which are safe under WAL. Remove the PRAGMA journal_mode = MEMORY from cbm_store_begin_bulk and the matching PRAGMA journal_mode = WAL from cbm_store_end_bulk. Update the header comments to reflect the new invariant. Add tests/test_store_bulk.c with three tests: - bulk_pragma_wal_invariant: asserts journal_mode remains "wal" after cbm_store_begin_bulk via an independent read-only connection - bulk_pragma_end_wal_invariant: asserts journal_mode remains "wal" after cbm_store_end_bulk - bulk_crash_recovery: forks a child that enters bulk mode, opens an explicit transaction, writes data, then calls _exit() without committing; the parent verifies the database opens cleanly and baseline data survives Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>