fix: prevent SQLite corruption by checkpointing WAL and closing DB on shutdown

The database was never properly closed on SIGINT/SIGTERM — WAL files were left
in a partially-written state causing "database disk image is malformed" errors.
Adds WAL checkpoint on close, synchronous=NORMAL pragma, SIGTERM handlers, and
a store.close() method that flushes all pending writes before exit.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
gsxdsm
2026-03-31 23:15:30 -07:00
parent fc37015f79
commit fa9b277c32
4 changed files with 55 additions and 5 deletions

View File

@@ -1693,6 +1693,18 @@ export class TaskStore extends EventEmitter<TaskStoreEvents> {
this.recentlyWritten.clear();
}
/**
* Gracefully shut down: stop watching and close the database connection.
* Ensures WAL is checkpointed so no pending writes are lost.
*/
close(): void {
this.stopWatching();
if (this._db) {
this._db.close();
this._db = null;
}
}
/**
* Mark a file path as recently written by an in-process mutation
* so the watcher will skip it.