Skip to content

feat(node): split probe-hold refusal metric by cause — disabled vs exhausted (#739) - #754

Merged
thiras merged 3 commits into
mainfrom
feat/739-probe-hold-cause-metrics
Jun 1, 2026
Merged

thiras merged 3 commits into
mainfrom
feat/739-probe-hold-cause-metrics

Conversation

@thiras

@thiras thiras commented Jun 1, 2026 •

Copy link
Copy Markdown
Contributor

Closes #739.

Problem

ProbeHoldOutcome::BudgetExhausted conflated two operationally distinct reasons a node answers has_blob: false for a blob it actually holds:

  1. max_probe_holds == 0 — the eviction-hold path is disabled by config (an operator decision).
  2. max_probe_holds > 0 but every slot is live — genuine budget pressure.

Both incremented decdn_probe_hold_violations_total, whose alert remedy in appendix-observability.md is "reduce load or increase max_probe_holds". That remedy is nonsensical — and the alert a false alarm — when an operator has intentionally turned holds off. Operators couldn't tell a misconfiguration from real cache pressure, which is exactly what the issue asks for.

Note on the issue title: holds are never pre-empted mid-flight. A held hash is filtered out of eviction_candidates (engine.rs), so the LRU driver can't break a live hold — it always runs to full PROBE_HOLD_DURATION. The meaningful, observable distinction is therefore at the grant point (disabled vs. exhausted), which is what this PR instruments. The doc's stale "evicted after signing has_blob: true" description is corrected accordingly.

Change

  • cache: split ProbeHoldOutcome::BudgetExhausted into BudgetExhausted (positive budget, all slots live) and a new HoldsDisabled (max == 0) variant.
  • node: map HoldsDisabled to a new decdn_probe_holds_disabled_total counter; keep BudgetExhausted on decdn_probe_hold_violations_total (now a clean "raise the budget" signal). Each refusal arm emits a structured debug log naming its cause.
  • adr/appendix-observability.md: new counter row in Probe Metrics, corrected probe_hold_violations description, cross-reference entry.

Checklist (from the issue)

  • Add a new variant distinguishing the cause (chose two variants over a reason field, matching the existing enum style).
  • Update the counter site — violations now only for genuine exhaustion; new probe_holds_disabled counter for the disabled case.
  • Structured log events at the split point.
  • Update appendix-observability.md.
  • Tests asserting each counter increments only for its respective path.

Testing

TDD throughout (watched each test fail first):

  • decdn-cache: probe_hold_disabled_when_budget_zero now asserts HoldsDisabled, distinct from the sibling exhaustion test.
  • decdn-node: two end-to-end probe tests assert the disabled and exhausted paths bump only their respective counter (the other stays 0).

cargo nextest run -p decdn-cache -p decdn-node → 507 passed. cargo clippy --all-targets and cargo fmt --check clean.

Conflict avoidance

Contained to the cache/node probe-hold path. No overlap with the in-flight payment-channel PRs (#753, #752, #743), which live in node settlement + incentive.

🤖 Generated with Claude Code

…hausted (#739)

`ProbeHoldOutcome::BudgetExhausted` conflated two operationally distinct
causes of a `has_blob: false` answer for a present blob:

- `max_probe_holds == 0` — holds intentionally disabled by config
- `max_probe_holds > 0` but every slot live — genuine budget pressure

Both bumped `decdn_probe_hold_violations_total`, whose alert remedy is
"increase max_probe_holds" — nonsensical (and a false alarm) when an
operator has deliberately turned holds off.

Split the outcome into `BudgetExhausted` (kept on `probe_hold_violations`,
now a clean "raise the budget" signal) and a new `HoldsDisabled` variant
counted by `decdn_probe_holds_disabled_total`. Each refusal path emits a
structured debug log naming its cause. Holds are never pre-empted mid-flight
(a held hash is invisible to the LRU driver), so the split is at the grant
point, not on expiry.

Updated appendix-observability.md (new counter row, corrected the
violations description, cross-reference entry).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Copilot AI review requested due to automatic review settings June 1, 2026 10:36

@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 distinguishes between probe holds refused due to genuine budget pressure (BudgetExhausted) and those refused because holds are intentionally disabled by configuration (HoldsDisabled when max_probe_holds == 0). This prevents intentional disables from triggering alerts meant for budget exhaustion. The changes update the ADR documentation, cache engine, probe handler, metrics, and tests. The review feedback highlights three key improvement opportunities: avoiding lock contention in the debug log by removing the redundant probe_hold_slots_used() call, optimizing performance by checking for disabled holds early before acquiring the lock, and removing an unused hashes vector in the test setup.

Comment thread crates/node/src/handlers/probe.rs Resolved
Comment thread crates/cache/src/engine.rs Resolved
Comment thread crates/node/tests/probe_loopback.rs Resolved

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 refines probe-hold observability by separating “probe hold refused” events into two operationally distinct causes—holds disabled by config vs budget exhausted under load—so operators can distinguish intentional configuration from actionable pressure signals.

Changes:

  • Split ProbeHoldOutcome::BudgetExhausted into BudgetExhausted vs new HoldsDisabled (max_probe_holds == 0) in decdn-cache.
  • Instrument decdn-node to emit a new counter decdn_probe_holds_disabled_total, keep decdn_probe_hold_violations_total for true exhaustion, and add cause-specific debug logs.
  • Update loopback probe tests and the observability appendix to cover/describe the new metric and semantics.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
crates/node/tests/probe_loopback.rs Adds end-to-end tests asserting the correct counter increments for disabled vs exhausted probe-hold refusal.
crates/node/src/metrics.rs Introduces probe_holds_disabled counter and a helper method to increment it.
crates/node/src/handlers/probe.rs Maps HoldsDisabled vs BudgetExhausted to distinct counters and emits structured debug logs per cause.
crates/cache/src/probe_hold.rs Extends ProbeHoldOutcome with HoldsDisabled and updates variant semantics docs.
crates/cache/src/engine.rs Implements the new split outcome in try_probe_hold and updates cache-level tests.
adr/appendix-observability.md Documents the new counter, updates probe_hold_violations semantics, and adds a canonical-name mapping entry.

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

Comment thread crates/node/src/handlers/probe.rs Resolved
Comment thread crates/cache/src/engine.rs Resolved
Comment thread adr/appendix-observability.md Resolved
@github-actions

github-actions Bot commented Jun 1, 2026 •

Copy link
Copy Markdown

Coverage report

Total: 89.51% (was 89.49%, ▲ +0.02%) — 23826/26619 lines

File Coverage Lines Δ
crates/cache/src/engine.rs 93.39% 1624/1739 ▲ +0.14%
crates/node/src/handlers/probe.rs 85.49% 165/193 ▲ +0.31%
crates/node/src/metrics.rs 84.63% 402/475 ▲ +0.10%
History
Commit Total Δ vs base
83aacb1 89.49% ● 0.00%
9dbd35c 89.50% ▲ +0.01%
528d948 (HEAD) 89.51% ▲ +0.02%

thiras and others added 2 commits June 1, 2026 13:46
…ck, doc/test cleanups

Bot review (gemini-code-assist, Copilot):

- engine: return `HoldsDisabled` early when `max_probe_holds == 0`, before
  the lock and fast path. Beyond skipping the O(N) sweep, this fixes a latent
  inconsistency: the fast path would refresh and re-sign an existing hold even
  with holds disabled, so a runtime `set_max_probe_holds(0)` didn't fully take
  effect. `max == 0` is now an unconditional "never sign has_blob:true".
  New test `runtime_disable_overrides_existing_probe_hold` covers it.
- probe handler: drop `probe_hold_slots_used()` from the budget-exhausted
  debug log — it re-locked `probe_holds` + swept on the refusal hot path for a
  foregone ~`max` value (the gauge is already published once per probe).
- docs/comments: update `try_probe_hold` doc and the handler match comment for
  the three-cause split; clarify the Slash-Safety section intro (counters vs
  gauges; violations is an availability signal, not a slash risk).
- test: drop the unused `hashes` vector in `cache_with_two_blobs`.

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

Multi-agent review (code/tests/comments/errors/types):

- Add `absent_blob_is_unavailable_even_when_holds_disabled` regression test
  (test-analyzer's one blocking gap): pins that the `max == 0` early return
  sits *after* `has()`, so an absent blob is `Unavailable`, not a
  `HoldsDisabled` config-disable event. Verified the test has teeth by
  temporarily reordering the checks (it failed), then reverted.
- Fix stale `set_max_probe_holds` doc: `try_probe_hold` returns
  `HoldsDisabled` for a present blob, not "`false`".
- Reframe the "config reload" framing in the early-return and test comments:
  `cache.max_probe_holds` is restart-required (not in the SIGHUP reload set),
  so the only post-startup caller is the test — the invariant is what matters,
  not a non-existent hot-reload path.
- Document that the `max == 0` early return is slash-safe despite skipping the
  under-lock `is_evicted` re-check: a concurrently-evicted blob is still
  answered `has_blob: false`, so the misclassification is a metric-only
  miscount, never a phantom `true`.

No behavior change beyond the added test. 509 tests pass, clippy + fmt clean.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@thiras
thiras merged commit 1b923c8 into main Jun 1, 2026
18 checks passed
thiras added a commit that referenced this pull request Jun 1, 2026
…ck, doc/test cleanups

Bot review (gemini-code-assist, Copilot):

- engine: return `HoldsDisabled` early when `max_probe_holds == 0`, before
  the lock and fast path. Beyond skipping the O(N) sweep, this fixes a latent
  inconsistency: the fast path would refresh and re-sign an existing hold even
  with holds disabled, so a runtime `set_max_probe_holds(0)` didn't fully take
  effect. `max == 0` is now an unconditional "never sign has_blob:true".
  New test `runtime_disable_overrides_existing_probe_hold` covers it.
- probe handler: drop `probe_hold_slots_used()` from the budget-exhausted
  debug log — it re-locked `probe_holds` + swept on the refusal hot path for a
  foregone ~`max` value (the gauge is already published once per probe).
- docs/comments: update `try_probe_hold` doc and the handler match comment for
  the three-cause split; clarify the Slash-Safety section intro (counters vs
  gauges; violations is an availability signal, not a slash risk).
- test: drop the unused `hashes` vector in `cache_with_two_blobs`.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@thiras
thiras deleted the feat/739-probe-hold-cause-metrics branch June 1, 2026 11:02
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.

cache: no metric or structured log event emitted when a probe hold expires naturally vs. is released early by eviction pressure

2 participants