Skip to content

feat(cache): live http/s3 probe-HEAD discovery for non-pinned origin content (#1130) - #1523

Merged
alpergundogdu merged 3 commits into
mainfrom
claude/origins-blob-probe-optimization-a09ea9
Jul 30, 2026
Merged

alpergundogdu merged 3 commits into
mainfrom
claude/origins-blob-probe-optimization-a09ea9

Conversation

@alpergundogdu

@alpergundogdu alpergundogdu commented Jul 30, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Closes the http/s3 half of the #1130 origin-discovery gap. #1130's origin_held index is enumerate() ∪ pins, and neither http nor s3 enumerates, so for a remote origin the index only ever holds pinned hashes. A non-pinned object sitting in the configured bucket therefore probes false everywhere, and decdn fetch auto-discovery fails outright ("none of the probed node(s) hold the requested blob") — even though the node could serve it reactively.

This adds a per-probe live-HEAD fallback: when the store and the zero-I/O origin_held index both miss, the probe consults the origin directly with a HEAD/HeadObject (Origin::size, no body fetched) and advertises has_blob: true + total_bytes. So a non-pinned bucket object is discoverable on the first probe.

How the hot path stays cheap

Answers are memoised under one TTL — both positive (Present(size)) and negative (Absent). Caching the negative is deliberate: it's what turns a random-hash probe flood into at most one HeadObject per hash per TTL window instead of one per probe. A slow origin is bounded by a per-probe timeout; on overrun the probe answers has_blob: false.

Slash safety

Post-#1512 (phantom-announcement retired, rate-manipulation gated on s.ok == true), a has_blob:false — or a later NotFound if the object vanished between HEAD and serve — is never slashable; the only cost of a stale positive is a local reputation ding, self-limited by the short TTL. No drop-not-sign gymnastics required.

Changes

  • crates/cache/src/origin_probe.rs (new): bounded, lazily-expiring TTL memo with an injected clock — deterministic unit tests, no new dependency, no background sweeper.
  • CacheEngine::origin_probe_size: refused-guard → memo → timeout-bounded live size() → memoise. set_origin_probe_config installs the knobs once at bring-up (restart-required, mirroring max_probe_holds).
  • probe seam (handlers/probe.rs): the live-HEAD fallback runs only when has_blob is still false after the existing index fold — no HEAD is paid when the store or index already answered.
  • config: cache.origin_probe_ttl_sec (15), origin_probe_timeout_ms (2000), origin_probe_memo_capacity (4096) across the raw + resolved layers, with the reload restart-required classification.

Scope

This is discovery only. The serve-side stream-while-store half — the whole-blob TTFB win that streams from the origin to the client while teeing into the store using a publisher-supplied {H}.obao4 outboard — is a larger follow-up (it generalizes the #856 window/voucher loop to a local outboard-backed bao source) and lands as a separate PR.

Testing

  • Memo unit tests: positive/negative memoization, TTL expiry + read-path sweep, capacity bound under live pressure, expired-reclaimed-before-live-eviction, refresh-in-place.
  • Engine tests: live HEAD then memoized (one backend call), negative memoized, refused-never-probes, slow-origin timeout → absent.
  • cargo fmt, cargo clippy --workspace --all-targets, and cargo nextest (cache + common + node, 897 node tests) all green; anvil-e2e compiles. Over-the-wire first-probe discovery is a noted anvil-e2e follow-up.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Added memoized live-origin probing (positive and negative caching) to determine object availability and size when cache index coverage is missing.
    • Added an additional live-origin HEAD fallback during probe handling, skipping further probing when already found.
  • Configuration
    • Added new cache settings: origin probe memo TTL, per-probe timeout, and memo capacity; changes require restart.
  • Tests
    • Added coverage for memoization behavior, refusal short-circuiting, and timeout handling for slow/unavailable origins.

@coderabbitai

coderabbitai Bot commented Jul 30, 2026 •

Copy link
Copy Markdown

Review Change Stack

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Free

Run ID: 6489c1e4-ba68-4423-b84f-4d62a97f56d7

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Walkthrough

Adds bounded, TTL-based positive and negative origin probe memoization, exposes cache engine probe APIs, wires three configuration fields through runtime setup and reload handling, and adds a live-origin fallback in probe handling with timeout and refused-hash behavior.

Changes

Live origin probe flow

Layer / File(s) Summary
Origin probe configuration
crates/common/src/config/*, crates/node/src/runtime/*, crates/node/tests/sighup_signal.rs, crates/node/tests/anvil_bringup_shutdown_e2e.rs, crates/cli/tests/config_validate.rs
Adds optional and resolved TTL, timeout, and memo-capacity fields, default resolution, runtime wiring, test fixture values, and restart-required reload detection.
Origin probe memo structure
crates/cache/src/origin_probe.rs, crates/cache/src/lib.rs
Adds Presence and OriginProbeMemo with positive/negative caching, lazy TTL expiry, bounded capacity, refresh behavior, defaults, and unit tests.
Cache engine probe API
crates/cache/src/engine.rs
Adds engine memo state, origin_probe_size, configurable memo replacement, timeout handling, refused-hash short-circuiting, and integration tests.
Node fallback integration
crates/node/src/handlers/probe.rs
Performs the live-origin size fallback when the existing origin-held lookup finds no blob.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant ProbeHandler
  participant CacheEngine
  participant OriginProbeMemo
  participant ConfiguredOrigin

  ProbeHandler->>CacheEngine: origin_probe_size(hash)
  CacheEngine->>OriginProbeMemo: get(hash)
  alt cached presence
    OriginProbeMemo-->>CacheEngine: Present(size) or Absent
  else cache miss
    CacheEngine->>ConfiguredOrigin: bounded origin_size probe
    ConfiguredOrigin-->>CacheEngine: size or no result
    CacheEngine->>OriginProbeMemo: insert presence with TTL
  end
  CacheEngine-->>ProbeHandler: optional origin size
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

github-actions Bot commented Jul 30, 2026 •

Copy link
Copy Markdown

Coverage report

Total: 80.23% (was 80.15%, ▲ +0.08%) — 54155/67496 lines

File Coverage Lines Δ
crates/cache/src/engine.rs 90.95% 2926/3217 ▲ +0.06%
crates/cache/src/lib.rs 100.00% 28/28 ● 0.00%
crates/cache/src/origin_probe.rs 100.00% 121/121 new
crates/common/src/config/mod.rs 97.05% 6838/7046 ● 0.00%
crates/common/src/config/resolved.rs 100.00% 33/33 ● 0.00%
crates/e2e/src/node.rs 25.60% 118/461 ▼ 0.71%
crates/node/src/dht/chain_origin_directory.rs 70.43% 555/788 ▼ 0.29%
crates/node/src/dht/origin.rs 100.00% 34/34 ▲ +5.00%
crates/node/src/handlers/client/dispatch.rs 89.17% 280/314 ▲ +0.70%
crates/node/src/handlers/client/mod.rs 89.45% 661/739 ▼ 0.13%
crates/node/src/handlers/client/wire.rs 97.73% 129/132 ▲ +2.17%
crates/node/src/handlers/probe.rs 86.36% 266/308 ▲ +0.23%
crates/node/src/metrics.rs 95.35% 963/1010 ▼ 0.01%
crates/node/src/runtime/mod.rs 46.56% 1090/2341 ▲ +0.32%
crates/node/src/runtime/reload.rs 96.39% 1654/1716 ▲ +0.02%
History
Commit Total Δ vs base
096ed1b 80.19% ▲ +0.07%
104f755 80.19% ▲ +0.07%
975cac9 (HEAD) 80.23% ▲ +0.08%

alpergundogdu and others added 3 commits July 30, 2026 15:17
… gate

The `pull_through_require_authorized_origin` gate refused to initiate a backend
pull/warm for a request whose `namespaceId` had no on-chain authorized origin.
But ADR 002 is explicit that the request namespace is a **routing hint, not a
trust anchor** — so using it as a serve-authorization decision was residual: a
husk left after the per-hash on-chain claim layer was removed. ADR 037 already
documented that the gate was namespace-scoped, not operator-scoped (#1368), and
authorized nothing per-content (it admitted a serve for any hash in any namespace
that had *any* registered origin, even one assigned to a different operator).

Remove the gate and everything specific to it: `pull_origin_gate` /
`pull_origin_gate_blocks`, `OriginDirectory::has_origin` (its only consumer),
`ServeRejectReason::UnauthorizedOrigin` and its wire mapping + metric, the
`cache.pull_through_require_authorized_origin` config across all three layers, the
`launch_authorized_origin` e2e fixture, and the three `g_node_08_*` tests that
existed only to exercise the gate.

KEEP the origin directory and `lookup_origins`: that is the legitimate node→node
*routing* mechanism (find which upstream origins to pull from for a namespace),
which ADR 002/022 sanction. Namespace stays routing-only.

Safe by construction: the gate was opt-in and default-off, and the real
protections are untouched — `pull_authorized` (channel ownership, the actual
unpaid-egress guard), the seed-leech caps, `ContentBlacklist`, and BLAKE3
verification. ADRs 037/022/019/011 updated to match.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
…content (#1130)

The #1130 `origin_held` index is built from `enumerate()` ∪ pins, and neither
http nor s3 enumerates — so for remote origins the index holds *pinned* hashes
only. A non-pinned object sitting in the configured bucket therefore probes
`false` everywhere and `decdn fetch` auto-discovery fails outright, even though
the node could serve it reactively.

Close that gap with a per-probe fallback: when the store and the zero-I/O
`origin_held` index both miss, consult the origin directly with a live
`HEAD`/`HeadObject` (`Origin::size`, no body fetched) and advertise
`has_blob: true` + `total_bytes`. Answers — positive `Present(size)` AND
negative `Absent` — are memoised under one TTL, so a random-hash probe flood
costs at most one origin round-trip per hash per window rather than one per
probe. A slow origin is bounded by a per-probe timeout; on overrun the probe
answers `has_blob: false`, which post-#1512 is never slashable (an unservable
advertisement, or a later `NotFound` on the serve, costs only local reputation).

- `crates/cache/src/origin_probe.rs`: bounded, lazily-expiring TTL memo with an
  injected clock (deterministic unit tests, no new dep, no background sweeper).
- `CacheEngine::origin_probe_size`: refused-guard -> memo -> timeout-bounded live
  `size()` -> memoise; `set_origin_probe_config` installs the knobs once at
  bring-up (restart-required, like `max_probe_holds`).
- probe seam: consulted only when `has_blob` is still false after the index fold.
- config: `cache.origin_probe_ttl_sec` (15), `origin_probe_timeout_ms` (2000),
  `origin_probe_memo_capacity` (4096) across raw + resolved layers, with the
  reload restart-required classification.

Serve-side stream-while-store (the whole-blob TTFB win via a publisher `.obao4`)
is the larger follow-up; this PR is discovery only.

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

The settlement/journeys CI jobs build `decdn-node --features anvil-e2e`, which
compiles `tests/anvil_bringup_shutdown_e2e.rs` — a full `ResolvedCache` literal
the default `cargo nextest` never builds. It was missing the three new
`origin_probe_*` fields (E0063). No logic change.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@alpergundogdu
alpergundogdu force-pushed the claude/origins-blob-probe-optimization-a09ea9 branch from 104f755 to 975cac9 Compare July 30, 2026 14:21
@alpergundogdu
alpergundogdu changed the base branch from main to claude/remove-residual-authorized-origin-gate July 30, 2026 14:21
Base automatically changed from claude/remove-residual-authorized-origin-gate to main July 30, 2026 14:35
@alpergundogdu
alpergundogdu merged commit b17ebe3 into main Jul 30, 2026
25 checks passed
@alpergundogdu
alpergundogdu deleted the claude/origins-blob-probe-optimization-a09ea9 branch July 30, 2026 14:57
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