fix(kanban): content-addressed corrupt-DB backup filename (refs #33529) - #33804
Merged
Conversation
Repeated quarantines of an unchanged corrupt kanban.db used to amplify disk usage by N: the gateway dispatcher's 5-minute retry loop, multi- profile fleets sharing one DB, and manual reopen attempts each produced a fresh '.corrupt.<timestamp>.bak' copy of the same bytes. After 10 retries on a 100KB DB you had 11x the disk footprint of duplicate corrupt data. Derive the backup filename from a sha256 of the main DB instead of a timestamp + collision counter. Same bytes → same filename → skip the copy on retries. Different bytes (partial repair, further damage) → different filename → preserve separately. Sidecar (-wal/-shm) backups inherit the same content-addressed name. Inspired by @hanzckernel's PR #33529, simplified down to ~30 LOC: drop the persistent JSON marker file, drop the atomic temp+fsync+rename helper (shutil.copy2 is fine for a quarantine-only path), drop the gateway-side WAL/SHM fingerprint extension (the existing (path, mtime, size) tuple still gives the 5-minute retry semantics it needs), and drop the gateway-side helper extraction. The backup file existing IS the marker; no separate state needed. Test: tests/hermes_cli/test_kanban_db.py::test_repeated_corrupt_open_reuses_single_backup proves 10 retries on the same corrupt bytes produce 1 backup (was 11), and mutating the corrupt bytes produces a second backup with a different fingerprint. Refs #33529 Co-authored-by: hanzckernel <zhicheng.han@mathematik.uni-goettingen.de>
Contributor
🔎 Lint report:
|
19 tasks
This was referenced May 28, 2026
Closed
Closed
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.
Salvages the conceptual approach from PR #33529 (@hanzckernel) — content-addressed backup filename — at ~10% the LOC.
Summary
_backup_corrupt_db()used a timestamp + collision counter for the backup filename. Each retry on an unchanged corrupt kanban.db produced a new.corrupt.<timestamp>.bakcopy of the same bytes. After 10 retry cycles (gateway dispatcher's 5-minute quarantine timer, multi-profile fleets sharing one DB, manual reopen attempts) you had 11x the disk footprint of duplicate corrupt data.This PR makes the backup filename deterministic in a sha256 of the main DB. Same bytes → same filename →
if not path.exists(): copyskips the work on retries. Different bytes (partial repair, further damage) → different fingerprint → second backup preserved.Live verification
10 retries on the same corrupt DB (100KB):
Tests: 449/449 kanban tests pass (test_kanban_db.py + test_kanban_core_functionality.py + test_kanban_tools.py). New regression test
test_repeated_corrupt_open_reuses_single_backupasserts the invariant directly + verifies mutated corrupt bytes still get a separate backup.Why simpler than #33529
@hanzckernel's PR weighed in at +670/-70 across 5 files. This is +66/-21 across 2 files. Dropped without losing the bug fix:
.corrupt-quarantine.jsonmarker file. Pure metadata. The deterministic backup file existing IS the marker — same property (idempotent retry), no separate state machine to maintain or clear.os.replacecopy helper.shutil.copy2is fine for a quarantine-only path. We're copying a known-broken DB; durability of the backup beats best-effort by no meaningful margin._pause_corrupt_board/_board_disabled_same_fingerprinthelper extraction. DRY-only refactor in the original PR. Useful but orthogonal to the bug being fixed. Existing inline code paths in gateway/run.py already work.(path, mtime, size)tuple still gives the 5-minute retry semantics it needs.The PR description for #33529 covers other issues (#30445, #31736) that the cluster sweep just closed via the WAL-init / connect_closing / quarantine-retry / torn-write defenses landed earlier this week. Those issues are resolved; the residual concern this PR addresses is purely the backup-file disk amplification on the retry path.
Credit
Infographic