Repository navigation
fix(node): derive pull-through outer deadline so multi-provider fallback survives timeout-shaped failures (#859) - #878
Conversation
…ack survives timeout-shaped failures (#859) The cache-miss pull-through outer deadline (`try_pull_through`) and the per-candidate stream timeout (`NodeOriginConfig.pull_timeout`) were both sourced from `cache.node_pull_timeout_sec`, so they expired together. When candidate #1 stalled, the outer `tokio::time::timeout` cancelled the whole `NodeOrigin::fetch` before the `MAX_PROVIDER_ATTEMPTS` loop reached candidates #2..N — the advertised N-provider fallback only worked for fast failures. Fix (Strategy A): keep `node_pull_timeout_sec` as the per-upstream budget and derive the outer deadline as `MAX_PROVIDER_ATTEMPTS × per + slack` via `selection::outer_pull_deadline`, so the outer backstop can never preempt the fallback loop. The config field keeps its documented per-upstream meaning; no new knob. Also adds background cache-fill: when the foreground deadline fires, the handler spawns a detached, budget-bounded, cancellation-token'd task to keep warming the cache from a slow-but-available upstream (deduped per hash by a guard-released in-flight set; cancelled at shutdown alongside gossip). Three new metrics: node_pull_through_background_{spawned,succeeded,failed}. Tests: a handler-level regression test proving the slow pull is abandoned under the old equal-deadline wiring but completes under the derived deadline; a NodeOrigin stall-fallthrough test; the derivation guard (outer > N × per_candidate); and the background-fill dedup contract. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
There was a problem hiding this comment.
Code Review
This pull request introduces a detached background cache-fill mechanism to warm the cache from slow upstreams after a foreground delivery deadline expires, and updates the outer pull-through deadline derivation to prevent premature preemption of the provider fallback loop. It also adds corresponding metrics, configuration updates, and comprehensive tests. The review feedback suggests enhancing the resilience of the background fill lock management by properly handling poisoned mutexes in both the BgInflightGuard drop implementation and the arm_background_fill function.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
Coverage reportTotal: 85.87% (was 85.93%, ▼ 0.06%) — 34407/40069 lines
History
|
There was a problem hiding this comment.
Pull request overview
This PR fixes node-to-node cache-miss pull-through fallback being prematurely cancelled under timeout-shaped failures by deriving a larger outer pull-through deadline from the per-candidate budget, and adds an optional detached background cache-warm path to continue populating the cache after the foreground deadline fires.
Changes:
- Derive handler-level outer pull-through deadline as
MAX_PROVIDER_ATTEMPTS × per_candidate + slackviaselection::outer_pull_deadline, and wire it in runtime. - Add handler-driven detached background cache-fill on foreground timeout, with per-hash dedup and new metrics.
- Add regression tests covering stalled-first-candidate fallthrough, derived outer deadline behavior, and background-fill dedup.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| crates/node/src/selection.rs | Adds outer_pull_deadline + slack constant and arithmetic regression tests. |
| crates/node/src/runtime/mod.rs | Wires derived outer deadline into attach_pull_through and attaches background-fill with shutdown cancellation. |
| crates/node/src/handlers/client.rs | Implements background-fill plumbing + timeout-path race handling and metrics/logging updates. |
| crates/node/src/metrics.rs | Adds counters for background fill spawned/succeeded/failed and helper increment methods. |
| crates/node/tests/node_origin_pull.rs | Adds stalled-provider integration test and a configurable per-candidate timeout helper. |
| crates/node/tests/client_loopback.rs | Adds handler-level regression test ensuring derived outer deadline allows slow pull to complete. |
| crates/common/src/config/types.rs | Clarifies node_pull_timeout_sec as a per-upstream budget (outer is derived). |
| crates/common/src/config/mod.rs | Updates default timeout docs to reflect derived outer deadline semantics. |
| crates/cli/src/commands/config.rs | Updates example config comment to describe derived overall deadline behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…t over-count & log wording (#859) Code-review follow-ups on the background cache-fill path: - BgInflightGuard::drop and arm_background_fill now recover a poisoned dedup lock via PoisonError::into_inner instead of silently skipping cleanup / declining to spawn — the claim is always released and the feature stays functional after an unrelated panic. (Gemini) - node_pull_through_timeout is now metered AFTER the race `has` check, so a blob that lands in the store right as the deadline fires is served without over-counting an abandoned-pull timeout. (Copilot) - The background-fill failure log no longer says "found no source" for a store/I/O fault; the message is neutral and the cause rides in `error`. (Copilot) Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Problem
Closes #859. Node-to-node cache-miss pull-through's advertised N-provider fallback was dead under timeout-shaped failures. The outer delivery deadline (
ClientHandler::try_pull_through, wrapping the wholediscover → probe → rank → pullfetch in onetokio::time::timeout) and the per-candidate stream timeout (NodeOriginConfig.pull_timeout) were both sourced from the samecache.node_pull_timeout_secvalue. So when candidate #1 stalled, both clocks expired together and the outer timeout cancelled the entireNodeOrigin::fetchat the instant candidate #1's own timeout fired — candidates #2..N (MAX_PROVIDER_ATTEMPTS = 3) were never tried. Fallback only worked for fast failures (connect refused, immediate error). Introduced with #831/#834.Fix
Part 1 — derived outer deadline (Strategy A). Keep
node_pull_timeout_secas the documented per-upstream budget; derive the outer deadline asMAX_PROVIDER_ATTEMPTS × per + PULL_THROUGH_OUTER_SLACKvia the newselection::outer_pull_deadline, wired atruntime/mod.rsattach_pull_through. The outer backstop can no longer preempt the fallback loop. Zero regression risk for a slow-but-healthy single upstream; no new config knob.Part 2 — background cache-fill. When the foreground deadline fires, the handler spawns a detached, budget-bounded,
CancellationToken-cancelled task to keep warming the cache from a slow-but-available upstream for future requests (leaning onCacheEngine::populate's existing single-flight). A handler-layer in-flight set deduplicates per hash; the claim and its release are fused into oneOption<BgInflightGuard>so the dedup invariant is type-enforced. Cancelled at shutdown alongsidegossip_shutdown. New metrics:node_pull_through_background_{spawned,succeeded,failed}.Tests
pull_through_outer_deadline_accommodates_a_slow_pull(handler-level regression) — drives a real authorized request against aSlowOrigin(1.5s); asserts the store stays empty under the pre-node: pull-through outer deadline equals the per-candidate stream timeout — multi-provider fallback is dead under timeout-shaped failures #859outer == perwiring but is filled under the derived deadline. The one test that fails ifattach_pull_throughregresses to the per-candidate value.node_origin_pull_falls_through_a_stalled_candidate— a staller that ranks first, answers the probe, then stalls the stream; asserts the loop abandons it (scoredUnreachable) and delivers from the honest fallback (scored clean).outer_pull_deadline_exceeds_all_per_candidate_budgets+ edges — the arithmetic root-cause guard (outer > N × per_candidate, saturation).background_fill_dedup_and_rearm— claim → dedup → re-arm-after-release contract.Review
A multi-agent review (code/tests/comments/silent-failures/type-design) ran on the branch; all Critical/Important findings were addressed — including the originally-too-weak regression test, a swallowed
cache.hasstore fault (now metered+logged), and thearm/guard fusion. Deferred (advisory, noted): full background-fill behavioral suite and a dedicatednode_pull_background_timeout_secknob.Verification
cargo clippy -p decdn-node -p decdn-common -p decdn-cli --all-targets— cleancargo nextest run -p decdn-node— 573 passed;-p decdn-cli -p decdn-common— 539 passedcargo fmt --check— clean; pre-commit (fmt/clippy/doc/deny) — passed🤖 Generated with Claude Code