Skip to content

fix(reference-index): keep transient sync failures retryable - #149

Merged
panos-xyz merged 1 commit into
mainfrom
fix/reference-index-transient-phase
Aug 5, 2026
Merged

panos-xyz merged 1 commit into
mainfrom
fix/reference-index-transient-phase

Conversation

@panos-xyz

@panos-xyz panos-xyz commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor

Problem

synchronize_once latched the runtime phase to Unavailable on every error:

if result.is_err() {
    self.handle.metrics().failures_total.increment(1);
    self.handle.set_phase(ReferenceIndexPhase::Unavailable);
}

Meanwhile run (runtime.rs:393-403) classifies errors with
requires_manual_rebuild() and retries everything else with exponential backoff
(1s up to 30s). The two sites used different criteria for the same question,
so a transient failure — a provider read error, a short canonical batch, an MDBX
hiccup — gated the read path even though catch-up was still in progress and
would succeed on the next turn.

The read path makes this visible: query_at short-circuits on Unavailable
(reader.rs:157) before any cursor comparison. During the backoff window,
queries therefore returned IndexUnavailable — which tells clients to stop
retrying — even when the durable cursor already matched the canonical tip and
the answer was fully servable. The RPC handler compounds it: IndexUnavailable
takes the Err(other) => return path (handler.rs:237) and so bypasses the
bounded server-side catch-up wait that IndexBehind is granted.

Fix

Gate the phase on the same predicate run already uses, so only unrecoverable
errors reach Unavailable:

  • CorruptMetadata
  • ChainIdentityMismatch
  • SchemaMismatch
  • ManualRebuildRequired

Transient errors leave the phase where the turn left it, letting the
cursor-vs-tip comparison surface IndexBehind — the retryable signal — on its
own.

Leaving the phase untouched is safe on every path: stopped at Live with a
matching cursor the data is genuinely valid and serves; a lagging cursor yields
IndexBehind; a first-time open_db failure keeps Opening with no installed
DB, which yields Initializing.

The Unavailable set in run when the blocking task dies unexpectedly
(runtime.rs:370) is unchanged — that path returns without further retries, so
the gate is correct there.

Impact

No correctness change. The index never served stale rows in either case, and
Unavailable was already non-sticky (set_phase clears the unavailable flag
on the next successful turn). This only removes a false-negative window where a
servable index refused queries and told clients not to come back.

Tests

  • incomplete_provider_batch_does_not_advance_the_cursor — updated to assert the
    phase is not polluted to Unavailable by a transient short batch; the cursor
    assertion is unchanged.
  • transient_failure_leaves_queries_retryable — new; asserts the read path
    answers IndexBehind rather than IndexUnavailable after a transient failure.
  • reorg_reaching_below_finalized_is_bounded_to_a_manual_rebuild and
    reorg_without_a_post_jade_ancestor_requires_a_manual_rebuild — unchanged, and
    now serve as regression protection for the unrecoverable branch.
cargo nextest run -p morph-reference-index   # 40 passed
cargo fmt --all -- --check                   # clean
cargo clippy -p morph-reference-index --all-targets -- -D warnings   # clean

Summary by CodeRabbit

  • Bug Fixes
    • Improved index availability during temporary synchronization failures.
    • Queries now report that the index is behind when updates are delayed, rather than incorrectly marking it unavailable.
    • Indexes are marked unavailable only when recovery requires a manual rebuild.
    • Incomplete provider batches now remain in the backfill phase for retry handling.

`synchronize_once` latched the runtime phase to `Unavailable` on every
error, while `run` classifies errors with `requires_manual_rebuild` and
retries everything else with backoff. The two used different criteria, so
a transient failure (provider read, short canonical batch, MDBX hiccup)
gated the read path even though catch-up was still in progress.

`query_at` short-circuits on `Unavailable` before any cursor comparison,
so during the backoff window (1s up to 30s) queries returned
`IndexUnavailable` — which tells clients to stop retrying — even when the
durable cursor already matched the canonical tip and the answer was
servable. The RPC handler compounds this: `IndexUnavailable` bypasses the
bounded server-side catch-up wait that `IndexBehind` is granted.

Gate the phase on `requires_manual_rebuild` so only unrecoverable errors
(corrupt metadata, chain identity or schema mismatch, missing post-Jade
ancestor) reach `Unavailable`. Transient errors leave the phase where the
turn left it, letting the cursor-vs-tip comparison surface `IndexBehind`.

No correctness change: the index never served stale rows in either case,
and `Unavailable` was already cleared by the next successful turn.

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

Claude Code Review is paused for this repository. To reconnect it, an admin of this repository's GitHub organization (or the account owner, for personal repositories) who can also manage your Claude organization's Code Review settings needs to re-link GitHub in Code Review settings. This is a one-time step.

Tip: disable this comment in your organization's Code Review settings.

@coderabbitai

coderabbitai Bot commented Aug 5, 2026 •

Copy link
Copy Markdown

Review Change Stack

Note

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

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 0023c8aa-a689-4f62-a46f-3010fae642c8

📥 Commits

Reviewing files that changed from the base of the PR and between e2642c4 and 19e3d8b.

📒 Files selected for processing (1)
  • crates/reference-index/src/runtime.rs
 __________________
< I see dead code. >
 ------------------
  \
   \   \
        \ /\
        ( )
      .( o ).
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/reference-index-transient-phase

Warning

Billing warning: we have not been able to collect payment for this subscription for more than 72 hours. Please update the payment method or pay any pending invoices in Billing to avoid service interruption.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@panos-xyz
panos-xyz requested a review from dylanCai9 August 5, 2026 07:21
@panos-xyz
panos-xyz merged commit fff94fe into main Aug 5, 2026
13 checks passed
@panos-xyz
panos-xyz deleted the fix/reference-index-transient-phase branch August 5, 2026 10:08
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