Skip to content

feat(node): uniform watcher liveness, panic, and enforcement observability - #1325

Merged
thiras merged 2 commits into
mainfrom
feat/watcher-observability-batch
Jul 19, 2026
Merged

thiras merged 2 commits into
mainfrom
feat/watcher-observability-batch

Conversation

@thiras

@thiras thiras commented Jul 19, 2026 •

Copy link
Copy Markdown
Contributor

Context

The node's six chain-event watchers (slash, staker-set, origin-directory, blacklist, settlement, reputation-indexer) share one resumable_watcher::run loop whose health machine is error-triggered: *_down_seconds moves only when a poll tick returns Err. A task that panics while healthy, wedges in an uncovered await, or exits cleanly on shutdown leaves the down-since state unset, so *_down_seconds reads a healthy 0 — a dead watcher is byte-identical to a live one. On top of that, 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 (a slashable exposure).

This batch gives all six watchers a uniform, positive-signal observability surface.

Supersedes #1315 (absorbs its blacklist-family design and FlakyHead/await_metric test harness; discards its stale base + unrelated churn).

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

What changed

Review

This branch was reviewed by the pr-review-toolkit (code / tests / silent-failure / type-design / comments). All actionable findings were applied before this PR, including a readiness-gate fail-open that an earlier revision of the #1321 fix introduced (now fixed by moving shutdown-awareness into the shared loop) and a cancel-path that discarded already-observed enforcement failures.

Verification

  • cargo clippy --workspace --all-targets -- -D warnings ✔
  • cargo fmt -- --check ✔
  • RUSTDOCFLAGS="-D warnings" cargo doc ✔
  • cargo nextest run -p decdn-node → 877 passed (incl. new tests: liveness fires-every-tick, panic-guard + false-positive control, end-to-end run panic, shutdown edge-suppression, Blacklist enforcement failures are unobservable after initial sync #1319 aggregate count, down-family parity, poisoned-lock)
  • prometheus-alerts.yml parses (promtool not installed locally)

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Added comprehensive monitoring for watcher liveness, downtime, task panics, and blacklist enforcement failures.
    • Added alerts for stalled watchers, panic events, and enforcement failures.
    • Watchers now report successful polling activity and shutdown-safe lifecycle status.
  • Bug Fixes

    • Improved blacklist rescan handling to continue retrying after enforcement failures while accurately reporting unsuccessful entries.
  • Documentation

    • Documented new watcher metrics, naming conventions, and recommended alerting guidance.

…ility

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]>
Copilot AI review requested due to automatic review settings July 19, 2026 18:39
@coderabbitai

coderabbitai Bot commented Jul 19, 2026 •

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

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

Next review available in: 47 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: dd831041-0a08-452a-90ce-468d37bf633a

📥 Commits

Reviewing files that changed from the base of the PR and between 6b68ed0 and 8f016e8.

📒 Files selected for processing (2)
  • crates/node/src/chain_events/resumable_watcher.rs
  • crates/node/src/metrics.rs

Walkthrough

The PR adds watcher liveness, panic, downtime, and blacklist enforcement metrics. Resumable watchers gain tick and panic hooks, watcher bootstraps wire those hooks into Metrics, blacklist rescans report partial failures, and Prometheus alerts and observability documentation cover the new signals.

Changes

Watcher observability

