Skip to content

fix(api): report a stalled indexer when there is no finality data - #133

Merged
v1rtl merged 2 commits into
stagingfrom
fix/coverage-stale-without-finality
Sep 29, 2026
Merged

v1rtl merged 2 commits into
stagingfrom
fix/coverage-stale-without-finality

Conversation

@v1rtl

@v1rtl v1rtl commented Sep 28, 2026 •

Copy link
Copy Markdown
Collaborator

stale on /ready, /coverage and _coverage came only from the safe-head comparison, and it answered false whenever finality data was absent. A deployment without finality therefore looked healthy however far behind it fell. graphql.ens.dev has no finality data (_finality.safe is null) and sat ~40h behind Sepolia while reporting stale: false.

Change

COVERAGE_STALE_AFTER_SECONDS adds a fallback for when there is no safe position. It is opt-in: the code default is 0 (off), and the shipped compose files set 3600.

With the fallback on, a deployment is stale when either:

  • any protocol it indexes has gone longer than the threshold without committing a batch, or
  • nothing has synced at all.

When finality data exists, it still decides on its own.

Every surface now calls one shared function, api/common.coverageStale: /ready, /coverage, _coverage, and a new /metrics gauge.

What changed since the first review

  • Never-synced reads stale. An API pointed at a database whose indexer never started used to report stale:false forever; with the fallback on it now reads stale.
  • A live protocol no longer masks a dead one. The check used max(v1, v2); it now flags any protocol with a sync_state row that has gone past the threshold. A protocol this deployment doesn't index has no row and is ignored, so the V2-only graphql.ens.dev (V1 lastSyncedAt: null) is unaffected.
  • Off by default. Healthy bulk-sync batches have taken 10–44 min. --backfill writes no last_synced_at, and END_BLOCK-pinned boxes stop writing, so a 900s default flagged healthy deployments. Operators now opt in:
    • The compose files set ${COVERAGE_STALE_AFTER_SECONDS:-3600}, above the worst recorded batch.
    • .env.example says to set 0 during a backfill or on a pinned box.
  • Clock skew. A last_synced_at ahead of the API clock reads as age 0 and logs a warning once per process. The subtraction saturates on hostile DB values.
  • Parsing. off/false/no disable the fallback. Any other non-integer (e.g. 1h) is logged instead of silently becoming a threshold; previously off silently meant 900.
  • /metrics.
    • ensv2_indexing_stale keeps its _finality.isStale meaning (1 whenever there is no safe data), so existing alerts don't change.
    • New ensv2_coverage_stale mirrors /coverage.
    • Both are documented on writeFinalityGauges.
  • Docs. The stale doc comment on handleCoverage is fixed, and the schema descriptions describe opt-in behaviour.

Tests

  • isStale/coverageStale cover:
    • boundaries at 899, 900 and 901
    • the per-protocol OR
    • never-synced
    • a future timestamp
    • overflow
  • New end-to-end coverage of the plumbing:
    • the pool arms every session with the threshold
    • config parsing (default, off spellings, junk)
    • _coverage.stale through the real handler: off, never synced, fresh, one dead protocol, and finality overriding both ways

Out of scope (follow-up)

With finality enabled, a dead indexer still reports stale:false, because finality freezes along with it. The same gap exists in _finality.isStale.

zig build test-all: 89/89 steps, 1493/1493 tests (zig 0.16.0). The Postgres lanes were not run locally; CI covers them. The postgres driver test literal carries both rpc_rate_limit_per_second and coverage_stale_after_seconds.

stale on /ready, /coverage and _coverage came only from the safe-head
comparison and answered false whenever finality data was absent, so a
deployment without FINALITY_ENABLED looked healthy however far behind it
fell. graphql.ens.dev sat ~40h behind Sepolia reporting stale:false.

COVERAGE_STALE_AFTER_SECONDS (opt-in, default 0) adds a fallback when
there is no safe position: stale when any indexed protocol has gone
longer than the threshold without committing a batch, or when nothing
has synced at all. Finality data still decides on its own when present.

- One live protocol no longer masks a dead one: the fold is an OR over
  protocols with a sync_state row, not max(last_synced_at).
- Never-synced reads stale once armed instead of healthy forever.
- A timestamp ahead of the API clock reads as age 0 and warns once per
  process; the subtraction saturates on hostile DB values.
- Off by default: healthy bulk-sync batches have taken 10-44 min, and
  --backfill and END_BLOCK-pinned deployments never advance the head.
- off/false/no parse as disabled; any other non-integer is logged
  instead of silently becoming a threshold.
- /ready, /coverage, _coverage and /metrics share coverageStale. The
  existing ensv2_indexing_stale gauge keeps its _finality.isStale
  meaning; the new ensv2_coverage_stale gauge mirrors /coverage.
The code default stays off. The deployments we run opt in at 3600s,
above the longest healthy batch on record, overridable per host.
@v1rtl
v1rtl force-pushed the fix/coverage-stale-without-finality branch from 77c4327 to 0202bc6 Compare September 29, 2026 13:56
@v1rtl v1rtl changed the title fix(api): detect a stalled indexer when there is no finality data fix(api): report a stalled indexer when there is no finality data Sep 29, 2026
@v1rtl
v1rtl merged commit b760e51 into staging Sep 29, 2026
4 checks passed
@v1rtl
v1rtl deleted the fix/coverage-stale-without-finality branch September 29, 2026 14:59
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.

1 participant