Skip to content

fix(core-manager): delete the head record when purging a core - #1307

Merged
RangerMauve merged 2 commits into
feat/hypercore11-migrationfrom
fix/purge-repair-mode
Jul 16, 2026
Merged

fix(core-manager): delete the head record when purging a core#1307
RangerMauve merged 2 commits into
feat/hypercore11-migrationfrom
fix/purge-repair-mode

Conversation

@gmaclennan

Copy link
Copy Markdown
Member

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 claiming length > 0 with 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.

… 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
RangerMauve merged commit 3a001e4 into feat/hypercore11-migration Jul 16, 2026
16 of 17 checks passed
@RangerMauve
RangerMauve deleted the fix/purge-repair-mode branch July 16, 2026 16:54
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants