fix(ocap-kernel): regenerate incarnationId on resetStorage=true#950
Merged
Conversation
The peer-restart detection added in #948 only works if the sender signals a new incarnation after a state wipe. The previous except-list in Kernel.#resetKernelState kept `incarnationId` alive across `resetStorage=true`, so a kernel-worker rebooted with the same incarnation as before — the receiver's persisted comparison decided "no restart," `highestReceivedSeq` stayed put, and fresh `seq=1` messages were dropped as duplicates. The browser kernel-worker hits this path on every offscreen-page reload (the URL carries `?reset-storage=true`), so every extension reload that re-registered a service silently dropped its first message. Dropping `incarnationId` from the except-list lets `provideIncarnationId` regenerate it, which is what the doc comment on that function already advertised. Adds an e2e regression covering the resetStorage path specifically (the existing #944 test goes through fresh-DB, which exercises a different code branch and didn't catch the bug). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Contributor
Coverage Report
File Coverage
|
||||||||||||||||||||||||||||||||||||||
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
Why
The peer-restart detection added in #948 only works if the sender signals a new incarnation when its state has been wiped. The except-list in `#resetKernelState` was preserving `incarnationId` across `resetStorage=true` resets, so the sender came back signalling the same incarnation, the receiver's handshake said "no restart", `highestReceivedSeq` stayed put, and the sender's fresh `seq=1` messages were dropped as duplicates.
The browser/extension kernel-worker URL carries `?reset-storage=true` and hits this branch on every offscreen-page reload, so in production this meant every plugin reload that re-registered a service silently lost its first message. Repro on metamask-extension chip/agentmask: full reset → first reload registers cleanly → second reload's PMS `registerServiceByRef` arrives at the matcher with seq=1, matcher logs `12D3KooW:: ignoring duplicate message seq=1 (highestReceived=4)` and the message disappears.
Confirmed empirically by dumping the matcher's KV after the second-reload symptom: `peerIncarnation.` was equal to the incarnation the extension was currently sending — exactly the case `#handleIncarnationChange` exits early on. The `provideIncarnationId` doc comment already advertised the post-fix behaviour ("regenerated when storage is cleared (when state is actually lost)"); the code just wasn't doing it.
Test plan
🤖 Generated with Claude Code
Note
Medium Risk
Changes how
resetStorage=trueresets persistent kernel state, which affects remote-communication handshake/dedup behavior across restarts; mistakes could cause message loss or unexpected peer identity changes.Overview
Fixes the
resetStorage=truereset path to regenerateincarnationIdwhile still preserving network identity keys (keySeed,peerId,ocapURLKey), so peers can reliably detect a state wipe and clear stale seq-dedup/c-list state.Adds an e2e regression test covering the browser/extension-style restart where the sender keeps the same DB file but starts with
resetStorage=true, ensuringseq=1messages are no longer silently dropped after reloads, and documents the fix in theCHANGELOG.Reviewed by Cursor Bugbot for commit c5cb8ea. Bugbot is set up for automated code reviews on this repo. Configure here.