Skip to content

feat(node): origin-only node policy — decline foreign relay via cached backend probe (#1759) - #1766

Merged
alpergundogdu merged 8 commits into
mainfrom
claude/origin-namespace-verification-cache-9fcad2
Aug 20, 2026
Merged

alpergundogdu merged 8 commits into
mainfrom
claude/origin-namespace-verification-cache-9fcad2

Conversation

@alpergundogdu

@alpergundogdu alpergundogdu commented Aug 20, 2026 •

Copy link
Copy Markdown
Contributor

Origin-only node policy (#1759)

Lets an operator run an origin-only node — one that serves and seeds only its own namespace and never relays foreign content. An origin is just an origin: it serves its own catalog rather than acting as a general CDN edge for others' data (no bandwidth competition, and none of the blacklist/compliance liability of mixing publishers' content).

The own-vs-foreign decision is backend-authoritative: the node asks its own backend (a content-addressed HEAD/HeadObject/stat) whether it holds the object named by a hash. The request's namespaceId is a routing hint, not a trust anchor (ADR 002), so it is never consulted for this decision — the classification cannot be lied to.

The toggle: cache.relay_foreign_namespaces

Node-local; no wire, ABI, or governance surface. The default is role-derived from whether the node has an origin backend configured:

  • Node with an origin ([cache.origin] / [[cache.origins]] set) → an origin → defaults false (origin-only, serve only its own catalog).
  • Node with no origin → a pure relay/cache edge whose only function is relaying → defaults true (relay foreign content for pay).
  • Explicit config always overrides, both directions — an origin operator who also wants relay revenue sets = true; an edge operator who wants origin-only sets = false.

Resolver: relay_foreign_namespaces.unwrap_or(origins.is_empty()).

Commits

  1. feat(cache): split origin-probe memo into positive + short negative TTL — the backend-existence memo gains a long positive TTL (cache.origin_probe_ttl_sec, 15s) and a short configurable negative TTL (cache.origin_probe_negative_ttl_sec, default 2s). The negative TTL bounds how long a stale Absent can hide newly-available own content (~2s vs 15s). Near-free on DoS: a random-hash flood never repeats a hash within any window.
  2. feat(node): origin-only serve policy — the categorical serve gate. When origin-only, serve_stream declines any hash the backend doesn't hold, above the cache-hit branch (so a foreign blob already in cache is also declined), before any discovery, lane accounting, or spend.
  3. feat(node): origin-only nodes advertise backend-held content only — under the toggle, probe has_blob and DHT cold-start announce are restricted to backend-held content, holding the invariant advertise iff will serve (a decline is never read as "advertised but didn't serve").
  4. fix(node): origin-only gate distinguishes foreign-decline from backend fault + fix(node): origin_probe_presence walks the origin chain to catch per-origin faults (addressing PR review) — a dedicated ServeRejectReason::ForeignNamespaceDeclined (wire-maps to NotFound, own metric) so policy declines aren't counted as cache misses; and a 3-way CacheEngine::origin_probe_presence (Present/Absent/Fault) that walks the origin chain itself so a backend fault (transport error or timeout) surfaces as InternalError — not an authoritative signed NotFound that would hide the operator's outage. Fault is not memoized (instant recovery; the 404 DoS bound survives).
  5. feat(config): default relay_foreign_namespaces from node role — the role-derived default described above.

Config

  • cache.relay_foreign_namespaces — role-derived default (origin-only when an origin is configured, relay otherwise); explicit value overrides.
  • cache.origin_probe_negative_ttl_sec — default 2.

Testing

  • New: origin_only_node_declines_a_foreign_hash, origin_only_node_serves_its_own_backend_hash, origin_only_node_declines_a_foreign_blob_already_in_cache, origin_only_node_fault_is_internal_error_not_signed_not_found, origin_only_probe_advertises_backend_only, origin_probe_presence unit tests, split-TTL memo unit test, and three resolver tests for the role-derived default.
  • Full workspace suite green; cargo fmt / cargo clippy --workspace --all-targets clean.

Closes #1759.

🤖 Generated with Claude Code

…ed backend probe

Add cache.relay_foreign_namespaces (default true, restart-required) and gate
serve_stream on it: when false, a hash the node's own backend does not hold
(per the memoized origin_probe_size HEAD probe) is declined as a signed
CacheMiss before any discovery, lane accounting, or spend. The gate sits
above cache.has, so a foreign blob already cached is still declined. The
request's namespace_id stays a routing hint only (ADR 002), never consulted
for this decision.
Copilot AI lite review requested due to automatic review settings August 20, 2026 12:52

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 adds an origin-only node policy toggle that prevents a node from relaying/serving content its own backend cannot prove it holds, and updates the origin-probe memoization logic to use a long positive TTL with a short negative TTL to reduce “fresh content dark time”.

Changes:

  • Split live-origin probe memo TTL into positive TTL (origin_probe_ttl_sec) and negative TTL (origin_probe_negative_ttl_sec, default 2s).
  • Add cache.relay_foreign_namespaces (default true) and thread it through runtime, probe, and client serve paths to enforce the origin-only policy.
  • Add/extend tests and CLI config output to cover and expose the new behavior.

Reviewed changes

Copilot reviewed 17 out of 17 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
crates/node/tests/sighup_signal.rs Updates test config seed to include new cache config fields.
crates/node/tests/probe_warm_reconnect.rs Threads new relay_foreign_namespaces argument into probe handler wiring in tests.
crates/node/tests/probe_loopback.rs Adds origin-only probe test ensuring advertise iff will-serve for backend-held content only.
crates/node/tests/client_loopback.rs Adds origin-only serve-path tests (decline foreign, serve own, decline cached-foreign).
crates/node/tests/anvil_bringup_shutdown_e2e.rs Updates e2e config builder with new cache config fields.
crates/node/src/runtime/reload.rs Adds new cache fields to defaults and marks them restart-required for reload logic.
crates/node/src/runtime/mod.rs Threads policy toggle into handlers and adjusts DHT cold-start seeding under origin-only mode; wires split TTLs into cache.
crates/node/src/handlers/probe.rs Adds relay_foreign_namespaces to probe handler and changes has_blob logic under origin-only.
crates/node/src/handlers/client/mod.rs Adds policy toggle to handler deps/state.
crates/node/src/handlers/client/dispatch.rs Adds serve-stream origin-only gate using backend-authoritative origin probe.
crates/common/src/config/types.rs Adds config schema fields and documentation for split TTL and relay toggle.
crates/common/src/config/resolved.rs Adds resolved config fields for split TTL and relay toggle.
crates/common/src/config/mod.rs Adds defaults and resolver wiring for new config fields.
crates/cli/tests/config_validate.rs Updates CLI config validation test expectations for new fields.
crates/cli/src/commands/config.rs Surfaces relay toggle in validation summary; updates default config template comments; updates default-config tests.
crates/cache/src/origin_probe.rs Implements split TTL memoization (positive vs negative) and adds unit tests.
crates/cache/src/engine.rs Extends origin-probe config plumbing to pass positive+negative TTLs; updates related tests.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@github-actions

github-actions Bot commented Aug 20, 2026 •

Copy link
Copy Markdown

Coverage report

Total: 81.35% (was 81.15%, ▲ +0.20%) — 60620/74518 lines

File Coverage Lines Δ
crates/cache/src/engine.rs 91.85% 3933/4282 ▲ +0.01%
crates/cache/src/lib.rs 100.00% 28/28 ● 0.00%
crates/cache/src/origin_probe.rs 100.00% 165/165 ● 0.00%
crates/cli/src/commands/config.rs 86.47% 537/621 ▲ +0.17%
crates/common/src/config/mod.rs 97.08% 6781/6985 ▼ 0.01%
crates/common/src/config/resolved.rs 100.00% 42/42 ● 0.00%
crates/e2e/src/node.rs 24.79% 120/484 ● 0.00%
crates/node/src/handlers/client/dispatch.rs 85.80% 441/514 ▲ +1.50%
crates/node/src/handlers/client/mod.rs 92.19% 1192/1293 ▲ +0.29%
crates/node/src/handlers/client/wire.rs 97.73% 129/132 ▲ +0.09%
crates/node/src/handlers/probe.rs 86.62% 272/314 ▲ +0.26%
crates/node/src/metrics.rs 94.46% 852/902 ▲ +0.10%
crates/node/src/runtime/mod.rs 47.90% 1094/2284 ▼ 0.33%
crates/node/src/runtime/reload.rs 96.49% 1514/1569 ▼ 0.28%
History
Commit Total Δ vs base
30202ee 81.18% ▲ +0.02%
6788ca0 81.23% ▲ +0.08%
9d55cdd 81.22% ▲ +0.92%
9b289cf (HEAD) 81.35% ▲ +0.20%

alpergundogdu and others added 5 commits August 20, 2026 14:20
…d fault

The origin-only serve gate (#1759) folded every backend probe outcome into
Present/Absent, so a transport error or timed-out HEAD on this node's own
backend signed an authoritative NotFound instead of surfacing InternalError
— hiding an operator's own outage from a paying client and from metrics.
Policy declines were also counted under the generic CacheMiss reason.

Add CacheEngine::origin_probe_presence (a 3-way Present/Absent/Fault probe;
origin_probe_size becomes a thin Fault-folds-to-None wrapper over it, so its
existing callers are unchanged) and ServeRejectReason::ForeignNamespaceDeclined
(wire NotFound, own metric). The gate now falls through on Present, declines
under ForeignNamespaceDeclined on Absent, and refuses with InternalError on
Fault.

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

origin_probe_presence previously delegated to origin_size, whose per-origin
error handling swallows a transport error and tries the next origin,
falling through to Ok(None) once the chain is exhausted — so a connection-
refused/5xx/DNS outage on a single-origin node looked identical to a
genuine 404 and was classified Absent instead of Fault. Only an overall
probe timeout ever reached the Fault arm.

origin_probe_presence now walks self.inner.origins directly (origin_size
itself stays untouched, since other callers depend on its swallow-and-
advance multi-origin fallback): any origin answering Present wins outright;
failing that, any origin answering Err (or the whole walk timing out) is
Fault; only when every origin answers Ok(None) is the result Absent. Fault
is still never memoised.

Adds a cache-engine unit test proving a per-origin transport error (not just
a timeout) yields Fault and is not memoised, and re-adds the node-loopback
test (removed in the prior commit as untestable via origin_size) that now
passes: an origin-only node behind an unreachable http origin refuses with
InternalError, not a signed NotFound.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
…ce-verification-cache-9fcad2

# Conflicts:
#	crates/node/src/metrics.rs
…-only when an origin is configured)

An origin node is not a general proxy: it should serve only its own
catalog by default, avoiding bandwidth competition and the
compliance/liability of mixing other publishers' data. A node with no
origin has no other function than relaying, so it keeps relaying by
default. The resolver now derives the default from whether an origin
backend is configured, instead of a flat true; explicit config still
overrides either way.

The anvil-e2e NodeFixture always renders a `[cache.origin]` table (even
for its "empty" pull-through nodes), so it now pins
relay_foreign_namespaces explicitly to the fixture's intent rather than
falling on the new origin-only default, which would otherwise break
node-to-node relay journeys.
…ce-verification-cache-9fcad2

# Conflicts:
#	crates/node/src/handlers/client/mod.rs
@alpergundogdu
alpergundogdu merged commit 27db4c6 into main Aug 20, 2026
25 checks passed
@alpergundogdu
alpergundogdu deleted the claude/origin-namespace-verification-cache-9fcad2 branch August 20, 2026 15:23
alpergundogdu added a commit that referenced this pull request Sep 18, 2026
) (#2055)

* docs(adr): record proxy-warming vs origin-only policy composition (#1990)

Two deliberate policies interact in a way neither ADR documented: the
client's cold-blob / warming fallback (ADR 037) targets RTT-nearest
non-holders, and an origin-configured node defaults to origin-only
(`relay_foreign_namespaces = false`, #1759) and declines a foreign miss.
The fallback can therefore route a warming attempt to a node that
categorically declines it.

Run through spec discipline, the two policies compose correctly rather
than conflict: proxy warming is a relay-edge mechanism by construction,
and an origin-only node declining a warming pull is the origin-only
policy holding, not a warming failure. The decline collapses to
`NotFound`, the client fails over over the shared pool at the cost of one
round-trip, and pays nothing.

Document the composition:
- ADR 037 gains a "Warming is a relay-edge mechanism" section and a
  Cross-ADR Impact bullet for ADR 002.
- ADR 002 § Retrieval by namespace gains the canonical statement of the
  `relay_foreign_namespaces` role-derived policy (previously code-only,
  referenced obliquely by ADR 041 as "a separate policy").

No mechanism is added. The two options that would (a self-attested probe
flag to pre-filter origin-only nodes, and reversing the #1759 default)
stay out — both add surface to force an optimization that is correctly
not firing. The interaction is already observable: the serving node
counts declines in `decdn_serve_stream_rejected_foreign_declined_total`
(exists since #1766) and the client logs its warming lead and each
failover; the client is an ephemeral CLI with no scrape endpoint, so a
client-side counter would be dead instrumentation.

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

* docs(adr): fix probe-signing and namespace-vs-backend wording (#1990 review)

Two accuracy fixes from PR review:
- ADR 037 said the probe `has_blob` answer is "unsigned"; it is signed
  (EIP-712 `slash_sig` over `{hash, has_blob, rate_per_mb, timestamp_us}`).
  The real point is that `ProbeResponse` carries no policy/role field, so a
  client cannot tell an origin-only node from a relay edge — reworded to say
  exactly that.
- ADR 002 described the origin-only decline in namespace terms, risking the
  implication that `namespaceId` drives the serve/decline decision. The gate
  is backend-authoritative (`origin_probe_presence(hash)`) and never consults
  `namespaceId`, which stays a routing hint (#1525). Reworded to backend
  presence and stated the non-consultation explicitly.

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

---------

Co-authored-by: Claude Opus 4.8 <[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.

Foreign-namespace relay opt-out: origin-only node policy

2 participants