Skip to content

Add internal onRollbackCommit callback API for rollback events#1283

Merged
DZakh merged 3 commits into
mainfrom
claude/sharp-curie-cbvOp
Jun 4, 2026
Merged

Add internal onRollbackCommit callback API for rollback events#1283
DZakh merged 3 commits into
mainfrom
claude/sharp-curie-cbvOp

Conversation

@DZakh
Copy link
Copy Markdown
Member

@DZakh DZakh commented Jun 4, 2026

Summary

Adds an internal, unstable ~internalAndWillBeRemovedSoon_onRollbackCommit API that allows indexers to register callbacks fired once per chain affected by a reorg rollback, after the rollback is durably written to the database.

Key Changes

  • New RollbackCommit module (packages/envio/src/RollbackCommit.res): Manages callback registration and firing for rollback commit events. Callbacks receive the chain ID and the last valid block number for that chain.

  • Integration in InMemoryStore: After a rollback diff is durably written, RollbackCommit.fire is invoked with the progress block numbers per chain. Throwing callbacks bubble to the write loop's error handler, crashing the indexer like a failed write.

  • Registration in Main: Exposes onRollbackCommitFn as a property on the indexer object, allowing users to register callbacks during the configuration phase. The method name is marked as internal and will be removed without notice.

  • Type definitions: Updated index.d.ts to include the callback signature in the IndexerFromConfig type.

  • Persistence layer: Extended the rollback type to carry progressBlockNumberByChainId, which is populated during rollback preparation in GlobalState and read by the callback firing logic.

  • Test coverage: Added test verifying that the callback fires once per affected chain with correct arguments after a rollback write.

Implementation Details

  • Callbacks are stored in a module-level array and can be unregistered via a returned function.
  • The progressBlockNumberByChainId dict is threaded through the rollback preparation pipeline to ensure the callback has access to the last valid block per chain.
  • The feature is intentionally marked as temporary and internal; all three call sites (module definition, registration, and firing) should be deleted together when the API is removed.

https://claude.ai/code/session_01E1JiTmZ9APfXhzDvjEVgX7

Summary by CodeRabbit

  • New Features

    • Added temporary internal API method to register callbacks for rollback completion events, with chainId and rollbackToBlock information provided to each callback.
  • Tests

    • Added test coverage for rollback callback registration and execution.

claude added 2 commits June 4, 2026 11:21
Add `indexer.~internalAndWillBeRemovedSoon_onRollbackCommit`, an unstable
internal hook fired once per chain affected by a reorg rollback, after the
rollback diff is durably written. A throwing callback bubbles to the write
loop's onError, crashing the indexer like a failed write.

The whole feature is concentrated in RollbackCommit.res plus three call
sites (registration in Main, per-chain block snapshot in GlobalState, fire
on a successful rollback write in InMemoryStore) so it can be removed in one
piece.

https://claude.ai/code/session_01E1JiTmZ9APfXhzDvjEVgX7
Carry per-chain last-valid blocks on `Persistence.rollback` instead of a
global pending ref, and guard the fire on a registered callback so an empty
registry doesn't schedule an extra microtask.

https://claude.ai/code/session_01E1JiTmZ9APfXhzDvjEVgX7
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 4, 2026

Review Change Stack

Caution

Review failed

The head commit changed during the review from 74bbb3a to 63741bb.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

Comment @coderabbitai help to get the list of available commands and usage tips.

@DZakh DZakh enabled auto-merge (squash) June 4, 2026 11:45
@DZakh DZakh merged commit 8b446eb into main Jun 4, 2026
7 of 8 checks passed
@DZakh DZakh deleted the claude/sharp-curie-cbvOp branch June 4, 2026 11:50
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 4, 2026

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: f2681f15-7d56-4d1c-8f40-6db543940e71

📥 Commits

Reviewing files that changed from the base of the PR and between a6add8a and 74bbb3a.

📒 Files selected for processing (7)
  • packages/envio/index.d.ts
  • packages/envio/src/GlobalState.res
  • packages/envio/src/InMemoryStore.res
  • packages/envio/src/Main.res
  • packages/envio/src/Persistence.res
  • packages/envio/src/RollbackCommit.res
  • scenarios/test_codegen/test/rollback/Rollback_test.res
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

Comment @coderabbitai help to get the list of available commands and usage tips.

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