Skip to content

feat(node): lean positive probe cache (ADR 001, 15s TTL, no evidence retention) (#1165) - #1223

Merged
thiras merged 20 commits into
mainfrom
feat/1165-positive-probe-cache
Jul 17, 2026
Merged

thiras merged 20 commits into
mainfrom
feat/1165-positive-probe-cache

Conversation

@yigitdot

@yigitdot yigitdot commented Jul 16, 2026 •

Copy link
Copy Markdown
Contributor

Closes #1165.

What

Implements the ADR 001 §Probe cache positive cache: a short-lived LRU hash → Vec<(NodeId, rate_per_mb, rtt)> (15s TTL, 1024 entries, ≤10 providers/hash) checked before the DHT lookup. A repeat cache-miss for a popular hash skips both the DHT FIND_VALUE and the probe fanout, going straight to selection. Covers both pull paths — buffered (Origin::fetch) and window-paced (open_progressive_pull).

Design highlights

  • No evidence retention (headline requirement). The cache stores only the ADR triple — never the signed ProbeResponse. Its slash_sig is another node's on-chain slashable statement; an availability cache has no business being an evidence locker. ProbedProvider has exactly three fields, enforced by a const size tripwire so it can't silently grow.
  • TTL derived, not literal. DEFAULT_TTL = PROBE_SLASH_WINDOW / 2 (ADR 005 §Derived constants) — a governance change to the slashing window moves it automatically; a literal 15s would silently not. Also bounded below probe_hold_duration (35s) so the eviction hold still covers a stream opened from a cached entry.
  • Shared attempt budget. The cached phase and the cold DHT-fallback phase share ONE MAX_PROVIDER_ATTEMPTS (=3) budget (threaded via a generic PullOutcome<T>), so the worst case stays 3 sequential pulls and outer_pull_deadline needs no change. A cached phase that exhausts the budget short-circuits before discover.
  • Staleness-safe hits. On a hit, cached_candidates re-applies the negative-cache and wedged-channel filters, re-checks active-staker membership (staker_set.is_active — the same admission gate find_providers applies on the cold path, so a node ejected/unbonding inside the TTL is denied a paid pull), and rebuilds reputation/region fresh every time (never cached). It deliberately does not re-run the ADR-030 region-latency penalty (a hit performs no probe → no new evidence).
  • Hand-rolled LRU over indexmap, mirroring the existing NegativeProbeCache line-for-line (no new dependency).

Observability

  • Wires decdn_probe_post_eviction_failures_total (ADR 001-mandated, specified at appendix-observability.md:86 and already scraped by grafana-dashboard.json — it had never been emitted). A DurableMissCause split (exhaustive match, not ==) keeps BlobTooLarge out of the count and forces any future cause to decide its telemetry.
  • Adds decdn_probe_cache_hits_total / decdn_probe_cache_misses_total (registered in the appendix). A 'hit' is counted when the candidate walk starts from a live entry; if every cached provider then fails within budget the fetch falls through cold but stays counted — the doc + appendix row say so explicitly.

Tests

New unit tests pin the cache's LRU/TTL/truncation semantics; integration tests assert at the wire (a probe-counting AtomicUsize), not just on metrics: second-fetch-skips-probe, past-TTL-reprobes, shared-budget (3 refusals not 6), hit-honours-negative-cache, cross-path reuse, partial-budget fall-through metering, invalidate-on-exhaustion, post-eviction-metric emission, fully-suppressed-entry miss, wedged-provider filter, and hit-drops-a-no-longer-active-provider (ejection inside the TTL). Full workspace suite green; clippy --workspace --all-targets and fmt clean.

Review rounds addressed

  • Five-agent review: metric-contract wording (probe_cache_hits semantics, node_pull_no_providers exclusivity gate), exhaustive DurableMissCause match, generic PullOutcome<T>, comment-accuracy fixes, plus coverage-gap tests.
  • Human review (@altanoruc): re-check active-staker membership on cache hits (893dac1) + regression test (2d8093b). One accepted tradeoff: a static-config origin that isn't a staker is skipped on a hit and served via cold fallthrough instead — correctness preserved, hit-acceleration lost for static-only deployments; a non-issue in production (chain-backed directories are staker-filtered).

Notes

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Added a positive probe cache to reuse recently successful provider probe results (TTL + LRU with provider ranking limits).
    • Applied probe-cache reuse to both progressive and buffered pull flows, including shared attempt-budget handling and cache fallthrough on exhausted budgets.
    • Expanded metrics coverage for probe-cache hits, misses, and post-eviction signals.
  • Bug Fixes

    • Refined durable-miss handling so post-eviction metrics increment only for the eviction cause (not for payload-size failures).
  • Documentation

    • Clarified probe-cache metric definitions and exact hit/miss/post-eviction counting behavior.
  • Tests

    • Expanded end-to-end and unit test assertions to validate cache TTL behavior, suppression interactions, and metric correctness.

yigitdot and others added 9 commits July 16, 2026 15:47
…robe cache)

