Skip to content

[#898] Detect and recover indexer gaps and reorgs - #910

Merged
greatest0fallt1me merged 1 commit into
Predictify-org:mainfrom
Baskarayelu:feat/issue-898-indexer-recovery
Aug 27, 2026
Merged

[#898] Detect and recover indexer gaps and reorgs#910
greatest0fallt1me merged 1 commit into
Predictify-org:mainfrom
Baskarayelu:feat/issue-898-indexer-recovery

Conversation

@Baskarayelu

Copy link
Copy Markdown

Summary

Make indexer recovery explicit and safe for missing ledger ranges, at-least-once RPC delivery, worker restarts, and chain reorgs.

What changed

  • Added deterministic event/position identities and replay planning primitives.
  • Added contiguous checkpoint decisions that refuse to cross unobserved ledgers and produce bounded replay ranges.
  • Deduplicated replay batches before persistence and added a database uniqueness constraint for event identity.
  • Added canonical event tracking and reorg records when a new transaction replaces the canonical event at the same ledger/operation position.
  • Reset stale prediction confirmation state tied to a replaced transaction so the confirmer can rebuild from the replacement event.
  • Fixed event persistence to use the declared data column and a safe fallback event type.
  • Added migration cleanup for legacy duplicate event rows before creating the unique identity index.
  • Added 33 regression tests covering gap detection, tail gaps, replay chunking, exact redelivery, restart reapplication, reorg replacement, stale-state repair, malformed input, and cursor monotonicity.

Acceptance criteria

  • Gaps are detected before advancing the checkpoint — explicit observations and IndexerRecoveryPlanner block missing ranges.
  • Replay is idempotent — stable event identity, batch dedupe, and ON CONFLICT DO NOTHING.
  • Reorged events cannot leave stale settlement state — old events become non-canonical, reorgs are recorded, and linked predictions return to pending confirmation.
  • Integration-style recovery tests cover gap, replay, restart, and recovery paths.

Validation

  • npm test -- --runInBand --forceExit tests/indexerRecovery.test.ts tests/indexerService.test.ts tests/indexerService.recovery.test.ts
  • npx tsc --noEmit ... on the recovery and indexer service modules

The repository-wide TypeScript build still reports unrelated pre-existing errors in other routes/services.

Failure-mode considerations

Replay is chunked to bound RPC work, exact redelivery cannot increment stored rows, stale workers cannot be treated as canonical through the database identity boundary, and prediction confirmation state is reset when its source transaction is replaced.

Closes #898

@greatest0fallt1me
greatest0fallt1me merged commit 8bc12c4 into Predictify-org:main Aug 27, 2026
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.

[GrantFox][High] Detect and recover indexer gaps and reorgs

2 participants