fix(claims): let a reindex recover a claim skipped by a ResolveError - #75
Merged
Merged
Conversation
A claim skipped by a ResolveError could never come back through a reindex: the resolver searched above the table-wide max claim id, which by replay time sits above every claim being revisited, so the lookup threw again. Bound the watermark by created_block <= the action's block. Indexing live this is the same number as before; on replay it is where the watermark stood when the claim was first seen. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
The bug
When
resolveClaimIdfails,claimActionthrows aResolveError. Theledgeredwrapper then removes the action's_processed_actionsrow so that "a later reindex can pick it up". That reindex could never succeed. The watermark it searches above was the table-widemax(id). By the time anyone replays, that max sits above every claim in the replayed range, so the lookup starts above the skipped claim's id and throws again.This happened in prod. Claim 20045 (action 115, created 2026-08-16 at block 427000148) was on chain and missing from the DB for six weeks. The anomaly check only flagged it on 2026-09-27, after the deploy, when it ran again. It was fixed that day by a one-row SQL insert with every value copied from the chain, because a reindex could not bring it back.
The fix
The watermark is now the highest claim id recorded at or before the action's block:
The
chain.jscomment onafterIdis updated to match.Verified on a local chain
One action, three claims in separate blocks: bob (id 1), carol (id 2), then bob again on the same action (id 3), which exercises the gap case. All three indexed with DB id = chain id. Then I recreated the prod state: deleted claim 1 and its
_processed_actionsrow, which is what aResolveErrorleaves behind. Then a full replay:masterresolveClaimId: no chain claim for action 1 / bob above id 3, skipped againClaim 3 (same action and claimer, later block) was untouched, and no duplicate rows appeared.
npx standard src/passes. No deploy steps beyond the usual pull +pm2 restart event-source.🤖 Generated with Claude Code