The metric has been specified at appendix-observability.md:86 and scraped by
monitoring/grafana-dashboard.json:411 without ever being emitted. Splitting
RefusalVerdict::DurableMiss over a DurableMissCause keeps BlobTooLarge — which
shares the verdict but says nothing about any hold mechanism — out of the count.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
…ate walk

Task 3 of the positive-probe-cache plan (#1165). Pure behaviour-neutral prep:
try_pull and a new open_from_candidates (lifted from open_progressive_pull's
inline loop) now take an explicit budget and report attempts consumed via a
new PullOutcome, so a later change can share one MAX_PROVIDER_ATTEMPTS budget
across the probe-cache walk and the DHT-discovery fallback walk. Both call
sites still pass the full MAX_PROVIDER_ATTEMPTS, so nothing observable changes.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Wire PositiveProbeCache into NodeOriginDeps (beside the negative cache)
and write the top-10 (node_id, rate_per_mb, rtt_ms) triple at the tail of
probe_and_rank, extracted into a shared `rank` helper. Write-only and
behaviour-neutral: nothing reads the cache yet, so the full decdn-node
suite (798 tests) stays green and unchanged.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
…T (ADR 001)

Origin::fetch now checks the positive probe cache before running a fresh
DHT lookup + probe fanout: cached_candidates rebuilds ranked Candidates
from a hit (fresh reputation/region, no ADR 030 latency re-scoring),
filtered through the same negative-cache and wedged-channel checks
probe_and_rank applies. MAX_PROVIDER_ATTEMPTS is now a single fetch-wide
budget shared between the cached-candidate walk and the cold-path
fallback, so a fully-refusing cache hit cannot double the worst-case
pull-through deadline.

Adds four integration tests exercising the wire-level property (no probe
sent on a hit), TTL expiry, the shared attempt budget, and the negative
cache's precedence over a stale positive hit — plus a probe-counting and
a refusal-counting test-server variant to observe those properties at
the wire rather than through metrics alone.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
open_progressive_pull (the window-paced pull path) wrote the positive probe
cache via probe_and_rank but never read it, unlike Origin::fetch (the
buffered path), which Task 5 made cached-first. Both consumers share one
probe cache and the same probe_and_rank chokepoint that fills it, so a path
that only writes pays the cost for the other's benefit.

Restructures open_progressive_pull to check cached_candidates() first,
walking the cached candidates via open_from_candidates() under a shared
MAX_PROVIDER_ATTEMPTS budget before falling through to discover + probe on
a miss or exhausted cache, mirroring Origin::fetch's flow exactly.

Metering delta: node_pull_attempt() now fires once per call, after the
cache-check on both branches (previously it fired unconditionally right
after discovery, before probing). No prior test asserted
node_pull_attempts_total on the progressive path, so this is safe — the
buffered and window paths now agree on the metering contract.

Adds a_progressive_pull_reuses_a_probe_cache_entry_written_by_a_buffered_fetch,
which runs Origin::fetch then open_progressive_pull for the same hash and
asserts the wire-level probe counter stays at 1 while the progressive pull
still delivers the verified payload.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
…deferred staker filter (#1165)

Origin::fetch's cache-hit-then-fall-through-to-cold path (the branch that
exercises the `if !attempt_metered` skip guarding node_pull_attempt() from
double-counting) had no coverage where the cached phase spends FEWER than
MAX_PROVIDER_ATTEMPTS before failing. Adds a test that warms the cache with a
single refusing provider, brings a second healthy provider online between
fetches, and asserts node_pull_attempts_total stays at 2 (not 3) across both
fetches. Also notes in cached_candidates why the staker-set membership filter
is deliberately not re-applied on a cache hit.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@coderabbitai

coderabbitai Bot commented Jul 16, 2026 •

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Free

Run ID: bcfc4d78-8a19-4916-addc-6fde22240916

📥 Commits

Reviewing files that changed from the base of the PR and between 3b65dbf and f80748d.

📒 Files selected for processing (4)
  • adr/appendix-observability.md
  • crates/node/src/dht/probe_cache.rs
  • crates/node/src/metrics.rs
  • crates/node/tests/node_origin_pull.rs
🚧 Files skipped from review as they are similar to previous changes (4)
  • crates/node/src/dht/probe_cache.rs
  • adr/appendix-observability.md
  • crates/node/src/metrics.rs
  • crates/node/tests/node_origin_pull.rs

Walkthrough

Adds an LRU/TTL positive probe cache, cached-first origin pull orchestration for buffered and progressive paths, probe-cache metrics, durable refusal causes, runtime wiring, and integration coverage for expiry, filtering, budgets, and cache reuse.

Changes

Positive probe cache integration

Layer / File(s) Summary
Cache storage and public API
crates/node/src/dht/probe_cache.rs, crates/node/src/dht/mod.rs
Defines ProbedProvider and PositiveProbeCache with bounded LRU storage, insertion-anchored TTLs, provider truncation, invalidation, poison-tolerant locking, public exports, and unit tests.
Dependency wiring and refusal observability
crates/node/src/node_origin.rs, crates/node/src/runtime/mod.rs, crates/node/src/metrics.rs, adr/appendix-observability.md
Adds the positive-cache dependency, runtime initialization, cache counters and documentation, and payload-carrying durable refusal causes that distinguish eviction from oversized blobs.
Cached-first origin pulls
crates/node/src/node_origin.rs
Adds cached candidate reconstruction and filtering, shared attempt budgets across cached and cold walks, cache population and invalidation, and cached-first behavior for buffered and progressive pulls.
Integration coverage and implementation plan
crates/node/tests/node_origin_pull.rs
Adds counted probe and stream fixtures plus tests for cache reuse, expiry, suppression, wedged providers, fallthrough, budget handling, progressive pulls, and post-eviction metrics.

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

Sequence Diagram(s)

sequenceDiagram
  participant Origin
  participant PositiveProbeCache
  participant DHTProbe
  participant Provider
  Origin->>PositiveProbeCache: look up hash
  PositiveProbeCache-->>Origin: return cached ranked provider data
  Origin->>Provider: attempt cached pull
  Origin->>DHTProbe: perform fresh lookup and probe on cache miss or fallthrough
  DHTProbe-->>PositiveProbeCache: store ranked provider triples
  DHTProbe-->>Origin: return cold candidates
  Origin->>Provider: attempt cold pull
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.

@github-actions

Copy link
Copy Markdown

Gas snapshot

No gas changes vs base.

@github-actions

github-actions Bot commented Jul 16, 2026 •

Copy link
Copy Markdown

Contracts coverage

Line coverage: 88.92% (2488/2798 lines)
▲ +0.00pp vs base (88.92% → 88.92%)
Run: 29608431414

@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 implements the positive probe cache as specified in ADR 001, allowing repeat cache misses for popular hashes to skip DHT lookups and probe fanouts. It introduces PositiveProbeCache (a bounded LRU cache with a 15-second TTL), integrates it into both the buffered and window-paced pull paths under a shared attempt budget, and adds corresponding metrics and tests. The reviewer suggested an optimization in the get method of PositiveProbeCache to reduce map operations by performing shift_remove first, which simplifies the control flow and improves performance.

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/dht/probe_cache.rs Resolved
@github-actions

github-actions Bot commented Jul 16, 2026 •

Copy link
Copy Markdown

Coverage report

Total: 81.53% (was 81.44%, ▲ +0.09%) — 48709/59746 lines

File Coverage Lines Δ
crates/node/src/dht/probe_cache.rs 96.23% 153/159 new
crates/node/src/metrics.rs 93.04% 829/891 ● 0.00%
crates/node/src/node_origin.rs 90.51% 963/1064 ▲ +1.34%
crates/node/src/runtime/mod.rs 50.07% 1083/2163 ▼ 0.02%
History
Commit Total Δ vs base
2b4c56e 80.61% ▲ +0.08%
25a7ce6 80.61% ▲ +0.08%
4f41578 80.67% ▲ +0.17%
0f64f71 81.22% ▲ +0.08%
3b65dbf 81.44% ▲ +0.11%
f80748d (HEAD) 81.53% ▲ +0.09%

yigitdot and others added 5 commits July 16, 2026 17:49
…ilures

- probe_cache insert doc: MAX_PROVIDERS_PER_HASH as a code span, not an
  intra-doc link (a public method may not link a private const under
  rustdoc -D warnings).
- plan doc: blank lines around lists/fences (MD031/MD032).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
…iew)

