Repository navigation
feat(node): origin-only node policy — decline foreign relay via cached backend probe (#1759) - #1766
Merged
alpergundogdu merged 8 commits intoAug 20, 2026
Conversation
…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.
There was a problem hiding this comment.
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(defaulttrue) 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.
Coverage reportTotal: 81.35% (was 81.15%, ▲ +0.20%) — 60620/74518 lines
History
|
…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
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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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'snamespaceIdis 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_namespacesNode-local; no wire, ABI, or governance surface. The default is role-derived from whether the node has an origin backend configured:
[cache.origin]/[[cache.origins]]set) → an origin → defaultsfalse(origin-only, serve only its own catalog).true(relay foreign content for pay).= true; an edge operator who wants origin-only sets= false.Resolver:
relay_foreign_namespaces.unwrap_or(origins.is_empty()).Commits
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 staleAbsentcan hide newly-available own content (~2s vs 15s). Near-free on DoS: a random-hash flood never repeats a hash within any window.feat(node): origin-only serve policy— the categorical serve gate. When origin-only,serve_streamdeclines 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.feat(node): origin-only nodes advertise backend-held content only— under the toggle, probehas_bloband 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").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 dedicatedServeRejectReason::ForeignNamespaceDeclined(wire-maps toNotFound, own metric) so policy declines aren't counted as cache misses; and a 3-wayCacheEngine::origin_probe_presence(Present/Absent/Fault) that walks the origin chain itself so a backend fault (transport error or timeout) surfaces asInternalError— not an authoritative signedNotFoundthat would hide the operator's outage.Faultis not memoized (instant recovery; the 404 DoS bound survives).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— default2.Testing
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_presenceunit tests, split-TTL memo unit test, and three resolver tests for the role-derived default.cargo fmt/cargo clippy --workspace --all-targetsclean.Closes #1759.
🤖 Generated with Claude Code