Repository navigation
feat(cache,node): pluggable admission & eviction policies (ADR 040) - #1757
Merged
alpergundogdu merged 16 commits intoAug 20, 2026
Merged
Conversation
…ngine gains generic segment primitives Co-Authored-By: Claude Opus 4.8 <[email protected]>
…utrality Exercises the real CacheEngine + eviction::sweep driver (not policy structs in isolation): tinylfu admission caps probation footprint and promotes a twice-requested blob to Main; tinylfu eviction ranks a primed hot blob ahead of a cold burst; and lru/always defaults reproduce a golden LRU sequence end to end.
Documents the shipped signals-in/decisions-at-sweep admission and eviction policy architecture (AdmissionPolicy, EvictionPolicy, FrequencyEstimator, W-TinyLFU, probationary admission) as ADR 040, replacing the LRU-only eviction appendix it supersedes. Repoints every cross-reference to the appendix, in architecture.md's reading order and appendices index, appendix-observability.md, 005-protocol.md, 022-content-discovery.md, the ADR Makefile's book build list, and the pre-launch alternatives history file.
Adds ADR 040 (Pluggable Cache Admission and Eviction Policies), documenting the shipped signals-in/decisions-at-sweep architecture: AdmissionPolicy/EvictionPolicy/FrequencyEstimator traits, the shared W-TinyLFU estimator, probationary admission with sweep-time promotion, and the whole-blob-only reclaim boundary. Repoints every cross-reference to the now-deleted eviction appendix: architecture.md's reading order and appendices index, appendix-observability.md, 005-protocol.md, 022-content-discovery.md, the ADR Makefile's book build list, and the pre-launch alternatives history file.
Rewords four "prior [...] behavior" phrasings that narrated a before/after story against the live `lru`/`always` defaults this same ADR describes, so each sentence reads as present-tense canon on its own.
…ix refs; validate promotion_threshold Serve paths now emit the ADR 040 hit signal exactly once per served request. Split touch into pub observe_hit (recency + frequency observe) and private record_access (recency only): deliver and serve_leg call observe_hit once at successful completion, fill paths (populate_inner) only record_access, and get keeps the full signal. This fixes hot resident blobs never accumulating frequency, without double-counting a miss that fills and serves. Also: repoint 12 stale appendix-blob-cache-eviction.md doc refs to ADR 040; reject cache.tinylfu.promotion_threshold = 0 at config load; add ADR known-limitation note on the probation-cap under-count; reconcile ADR serve-signal wording to match the code. Co-Authored-By: Claude Opus 4.8 <[email protected]>
There was a problem hiding this comment.
Pull request overview
This PR implements ADR 040 by making cache admission and eviction policy pluggable in the cache crate while keeping policy semantics out of the engine, and wiring policy selection/config into the node runtime and operator-facing docs.
Changes:
- Add
AdmissionPolicy/EvictionPolicy/FrequencyEstimatortraits plus default (always/lru) andtinylfuimplementations, and extendCacheEnginewith segment metadata + a hit-signal hook. - Wire policy selection and TinyLFU tuning via config (
cache.{admission_policy,eviction_policy},[cache.tinylfu]) and treat policy changes as restart-required in node reload logic. - Update ADR/docs to retire the prior blob-cache eviction appendix and document ADR 040 + the new configuration surface.
Reviewed changes
Copilot reviewed 27 out of 27 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| crates/node/tests/sighup_signal.rs | Updates test resolved-config seed with new cache policy fields. |
| crates/node/src/runtime/reload.rs | Adds resolved defaults for new policy fields + marks them restart-required. |
| crates/node/src/runtime/mod.rs | Wires estimator/admission/eviction policy selection into bring-up; injects policy into eviction task. |
| crates/node/src/runtime/eviction.rs | Updates driver to delegate ordering/decisions to injected EvictionPolicy and adds end-to-end policy tests. |
| crates/node/src/handlers/client/serve_leg.rs | Emits cache hit-signal on successful completion of served request. |
| crates/node/src/handlers/client/delivery.rs | Emits cache hit-signal on successful completion of served request. |
| crates/common/src/config/types.rs | Adds config schema for policy selectors + [cache.tinylfu] tuning knobs. |
| crates/common/src/config/resolved.rs | Adds resolved fields for policy selectors + resolved TinyLFU knobs. |
| crates/common/src/config/mod.rs | Adds defaults/constants + resolver validation for policy selector names and TinyLFU params. |
| crates/cli/tests/config_validate.rs | Updates CLI config-validation tests for new resolved fields. |
| crates/cli/src/commands/config.rs | Documents new cache policy settings in default config template + updates tests. |
| crates/cache/src/probe_hold.rs | Updates docs to point at ADR 040 references. |
| crates/cache/src/policy/tinylfu.rs | Adds TinyLFU estimator + probation admission + TinyLFU eviction policy. |
| crates/cache/src/policy/sketch.rs | Adds count-min sketch implementation keyed on content hashes. |
| crates/cache/src/policy/mod.rs | Introduces policy traits, shared context structs, and re-exports. |
| crates/cache/src/policy/lru.rs | Adds behavior-preserving LruEviction and AlwaysAdmit implementations. |
| crates/cache/src/metrics.rs | Updates eviction/health metric section docs to reference ADR 040. |
| crates/cache/src/lib.rs | Exposes new policy module and re-exports policy traits/types. |
| crates/cache/src/engine.rs | Adds admission + frequency estimator plumbing; adds in-memory segment membership + hit signal semantics. |
| adr/Makefile | Adds ADR 040 and removes retired blob-cache eviction appendix from book build. |
| adr/architecture.md | Links ADR 040 from the Operations chapter; removes retired appendix reference. |
| adr/appendix-observability.md | Repoints eviction-related references from retired appendix to ADR 040. |
| adr/appendix-blob-cache-eviction.md | Removes retired appendix (replaced by ADR 040). |
| adr/040-cache-policy.md | Adds ADR 040 describing the pluggable policy architecture and acceptance criteria. |
| adr/022-content-discovery.md | Updates pinning reference from retired appendix to ADR 040. |
| adr/005-protocol.md | Updates probe-hold reference from retired appendix to ADR 040. |
| adr/_history/alternatives-pre-launch.md | Updates historical reference to point at ADR 040. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Coverage reportTotal: 81.09% (was 80.84%, ▲ +0.24%) — 59628/73537 lines
History
|
…comments The anvil-e2e-gated ResolvedCache literal in anvil_bringup_shutdown_e2e.rs missed the three new cache-policy fields; default cargo nextest skips that feature so it slipped past local runs and broke CI clippy (--all-features) and the anvil settlement compile. Also addresses the PR review: - Move observe_hit after the terminal StreamEnd frame is written on both serve paths (delivery, serve_leg), so a serve that fails to finish cleanly is not counted. - Repoint stale "LRU eviction driver" doc comments to policy-ranked wording (eviction.rs module docs, runtime/mod.rs, config/types.rs); the driver now executes the injected EvictionPolicy. Co-Authored-By: Claude Opus 4.8 <[email protected]>
…ook, segment ordering, free default path - Warn at bring-up when admission_policy=tinylfu but eviction_policy!=tinylfu: promotion and the probation cap live only in TinyLfuEviction::plan, so with lru eviction the probation labels are inert and the estimator runs for no effect. Document the coupling in ADR 040 (the two selectors are chosen independently but tinylfu admission depends on tinylfu eviction). - Remove the never-invoked EvictionPolicy::on_access hook and its TinyLfu override; correct the plan() doc that referenced it. Observes route through the shared FrequencyEstimator, which frequency policies read directly. - admit_bao_stream: label the segment only after protect_partial succeeds, so a failed protect leaves no stale membership entry for an unprotected blob. - observe_hit: clone the estimator Option only via a double-deref of the load() guard, so the default (no-estimator) path does no Arc clone / refcount roundtrip, instead of load_full()'s unconditional outer-Arc clone. Co-Authored-By: Claude Opus 4.8 <[email protected]>
alpergundogdu
deleted the
claude/cdn-eviction-admission-policies-11802e
branch
August 20, 2026 09:27
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.
Closes #1754.
Introduces pluggable cache admission & eviction policies (ADR 040). deCDN caches while serving but previously had no admission policy and only recency-only, whole-blob eviction. This makes both decisions pluggable and adds a real frequency/heat policy.
Architecture — signals in, decisions at the sweep
set_segment/segment_of/segment_bytes). Segment membership is pure in-memory metadata; the engine reads no frequency and runs no promotion.AdmissionPolicydecides a segment instantly at store time.EvictionPolicy::plan(ctx) -> { evict, promote }is the single sweep-time decision; the driver is a dumb executor. No tag mutation between sweeps.always+lrureproduce prior behavior exactly.cache.admission_policy/cache.eviction_policy=always|lru|tinylfu, plus[cache.tinylfu]params.Key correctness properties
deliverand the node→node serve-leg emit exactly one sighting per completed served request, so a hot resident blob accumulates frequency and promotes (fills alone only record recency; a fill-and-serve miss counts once).observe, so a first-ever request lands inProbationandpromotion_threshold = Nmeans "admit to Main after N prior sightings."Scope / limits
gc_interval_sec=0reclaim hole and missing write-path backpressure are carried forward, out of scope.Docs
ADR 040 added; the
appendix-blob-cache-evictionis retired and all references repointed.Testing
Full workspace suite: 2752 passed, 0 skipped (anvil-e2e gated as in CI); clippy/fmt clean.
Follow-ups (separate issues)
🤖 Generated with Claude Code