Layer / File(s) Summary
Metrics and watcher hook contracts
crates/node/src/chain_events/resumable_watcher.rs, crates/node/src/metrics.rs, crates/node/src/chain_events/shared_head.rs
Watcher configurations and metrics now support successful-tick, panic, downtime, and enforcement-failure recording, with corresponding metric tests.
Resumable watcher lifecycle semantics
crates/node/src/chain_events/resumable_watcher.rs
Successful ticks fire on every tick, shutdown suppresses readiness/backoff edges, and panic unwinding invokes the panic hook.
Watcher integrations and blacklist enforcement
crates/node/src/blacklist_watcher.rs, crates/node/src/slash_watcher.rs, crates/node/src/payment_settlement.rs, crates/node/src/reputation_indexer.rs, crates/node/src/dht/*, crates/node/src/runtime/mod.rs
Watcher bootstraps wire lifecycle metrics; blacklist rescans aggregate unenforced entries and retain initial-sync retry behavior.
Alerting and observability documentation
adr/appendix-observability.md, monitoring/prometheus-alerts.yml
Documents metric semantics and adds stalled, panic, and blacklist enforcement alerts.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Watcher
  participant Metrics
  participant Prometheus
  Watcher->>Metrics: record successful tick or panic
  Watcher->>Metrics: record downtime transitions
  Metrics-->>Prometheus: expose watcher metrics
  Prometheus->>Prometheus: evaluate staleness and failure alerts
Loading

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 introduces a uniform observability and liveness tracking system across all six chain-event watchers. It adds positive liveness signals (*_last_tick_timestamp_seconds), panic tracking counters (*_task_panicked_total) via a new PanicGuard in the resumable watcher loop, and specific blacklist enforcement failure metrics. Additionally, it brings the blacklist, settlement, and reputation indexer watchers to full downtime metric parity, updates Prometheus alerting rules, and adds comprehensive unit tests. No review comments were provided, so there is no feedback to address.

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.

@github-actions

github-actions Bot commented Jul 19, 2026 •

Copy link
Copy Markdown

Coverage report

Total: 81.63% (was 81.50%, ▲ +0.13%) — 50382/61722 lines

File Coverage Lines Δ
crates/node/src/blacklist_watcher.rs 80.67% 363/450 ▲ +17.92%
crates/node/src/chain_events/resumable_watcher.rs 94.85% 792/835 ▲ +0.85%
crates/node/src/chain_events/shared_head.rs 94.33% 183/194 ▲ +0.06%
crates/node/src/dht/capacity_bond_registry.rs 65.60% 246/375 ▼ 0.89%
crates/node/src/dht/chain_origin_directory.rs 72.22% 811/1123 ▼ 0.52%
crates/node/src/metrics.rs 94.33% 998/1058 ▲ +0.44%
crates/node/src/payment_settlement.rs 56.53% 943/1668 ▼ 0.44%
crates/node/src/reputation_indexer.rs 59.73% 307/514 ▼ 1.43%
crates/node/src/runtime/mod.rs 45.81% 1081/2360 ▼ 0.02%
crates/node/src/slash_watcher.rs 57.41% 124/216 ▼ 1.08%
History
Commit Total Δ vs base
6b68ed0 81.63% ▲ +0.13%
8f016e8 (HEAD) 81.63% ▲ +0.13%

Copilot AI 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.

Pull request overview

This PR strengthens node chain-event watcher observability by adding uniform positive-signal liveness gauges, panic visibility, and parity in downtime metrics across all six watchers, plus alerting/docs to operationalize the new signals.

Changes:

  • Added per-watcher liveness stamping (*_last_tick_timestamp_seconds) and per-watcher panic counters (*_task_panicked_total) via new resumable_watcher hooks.
  • Extended downtime metrics parity to previously uncovered watchers (blacklist, settlement, reputation-indexer) and added a dedicated blacklist enforcement-failure counter.
  • Added Prometheus alert rules and updated observability documentation to recommend gauge-based liveness/downtime alerting.

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
monitoring/prometheus-alerts.yml Adds alert rules for watcher staleness, task panics, and blacklist enforcement failures.
crates/node/src/chain_events/resumable_watcher.rs Introduces on_tick_success/on_task_panic hooks, shutdown edge suppression, and panic guard plumbing.
crates/node/src/metrics.rs Defines new watcher liveness/panic/enforcement metrics and corresponding recorders/tests.
crates/node/src/blacklist_watcher.rs Wires new watcher hooks, threads metrics into the sink, and counts enforcement failures from rescans.
crates/node/src/slash_watcher.rs Wires tick-success liveness and panic hooks for the slash watcher.
crates/node/src/payment_settlement.rs Adds full watcher hook wiring (established/backoff/tick/panic) for settlement watcher.
crates/node/src/reputation_indexer.rs Adds established/backoff parity, plus tick/panic hooks for the reputation indexer watcher.
crates/node/src/dht/chain_origin_directory.rs Wires tick-success liveness and panic hooks for origin-directory watcher.
crates/node/src/dht/capacity_bond_registry.rs Wires tick-success liveness and panic hooks for staker-set watcher.
crates/node/src/chain_events/shared_head.rs Updates tests to account for the expanded WatcherConfig struct fields.
crates/node/src/runtime/mod.rs Threads node_metrics into blacklist watcher spawn callsite.
adr/appendix-observability.md Documents new watcher liveness/panic/enforcement metrics and recommended alerting strategy.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread crates/node/src/metrics.rs Resolved
…p 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]>
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: chain watcher task panics are invisible (detached JoinHandle + zero-valued downtime gauge)

2 participants