fix(core-manager): delete the head record when purging a core - #1307
Merged
Conversation
… mode purgeCore deletes all tree nodes and blocks but leaves the core's head record (fork, length, root hash) in storage. When the same storage is re-opened - as happens when a device re-joins a project after leaving, which re-adds the same core keys - hypercore finds a header claiming length > 0 with no merkle roots and puts the core in repair mode: the replicator becomes push-only and never sends a Synchronize, so the core silently never syncs for the rest of the session. Peers waiting on that core's handshake wait forever. The new test purges a downloaded core, re-opens the same storage, and asserts a block can be re-downloaded. It times out on the current implementation.
purgeCore deletes all tree nodes and blocks but left the core's head record (fork, length, root hash) in storage. When the same storage was re-opened - a device re-joining a project after leaving re-adds the same core keys - hypercore found a header claiming length > 0 with no merkle roots and put the core in repair mode: push-only, never sending a Synchronize, so the core silently never synced for the rest of the session, and peers gating on its handshake waited forever. Delete the head record too, so a purged core re-opens as a normal empty core and re-syncs from peers.
RangerMauve
approved these changes
Jul 16, 2026
RangerMauve
merged commit Jul 16, 2026
3a001e4
into
feat/hypercore11-migration
16 of 17 checks passed
RangerMauve
pushed a commit
that referenced
this pull request
Jul 20, 2026
* test(core-manager): failing test for purged cores reopening in repair mode purgeCore deletes all tree nodes and blocks but leaves the core's head record (fork, length, root hash) in storage. When the same storage is re-opened - as happens when a device re-joins a project after leaving, which re-adds the same core keys - hypercore finds a header claiming length > 0 with no merkle roots and puts the core in repair mode: the replicator becomes push-only and never sends a Synchronize, so the core silently never syncs for the rest of the session. Peers waiting on that core's handshake wait forever. The new test purges a downloaded core, re-opens the same storage, and asserts a block can be re-downloaded. It times out on the current implementation. * fix(core-manager): delete the head record when purging a core purgeCore deletes all tree nodes and blocks but left the core's head record (fork, length, root hash) in storage. When the same storage was re-opened - a device re-joining a project after leaving re-adds the same core keys - hypercore found a header claiming length > 0 with no merkle roots and put the core in repair mode: push-only, never sending a Synchronize, so the core silently never synced for the rest of the session, and peers gating on its handshake waited forever. Delete the head record too, so a purged core re-opens as a normal empty core and re-syncs from peers.
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.
purgeCore()deletes all tree nodes and blocks but leaves the core's head record (fork, length, root hash) in storage. When the same storage is re-opened — a device re-joining a project after leaving re-adds the same core keys — hypercore finds a header claiminglength > 0with no merkle roots and puts the core in repair mode (core.js:_repairMode = !roots.length && length && !overwrite). In repair mode the replicator is push-only and never sends a Synchronize, so the core silently never syncs for the rest of the session, and peers waiting on that core's handshake wait forever.This has been broken since purgeCore was introduced, but was masked by the old
core.update()-based peer status, which reported peers as started without hearing from them. The stricter per-peer handshake gate in #1306 exposed it: the remove-member/re-add e2e tests only passed there because of the 5s fallback timer, and each affected sync silently ate the full fallback delay.The fix is to also delete the head record in the purge transaction, so a purged core re-opens as a normal empty core and re-syncs from peers.
The first commit adds only the regression test (purge a downloaded core, re-open the same storage, assert a block can be re-downloaded) so its CI run records the failure; the second commit is the fix. With the fix, the previously-hanging e2e tests pass in about 2 seconds even with the #1306 fallback disabled entirely, which means that fallback can be removed in a follow-up.