fix: verify source memory DB integrity before backing it up (#2895) - #3134
fix: verify source memory DB integrity before backing it up (#2895)#3134ruvnet wants to merge 1 commit into
Conversation
backupMemoryDb() never ran PRAGMA integrity_check on the SOURCE
.swarm/memory.db before snapshotting it, so a corrupt DB was copied
forward every night and reported as `{ backedUp: true }` — silently
rotating the last clean snapshot out of the retention window.
restoreMemoryDbFromBackup() already verified candidates on the way
out; this adds the matching check on the way in, in both the
online-backup and byte-copy-fallback success paths.
A corrupt (or unreadable) source is still backed up — a corrupt
snapshot beats none — but the file is tagged `*.CORRUPT.db` (still
matched by the existing `/^memory-.*\.db$/` rotation/restore glob,
so it stays discoverable but correctly fails its own integrity
check and is skipped by restore in favor of an older clean backup),
an unconditional console.warn is emitted, and the result now carries
`sourceIntegrity`/`sourceCorrupt` so callers such as
runBackupWorker() can surface it.
Co-Authored-By: RuFlo <ruv@ruv.net>
Claude-Session: https://claude.ai/code/session_01KpeUPeLwJtPC5USnJGukv9
|
CI red on this PR is not caused by this diff. Checked the job logs for the failing checks (e.g. "Audit root (critical-blocking)", "graph schema smoke", "memory stats legacy-DB smoke", "neural-trader feature/backtest smoke", "Plugin package install-safety", "plugin-registry signature verification smoke") — all of them fail at the same install step, before any test code runs: This is a pre-existing, repo-wide dependency-resolution failure — No fix ported: resolving it means either publishing Generated by Claude Code |
Fixes #2895.
backupMemoryDb()never ranPRAGMA integrity_checkon the SOURCE.swarm/memory.dbbefore snapshotting it, so a corrupt DB was copied forward every night and reported as a clean success, silently rotating the last good snapshot out of the retention window. This adds the same integrity checkrestoreMemoryDbFromBackup()already runs on the way out, to both the online-backup and byte-copy-fallback success paths inmemory-backup.ts: a corrupt/unreadable source is still backed up (a corrupt snapshot beats none), but the file is tagged*.CORRUPT.db(still matched by the existing rotation/restore glob, so it stays discoverable but correctly fails its own integrity check and is skipped by restore), an unconditionalconsole.warnis emitted, and the result now carriessourceIntegrity/sourceCorruptwhichrunBackupWorker()surfaces into its metrics. Opened by the nightly triage routine — human review required before merge.Generated by Claude Code