mirror of
https://github.com/DeusData/codebase-memory-mcp.git
synced 2026-10-28 07:03:20 +08:00
Architecture change to prevent concurrent write corruption: Indexing (new project): cbm_write_db writes project.db directly Reindexing (existing): delete project.db, then index as new Incremental: upsert changes into existing project.db (unchanged) Root cause: rename(project.db.tmp, project.db) while watcher/MCP had the old file open via SQLite caused WAL corruption — stale connections wrote to deleted inodes. Changes: - cbm_gbuf_dump_to_sqlite: write to final path, no .tmp + rename - pipeline.c: if DB exists but not eligible for incremental, delete it before proceeding with full index (reindex = delete + index) - Pipeline lock (atomic spinlock) serializes concurrent runs: MCP/autoindex block, watcher skips if busy - delete_project acquires pipeline lock before unlinking - BEGIN IMMEDIATE for all write transactions (respects busy_timeout) - cbm_store_check_integrity: detects corrupt DBs (>5 project rows or invalid root_path), auto-deletes with ERROR log - cbm_store_get_db accessor for test corruption simulation Tests: 5 integrity tests + 4 concurrency lock tests