Uh oh!
There was an error while loading. Please reload this page.
feat(dig-node): tier-0 knapsack selector + sub-budget + hysteresis - #152
Merged
Conversation
Add tier0_selector: a pure, deterministic module that picks which
speculative-precache candidates are worth keeping under a small
sub-budget of DIG_NODE_CACHE_CAP, reusing relevance()/RelevanceValue/
should_displace from the child-1 relevance module rather than
reimplementing scoring or hysteresis.
- Candidate{size_bytes, relevance} + select_within_budget: O(n log n)
greedy by value-density (relevance/size), never exceeding the given
budget. Deliberately greedy, not DP: at GiB-scale budgets a DP table
is disproportionate, and greedy under-fills by at most one
candidate's size.
- tier0_budget_bytes: TIER0_BUDGET_FRACTION (0.10) of the whole cache
cap, pure arithmetic over a caller-supplied cap (no I/O in this
module).
- should_displace_tier0: thin named wrapper over should_displace with
the selector's own DEFAULT_HYSTERESIS_MARGIN, so a marginally-better
candidate cannot displace an incumbent and thrash fetch/evict/refetch.
Also fixes two comment-accuracy nits left over from child #1 in
relevance.rs: the xor-weight-dominance comment now states it exceeds
only the ATTACKER-GAMEABLE secondaries (scarcity+demand+recency=0.85),
excluding the operator-controlled pin/pin_adjacent bonuses; the
proximity-map comment now says `hi128 / u128::MAX` to match what the
code actually divides by. No behaviour change.
Bumps: crates/dig-node-core 0.27.0 -> 0.28.0 (MINOR, new export) and
the root workspace [workspace.package].version (the released dig-node
binary) 0.76.0 -> 0.77.0 (MINOR), with Cargo.lock regenerated to match.
Co-Authored-By: Claude <noreply@anthropic.com>Add SPEC.md §7.10b normativley describing tier0_selector's contract (the 10% sub-budget, greedy-by-density selection, and the hysteresis reuse of should_displace) alongside §7.10a's relevance model. Also applies the rustfmt ordering rustfmt itself wants for the new `pub mod tier0_selector;` declaration in lib.rs. Co-Authored-By: Claude <noreply@anthropic.com>
Uh oh!
There was an error while loading. Please reload this page.
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 freeto 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 DIG-Network/dig_ecosystem#1988 — child 3/7 of the tiered relevance-cache epic (dig_ecosystem#1934). Builds on child 1 (
relevance()/should_displace(), merged9fff0cdc).What changed
New pure module
crates/dig-node-core/src/tier0_selector.rs(pub mod tier0_selector;in lib.rs) — the tier-0 selection brain, no I/O:Candidate { size_bytes, relevance }+select_within_budget(...)— 0/1 knapsack via greedy value-density (value ÷ size), O(n log n) (WHY-commented: near-optimal on a GiB-scale budget, DP is wasteful there).size_bytes == 0handled defensively (no divide-by-zero).tier0_budget_bytes(cache_cap)— the tier-0 sub-budget = a FRACTION of the whole cache cap (TIER0_BUDGET_FRACTION = 10%, overridable), never the whole cap, so eager precache can't starve demand-driven tiers. The selected set's total size never exceeds it.should_displace_tier0(...)— thin wrapper over child 1'sshould_displacewithDEFAULT_HYSTERESIS_MARGIN = 0.05, so a marginally-better candidate doesn't displace an incumbent (churn control).Also fixes the two cosmetic comment-accuracy nits deferred from child 1 in
relevance.rs(attacker-gameable-only sum wording;hi128 / u128::MAX) — comment text only, no behaviour change (relevance's 11 unit tests unchanged/green).Scope is only the pure selector — no DHT sampling (child 2), no prefetch loop (child 4), no live-cache wiring.
How verified
cargo fmt --all -- --check→ clean;cargo clippy -p dig-node-core --all-targets --all-features -- -D warnings→ exit 0;cargo build -p dig-node-core→ green.cargo test -p dig-node-core --lib tier0_selector→ 5/5 (greedy-optimal subset, budget fraction, budget-never-exceeded, zero-size no-divide, hysteresis margin).relevance11/11 unchanged.cargo llvm-cov -p dig-node-core --lib):tier0_selector.rs100%; crate total 86.34% lines — above the 80% floor.Note: 9
peer::tests::*/dual_stack_bind_*/ pool-status tests fail in the CI sandbox used for local dev because it can't bind sockets — they are pre-existing and unrelated (reproduced one in isolation; none touchrelevance/tier0_selector). Real CI runners bind sockets, so they run normally here.Version
dig-node-core0.27.0 → 0.28.0 (MINOR — new export); root[workspace.package].version0.76.0 → 0.77.0 (the version-increment gate reads the root);Cargo.lockregenerated.SPEC.md§7.10b adds the normative selector/budget/hysteresis contract.Generated by Claude Code