Skip to content

docs(cache): correct stale retry-amplification note and pin the circuit-breaker bound - #1619

Merged
alpergundogdu merged 1 commit into
mainfrom
claude/cache-retry-amplification-bound
Aug 5, 2026
Merged

alpergundogdu merged 1 commit into
mainfrom
claude/cache-retry-amplification-bound

Conversation

@alpergundogdu

@alpergundogdu alpergundogdu commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Issue #1615 flags the retry amplification at crates/cache/src/retry.rs: N concurrent waiters coalescing on one missing hash can each, in turn, become the owner and run a full retry budget against a down origin — up to N sequential budgets — and the module comment called the shared retry-budget "not implemented" and asked whether the trade-off needs a bound.

Finding: it already has one, and the comment was stale. The comment predates the per-origin circuit-breaker (#963, circuit_breaker.rs). Each budget-exhaustion against a down origin records one Unavailable outcome; after failure_threshold consecutive exhaustions the breaker trips OPEN and every later waiter short-circuits before the retry loop. So the worst case is failure_threshold full budgets per origin per cooldown window — a constant, independent of N — not O(N).

The design call (why not a tighter per-hash single-flight)

The triage suggested a watch/semaphore guard that shares one owner's failure with all waiters so not even failure_threshold budgets run. That is unsafe here and is why I did not implement it:

  • Coalesced waiters do not share origin reach. populate_local (cache: reactive local-origin pull-through is coupled to node_to_node_pull_through_enabled #1116) touches the operator's local origins only; get / populate walk the full chain including the paid Peer origin. Both coalesce on the same hash-keyed in-flight map.
  • Across concurrent requests these interleave (see handlers/client/dispatch.rs — one client can be at the try_local_populate stage while another reaches try_pull_through), so a populate_local owner and a full-chain waiter genuinely coalesce.
  • Re-election is load-bearing: a local-only owner's NotFound must not short-circuit a full-chain waiter that could still succeed via Peer. Sharing the owner's failure blindly would turn that into a wrong answer.

A correct shared-failure design would have to be origin-reach-aware — real complexity on a hot, cancellation-sensitive path — for a benefit that overlaps almost entirely with what the breaker already sheds. Not worth the risk. A maintainer who disagrees can weigh in, but the safe, honest fix is to make the existing bound explicit and tested.

Changes

  • retry.rs module doc — rewritten to describe the real bound (the cache: CacheEngine has no circuit-breaker for origin pull-through when the origin returns repeated errors, causing every cache-miss to incur full retry backoff even during a sustained origin outage #963 breaker) and to document why the shared-budget variant is deliberately not implemented.
  • tests/pull_through.rs — the old coalesced_owner_exhaustion_bounded_by_serial_owner_count used N_WAITERS == failure_threshold, so the breaker never actually short-circuited a waiter and its assertion only reproved the O(N) worst case (and its comment framed the amplification as an accepted unbounded trade-off, contradicting reality). Replaced with coalesced_owner_exhaustion_bounded_by_circuit_breaker, which sets N_WAITERS = 12 > failure_threshold = 5 and pins both directions:
    • breaker disabled → fetches == N * (1 + max_retries) (exactly the O(N) worst case);
    • breaker enabled (default) → fetches <= failure_threshold * (1 + max_retries) and strictly < N * (1 + max_retries).
      This is the assertion that would regress to O(N) if the breaker were ever unwired from pull-through.
  • Added a build_engine_with_retry_and_breaker test helper so the two breaker policies can be compared.

No production behavior changes — this is a documentation correction plus a regression test that locks in the existing (previously only emergent, untested) bound.

Testing

  • cargo nextest run -p decdn-cache — 324 passed, 0 failed.
  • The new test proves the bound bites: with the breaker enabled the assertion bounded < O(N) only holds because waiters short-circuit after the threshold; the breaker-disabled arm asserts the exact == O(N) fallback.
  • cargo clippy -p decdn-cache --all-targets — clean; cargo fmt -- --check — clean; pre-commit hooks (fmt, clippy, doc, deny) — passed.

Closes #1615

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Documentation

    • Expanded guidance on retry amplification, circuit-breaker limits, cooldown behavior, and fallback handling.
  • Tests

    • Added coverage for configurable circuit-breaker policies.
    • Verified that disabled breakers can trigger full retry amplification, while the default policy limits fetch attempts.
    • Confirmed callers continue receiving the expected origin error.

…bound (#1615)

The retry.rs coalescing note claimed the N-concurrent-waiters retry
amplification was an unbounded, accepted trade-off with "no shared
retry-budget implemented". That predates the per-origin circuit-breaker
(#963), which already bounds it: after `failure_threshold` consecutive
budget-exhaustions the breaker trips OPEN and later waiters short-circuit
before the retry loop, so the worst case is a constant number of full
budgets per origin per cooldown window, independent of N.

A tighter per-hash "share the owner's failure to all waiters" single-flight
is deliberately not done: coalesced waiters do not share origin reach
(a `populate_local` owner touches local origins only, while a `get` /
`populate` waiter has the full chain including the paid `Peer` origin),
and re-election is load-bearing there — a local-only owner's NotFound must
not short-circuit a full-chain waiter that could still succeed via Peer.

- Rewrite the retry.rs module doc to describe the real bound and why the
  shared-budget variant is unsafe here.
- Strengthen the coalescing exhaustion test into
  `coalesced_owner_exhaustion_bounded_by_circuit_breaker`, now with
  N_WAITERS (12) > failure_threshold (5) so the breaker must shed load,
  and pinning both directions: breaker-disabled gives exactly the O(N)
  worst case, breaker-enabled caps fetches at failure_threshold * budget
  and strictly below O(N).
- Add a `build_engine_with_retry_and_breaker` test helper so the two
  breaker policies can be compared.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Copilot AI lite review requested due to automatic review settings August 5, 2026 15:09
@coderabbitai

coderabbitai Bot commented Aug 5, 2026 •

Copy link
Copy Markdown

Review Change Stack

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Free

Run ID: a17e537d-a9e4-44f8-b812-9530c8afe8e9

📥 Commits

Reviewing files that changed from the base of the PR and between 0f1be9c and 4721ef3.

📒 Files selected for processing (2)
  • crates/cache/src/retry.rs
  • crates/cache/tests/pull_through.rs

Walkthrough

The change adds configurable circuit-breaker setup to cache retry tests. It verifies retry amplification with disabled breakers, bounded fetches with default breakers, retry ordering, and OriginError results. Coalescing documentation describes these behaviors.

Changes

Retry amplification

Layer / File(s) Summary
Configurable circuit-breaker test setup
crates/cache/tests/pull_through.rs
The test helpers accept an explicit circuit-breaker policy. The existing helper continues to use the default policy.
Retry amplification and breaker bounds
crates/cache/tests/pull_through.rs, crates/cache/src/retry.rs
The test compares disabled and default breaker behavior, checks retry ordering, and verifies OriginError results. The documentation describes owner re-election, retry amplification, breaker limits, and origin-reach differences.

Estimated code review effort: 3 (Moderate) | ~20 minutes


Note

🎁 Summarized by CodeRabbit Free

Your organization is on the Free plan. CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please upgrade your subscription to CodeRabbit Pro by visiting https://app.coderabbit.ai/login.

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Aug 5, 2026

Copy link
Copy Markdown

Coverage report

Total: 80.32% (was 80.30%, ▲ +0.02%) — 57109/71103 lines

File Coverage Lines Δ
crates/cache/src/retry.rs 80.26% 187/233 ● 0.00%
History
Commit Total Δ vs base
4721ef3 (HEAD) 80.32% ▲ +0.02%

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 corrects stale documentation around cache-miss retry amplification in decdn-cache by documenting the existing per-origin circuit-breaker bound, and updates the integration test suite to lock in that bound (and its breaker-disabled O(N) fallback) as a regression check.

Changes:

  • Update crates/cache/src/retry.rs module docs to reflect that retry amplification is bounded by the per-origin circuit-breaker, and document why a per-hash shared-budget approach is intentionally not implemented.
  • Replace the prior coalescing/retry amplification test with a two-arm test that asserts exact O(N) behavior when the breaker is disabled and a constant bound when the breaker is enabled.
  • Add a test helper to build a CacheEngine with an explicit CircuitBreakerPolicy so the enabled/disabled behaviors can be compared directly.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
crates/cache/src/retry.rs Updates module documentation to describe the real retry-amplification bound via the per-origin circuit-breaker and the rationale for not sharing failures across origin-reach variants.
crates/cache/tests/pull_through.rs Reworks the coalescing amplification test to pin both the breaker-disabled O(N) behavior and the breaker-enabled constant bound; adds a helper to configure breaker policy in tests.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@alpergundogdu
alpergundogdu merged commit 65722b1 into main Aug 5, 2026
26 checks passed
@alpergundogdu
alpergundogdu deleted the claude/cache-retry-amplification-bound branch August 5, 2026 15:55
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.

cache retry amplification: N waiters can each run a full retry budget

2 participants