fix(dag): clearCanonicalState wipes all canonical tables (closes post-snapshot Merkle divergence)#72
Merged
Conversation
vrkothekar
approved these changes
Jun 4, 2026
vrkothekar
left a comment
Collaborator
There was a problem hiding this comment.
Review: APPROVED ✅
Reviewed against AUDIT_CROSSREF_2026-06-03.md finding C-1. Fix is correct and complete.
Verified locally
- All 5 new regression tests pass (
clear-canonical-state.test.js) - 209 existing tests pass — zero regressions
- Full
iterateCanonicalStatecross-checked: all 12 yielded tables are now cleared across all 3 store implementations (MemoryStore, SQLiteStore, KnexAdapter) state_merkle_rootidentity test (test 5) proves no canonical row survives clear regardless of seed history — directly closes the consensus-halt-after-snapshot-install bug
Non-blocking note addressed
The stale comment "Wipe the 7 canonical-state tables" in snapshot-handler.js:860 has been updated in this branch (pushed as 3533e81) — count removed, now reads "Wipe all canonical-state tables".
Scope
Correctly scoped to C-1 only. Remaining audit items (C-2, C-3, C-4, C-6, C-8–C-12) to follow as separate PRs on this branch as described.
Ready to merge.
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.
Summary
Fixes audit finding C-1 from
my-notes/audit-report.md(2026-06-03).clearCanonicalStatewas missing 3 tables in all three store implementations (MemoryStore, SQLiteStore, KnexAdapter). The missing tables —domain_bindings,prescan_reviews,interests_registry— are yielded byiterateCanonicalStateand therefore contribute tostate_merkle_root. Any node that had ever processedBIND_DOMAIN,PRESCAN_REVIEW_TRIGGERED, orINTEREST_REGISTEREDwould compute a different merkle root than a fresh snapshot author after install → permanent consensus halt with no recovery path.What changed
node/src/dag.jsMemoryStore.clearCanonicalState— clears_domainBindings,_prescanReviews,_interestsRegistrynode/src/dag.jsSQLiteStore.clearCanonicalState— adds 3DELETE FROMinside the existingdb.transaction()blocknode/src/db/knex-adapter.jsKnexAdapter.clearCanonicalState— adds 3.delete()to the existingPromise.all([...])flushnode/tests/dag/clear-canonical-state.test.js(5 tests)Why this slipped through
The 3 tables were added to
iterateCanonicalStatewhen their features landed, butclearCanonicalStatewas never updated in lockstep. There was no regression test asserting the two stay in sync. This PR adds one.Test plan
node/tests/dag/clear-canonical-state.test.js(5 tests, all green):clearCanonicalState,iterateCanonicalStateyields zero rowsdomain_bindingsis cleared (was missed pre-fix)prescan_reviewsis cleared (was missed pre-fix)interests_registryis cleared (was missed pre-fix)state_merkle_rootafter clear — proves zero canonical state survives, which directly closes the consensus-halt-after-snapshot-install bugBackwards compatibility
None required — the fix is local to each store's clear path. Already-running federations are unaffected (the bug only fires during a snapshot install, which is rare; this fix just ensures it stops being silent when it does).
Pairs with
my-notes/audit-report.md