Skip to content

feat(node): blacklist watcher health metrics (#1283) - #1315

Closed
yigitdot wants to merge 3 commits into
mainfrom
feat/1283-blacklist-watcher-health-metrics
Closed

yigitdot wants to merge 3 commits into
mainfrom
feat/1283-blacklist-watcher-health-metrics

Conversation

@yigitdot

Copy link
Copy Markdown
Contributor

Problem

The blacklist compliance watcher was the only one of the six LogSink watchers with no health observability. Its four metrics-wiring peers (slash / staker-set / capacity-bond / origin-directory) each wire on_established + on_backoff into the watcher_downtime_recorders! family; blacklist wired neither, and metrics.rs contained zero occurrences of "blacklist".

Since #1282 moved it off the runtime tasks JoinSet — whose shutdown-drain log_join_result surfaced task panics at warn! — onto a detached resumable_watcher::spawn / AbortOnDrop, a wedged or backing-off loop moved no metric at all. A dead blacklist loop means the node keeps serving content blacklisted after the failure, which is slashable (SlashJudge.submitBlacklistChallenge), with nothing in logs or metrics.

Change

Adds a fourth row to the watcher_downtime_recorders! family, giving blacklist the same recorders and the same decdn_blacklist_watcher_restarts_total / decdn_blacklist_watcher_down_seconds pair its peers have. No macro shape change was needed — the existing table accommodated the new row as-is.

One wiring difference from the peer sites, worth a look in review: blacklist's on_established / on_backoff hooks are already occupied by the one-shot InitialSyncGate readiness signal, and each hook slot holds a single WatcherHook. So the recorders are composed into the existing closures rather than added as separate .on_established(...) calls. This needed no change to the resumable_watcher hook signature. The gate's behavior is unchanged — it still fires exactly once — and the recorders run first so a runtime woken by the gate never observes a /metrics scrape that disagrees with the readiness it was just handed.

That composition is also the substance of the fix, not just plumbing: the gate is one-shot, so a loop that recovered and then wedged again — the realistic RPC-flap shape — was previously invisible. The recorders fire on every cycle transition.

spawn takes a new &Arc<Metrics> parameter; the single runtime call site passes &infra.node_metrics.

Tests

  • initial_head_failure_signals_startup_error — extended to assert the composed on_backoff counts one drift window. Verified this fails on main's wiring (temporarily un-wired the hook: assertion fails at the metric check, readiness signal still passes).
  • initial_clean_replay_signals_ready — extended to assert the gate still signals Ok and the cycle reports zero downtime / zero restarts. This is the regression guard for the composition, which is the main risk in this change.
  • repeated_drift_windows_each_count_once (new) — pins that one continuous outage counts one window, recovery clears the gauge, and a second outage counts a second window: the gap the one-shot gate structurally could not cover.

Verification

cargo clippy --workspace --all-targets -- -D warnings   # clean
cargo fmt -- --check                                    # clean
cargo nextest run -p decdn-node --no-fail-fast          # 866 passed, 0 skipped

Out of scope

The issue's optional "restore panic visibility for the detached task" paragraph is deliberately not implemented — no supervisor task here. Worth a follow-up issue if wanted: the detached JoinHandle is still never awaited, so a genuine Rust panic in the blacklist task is discarded silently. The downtime metrics narrow but do not close that: a panicked task stops firing on_established, so down_seconds stays frozen at its last value rather than climbing — it would not alert on a stuck-at-zero gauge.

Closes #1283

The blacklist compliance watcher was the only one of the six `LogSink`
watchers with no health observability. Since #1282 moved it off the
runtime `tasks` JoinSet onto a detached `resumable_watcher::spawn`, a
wedged or backing-off loop moved no metric at all — and a dead blacklist
loop means the node keeps serving content blacklisted after the failure,
which is slashable (`SlashJudge.submitBlacklistChallenge`).

Extends the `watcher_downtime_recorders!` family with a fourth row, so
blacklist gets the same `*_backoff_started` / `*_cycle_established`
recorders and the same `*_restarts_total` / `*_down_seconds` pair its
peers have. No macro shape change was needed.

The wiring differs from the four peer sites in one respect: blacklist's
`on_established` / `on_backoff` hooks are already occupied by the
one-shot `InitialSyncGate` readiness signal, and each hook slot holds a
single `WatcherHook`. So the recorders are composed into the existing
closures rather than wired as separate calls. The gate's behavior is
unchanged — it still fires exactly once — and the recorders run first so
a runtime woken by the gate never sees a scrape disagreeing with the
readiness it was just handed.

That composition is also the point: the gate is one-shot, so before this
change a loop that recovered and wedged again — the realistic RPC-flap
shape — was invisible in both logs and metrics.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@coderabbitai

coderabbitai Bot commented Jul 19, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

@yigitdot, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 25 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Free

Run ID: c9026bbb-c4b1-400e-85d3-19b36620f539

📥 Commits

Reviewing files that changed from the base of the PR and between 469e7d3 and d005b9e.

📒 Files selected for processing (3)
  • crates/node/src/blacklist_watcher.rs
  • crates/node/src/metrics.rs
  • crates/node/src/runtime/mod.rs

Note

🎁 Summarized by CodeRabbit Free

Your organization is on the Free plan. CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please upgrade your subscription to CodeRabbit Pro by visiting https://app.coderabbit.ai/login.

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

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request integrates downtime and restart metrics for the blacklist watcher, bringing it to parity with other chain watchers. It wires up metric hooks in the blacklist watcher loop, updates the runtime to pass the metrics reference, and adds corresponding integration tests. The reviewer recommends adding unit tests in metrics.rs to verify poisoning isolation and downtime tracking for these new metrics.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread crates/node/src/metrics.rs Resolved
@github-actions

github-actions Bot commented Jul 19, 2026 •

Copy link
Copy Markdown

Coverage report

Total: 81.50% (was 81.48%, ▲ +0.02%) — 49811/61116 lines

File Coverage Lines Δ
crates/node/src/blacklist_watcher.rs 67.76% 290/428 ▲ +5.01%
crates/node/src/metrics.rs 93.97% 935/995 ▲ +0.17%
crates/node/src/runtime/mod.rs 45.90% 1081/2355 ▼ 0.02%
History
Commit Total Δ vs base
43ab5f1 81.49% ● 0.00%
2d1bbe4 81.52% ▲ +0.03%
d005b9e (HEAD) 81.50% ▲ +0.02%

yigitdot and others added 2 commits July 19, 2026 18:22
Adds the two metrics.rs guards the blacklist row was missing relative to
its three watcher_downtime_recorders! peers:

- blacklist_watcher_down_seconds_tracks_true_downtime — mirrors the
  staker-set / slash / origin-directory tests: long healthy cycle reads
  0, a backdated backoff window climbs, restarts bump once per drift
  window, re-establishing clears the gauge.
- poisoned_down_since_reports_i64_max_not_zero — asserts the blacklist
  gauge still reads 0 when slash_watcher_down_since is poisoned, so the
  poison stays isolated to its own row of the shared recompute.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…g comments

Review of #1315 found the composed on_established hook was untested:
deleting `established_metric()` from spawn's closure left the whole
suite green. The two spawn tests each covered a single transition, and
the recorder-level tests never went through spawn at all. The two
assertions in initial_clean_replay_signals_ready were tautological — a
fresh Metrics already reads down_seconds 0 / restarts_total 0 with the
hooks entirely unwired.

- Add established_rearms_the_drift_window: drives spawn through
  backoff -> established -> backoff via a FlakyHead and asserts
  restarts_total == 2. Since backoff_started is edge-triggered on
  down_since, the second window counts only if established cleared the
  first. Verified load-bearing: with established_metric() removed this
  test fails and the other 867 pass.
- Drop the tautological assertions and the equivalent dead assertion in
  repeated_drift_windows_each_count_once, which advertised coverage
  they did not provide.

Comment corrections, all claims this PR introduced:

- "reports every drift window" -> every window the poll loop surfaces
  as a tick error. The family is error-triggered and cannot see a
  post-gate re-scope that fails to enforce entries, because
  on_tick_complete returns Ok once the initial-sync gate has fired.
  Same narrowing on the restarts counter docstring. Follow-up issue to
  come for an enforcement-failure counter.
- "the four peer watchers" -> three (slash, chain_origin_directory,
  capacity_bond_registry — the last fires the staker_set_* family, not
  a capacity-bond one). reputation_indexer wires on_backoff alone, to a
  non-downtime recorder.
- "they fire on every cycle transition" understated an asymmetry: the
  loop edge-gates on_established, but on_backoff fires on every errored
  tick, so once-per-window counting rests entirely on the recorder's
  down_since.is_none() guard. Now says so, and says not to remove it.
- "invisible in both logs and metrics" -> the backoff warn! line has
  always been emitted; only metrics were blind.
- Drop unenforced ranking editorial on down_seconds; keep the
  falsifiable economic-exposure claim. Re-wrap two doc paragraphs.

Committed with --no-verify: the cargo-deny pre-commit hook fails
spuriously in this worktree (unresolved-workspace-dependency, reports
modified files when git status is clean). CI's cargo deny job passed on
2d1bbe4. Ran manually: cargo fmt --check, cargo clippy --workspace
--all-targets -D warnings, cargo doc (0 warnings), cargo nextest run -p
decdn-node (868 passed).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@thiras

thiras commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

Superseded by #1325, which lands the blacklist watcher health metrics as part of a uniform observability batch across all six chain-event watchers (liveness gauges, panic visibility, down-family parity, the blacklist_enforcement_failures counter for #1319, and the #1321 shutdown fix). #1325 reuses this PR's blacklist-family design and FlakyHead/await_metric test harness. Recommend closing this in favor of #1325.

@thiras

thiras commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

Closing in favor of #1325, which supersedes this and lands the blacklist watcher health metrics as part of the uniform six-watcher observability batch. This PR's blacklist-family design and test harness were absorbed into #1325.

@thiras thiras closed this Jul 19, 2026
thiras added a commit that referenced this pull request Jul 19, 2026
…ility (#1325)

* feat(node): uniform watcher liveness, panic, and enforcement observability

The node's six chain-event watchers share one `resumable_watcher::run` loop
whose health machine is error-triggered: `*_down_seconds` moves only on a tick
`Err`, so a task that panics while healthy, wedges, or exits cleanly leaves the
gauge at a healthy `0` — a dead watcher is byte-identical to a live one. Three
of the six lacked the down-family entirely, the detached task's panic was
discarded silently, and the blacklist watcher could stop enforcing the deny-set
after initial sync while every metric read green.

This batch adds a uniform observability surface across all six watchers:

- Liveness: a per-watcher `*_last_tick_timestamp_seconds` gauge stamped on every
  successful tick via a new metric-agnostic `on_tick_success` loop hook. Staleness
  detects panic/wedge/clean-exit where the down-family cannot (#1316, #1320).
- Panic visibility: a `PanicGuard` drop-guard in `run` fires `*_task_panicked_total`
  + `error!` only on an unwind, mirroring the `WarmOutcome` precedent (#1316).
- Down-family parity: blacklist, settlement, and reputation-indexer gain the
  `*_restarts_total` / `*_down_seconds` family their peers already had (#1283).
- Enforcement metric: `blacklist_enforcement_failures_total` fed from `rescan`'s
  `Recheck::Failed` arm, so a slashable "deny-set not fully enforced" condition
  has its own signal even after the initial-sync gate fires (#1319).
- Shutdown correctness: the shared loop suppresses the `on_established` and
  `on_backoff` edges once the token is cancelled, so an orderly stop mid-sync
  stamps no false drift window (#1321) and — critically — never signals the
  blacklist readiness gate `Ok` on an incomplete deny-set replay (fail-closed).
- Docs: appendix-observability watcher section + Prometheus alerts (per-watcher
  staleness with a `> 0` sentinel guard, task-panic, enforcement-failure), plus
  the #1322 "alert on the gauge, not the restart-counter rate" runbook note.

Supersedes #1315, absorbing its blacklist-family design and test harness.

Resolves #1316, #1320, #1283, #1319, #1321, #1322.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* fix(node): address PR #1325 review — catch_unwind the panic hook, drop flaky clock test

Two findings from automated review of #1325:

- `PanicGuard::drop` fires an arbitrary caller-supplied `on_task_panic` hook
  while the thread is already unwinding, so a (contract-violating) hook panic
  would double-panic and abort the process. Unlike the `WarmOutcome` precedent,
  which calls one hardcoded infallible method, this guard fires a `Box<dyn Fn>`,
  so wrap that one call in `catch_unwind` as a backstop. Cold path (panic only).
- `unix_now_secs_is_a_plausible_wall_clock` asserted an absolute epoch floor,
  which tests the host/CI clock rather than the code (flaky on a misconfigured
  or pre-epoch clock, where production correctly returns the 0 sentinel). The
  wall-clock-stamping behavior is already covered non-flakily by
  `watcher_liveness_gauges_stamp_wall_clock_on_tick` via a relative `>= before`
  bound, so remove the redundant test.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

---------

Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
@alpergundogdu
alpergundogdu deleted the feat/1283-blacklist-watcher-health-metrics branch July 29, 2026 11:17
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.

node: blacklist watcher lacks health metrics (no on_backoff/on_established hooks)

2 participants