Drops the redundant O(1) get before the O(N) shift_remove; the hit path is
now two IndexMap ops. Behaviourally identical — an expired entry is still
evicted before returning None. Covered by the existing LRU/expiry tests.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
…ullOutcome<T>

From the five-agent PR review of #1223:

- probe_cache_hits doc + appendix row: a hit is "the walk STARTED from a
  cache entry", not "lookup+fanout skipped entirely" — the partial-budget
  fall-through re-probes within the same fetch and stays counted as a hit.
- node_pull_no_providers gated behind !attempt_metered in both pull paths,
  restoring its documented exclusivity with node_pull_attempts ("not a
  pull failure") on hit-then-fallthrough fetches that re-discover empty.
- DurableMissCause metric site: exhaustive match instead of ==, so a third
  cause must decide its telemetry (the file's own exhaustiveness doctrine).
- PullOutcome made generic over the payload; open_from_candidates returns
  PullOutcome<(UpstreamPullHeader, NodeProgressivePull)> instead of a bare
  tuple (drops the .await.0 access); the misleading Pin<Box<dyn Future>>
  justification is gone.
- Comment accuracy: staker-filter backstop narrowed to deregistration only
  (ejection/unbonding survive address resolution); invalidate doc no longer
  claims "every provider failed" when only the budgeted prefix was tried;
  KNOWN LIMITATION (#1129) cross-referenced at both budget==0 exits;
  DEFAULT_TTL doc cites ADR 001's second bound (probe_hold_duration);
  rot-prone free-floating 15s literals reworded; provenance tag -> #1223.
- const size tripwire on ProbedProvider (no-evidence-retention invariant).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
…ion metric, window fallthrough, suppressed-entry miss (#1223)

Co-Authored-By: Claude Opus 4.8 <[email protected]>

@altanoruc altanoruc left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewed the positive probe-cache implementation at 4f41578. The shared attempt budget, negative/wedged-provider filtering, cache invalidation, and buffered/progressive-path coverage are well exercised, and the current CI suite is green. I found one blocking ADR/policy regression on cache hits: current active-staker membership is not revalidated before opening the paid stream.

Comment thread crates/node/src/node_origin.rs Resolved
yigitdot and others added 6 commits July 17, 2026 02:37
… 001)

The cache-hit path (cached_candidates) bypassed find_providers, so it
skipped the active-staker filter the cold path applies — a node ejected
or unbonding inside the 15s TTL could win a paid pull the cold path
would deny (addr_resolver is not this guard: the address binding
survives ejection/unbonding, only deregistration clears it). Re-apply
deps.staker_set.is_active on each cached provider, per the ADR.

Requested by review on #1223.

A static-config origin that is not a staker is now skipped on a hit and
falls through to the cold path, where the unfiltered directory fallback
re-serves it: static-only deployments get correctness, not hit
acceleration. Production directories are chain-backed + staker-filtered,
so their origins are stakers and the check is complete.

Existing probe-cache tests now seed the staker set from the providers
they inject (matching production); find_providers still returns empty for
them (no routing entries), so cold-path discovery is unchanged.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
…kerSet

Merged origin/main, which retired the StakerSet::subscribe_changes seam and
StakerChange (#1231, zero production consumers). The #1223 regression test
helper implemented the old trait, so the PR-merge build failed to compile
(unresolved StakerChange import, subscribe_changes not a trait member).
Strip the broadcast field/method; MutableStakerSet now needs only is_active
+ active_nodes. new() is const now that the channel is gone.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
…obe-cache

# Conflicts:
#	crates/node/src/metrics.rs
…-path budget exhaustion

Addresses PR review findings:

- Rewrite the ProbedProvider "no evidence retention" size tripwire comment to
  describe the `size_of <= 48` assert as the review speed-bump it is (4 bytes of
  padding slack let a small field slip past), and name the actual guards: the
  `Copy` derive and the exhaustive struct literal at the write site.
- Fix the `probe_cache_hits` doc (metrics.rs + appendix-observability.md): an
  all-cached-fail hit either falls through cold (budget remaining) OR returns a
  clean miss (budget exhausted, the common case with 10 providers vs a 3 budget),
  counted as a hit either way. The old "falls through" wording was wrong on the
  common path.
- Broaden the `probe_cache_misses` suppression-cause list to include the
  inactive-staker and bad-key filters, not just negative-cache/wedged.
- Add a window-path twin of the buffered budget test: three cached refusers driven
  through `open_progressive_pull` exercise the window path's own `budget == 0`
  short-circuit and `invalidate`, proven at the wire (probes 3→3→6, streams
  3→6→9). Neither statement had test coverage before.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@thiras
thiras dismissed altanoruc’s stale review July 17, 2026 19:43

Dismissing: the requested change (re-check active-staker membership on probe-cache hits) was addressed in 893dac1 + regression test 2d8093b, plus follow-up review-fix commit f80748d. Dismissed by maintainer to unblock merge.

@thiras
thiras merged commit 14f65a4 into main Jul 17, 2026
22 checks passed
@thiras
thiras deleted the feat/1165-positive-probe-cache branch July 17, 2026 19:43
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.

Implement lean positive probe cache (15s TTL, no evidence retention)

3 participants