Skip to content

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

Closed

Description

@alpergundogdu

When an origin is fully unavailable, every cache miss goes through the full retry cycle (up to 3 retries with exponential backoff up to 10s), serializing the backoff cost across all concurrent misses with no way to fast-fail until the origin recovers. A per-origin half-open circuit-breaker would let the cache fail fast and shed load during outages.


Filed via GitDailyReporterBot

Activity

  1. added
    kind:bug
    kind:feature
    prio:high
    on Jun 22, 2026
  2. github-actions commented on Jun 22, 2026

    @github-actions

    🎯 Triage report

    The CacheEngine in crates/cache has no circuit-breaker for origin pull-through. During a sustained origin outage, every concurrent cache-miss waiter can run its own full retry budget sequentially (up to N budgets × 3 retries × 10 s backoff), amplifying latency and load rather than failing fast. The fix is a per-origin half-open circuit-breaker that short-circuits new pull attempts while the circuit is open.

    Notably, crates/cache/src/retry.rs already documents this exact amplification as a known trade-off: "a sustained outage can produce up to N sequential retry budgets across N concurrent waiters. Accepted as a known trade-off: bounding the amplification would require a shared retry-budget across waiters, which is not implemented." This issue is the natural next step.

    📊 Assessment

    Dimension Value Reasoning
    Type unchanged Could not query org issue types (403)
    Labels unchanged Existing bug, enhancement, technical, high are all accurate
    Coding agent Suitable Scope is self-contained to crates/cache; requirements and success criteria are well-defined; no cross-crate design decisions needed

    🔗 Similar issues

    💡 Notes and suggestions

    Current state (from code)

    crates/cache/src/retry.rs already acknowledges the problem in a doc comment but defers it. The amplification bound is N * (1 + max_retries) * max_backoff_per_attempt in the worst case across N concurrent waiters for the same hash, after coalescing breaks down post-exhaustion.

    CacheEngine::Inner.origins is Vec<Arc<dyn Origin>> with no per-origin state. The circuit-breaker state would live alongside this.

    Suggested implementation approach

    1. State struct — Add a OriginCircuitBreaker struct per-origin (keyed by index or Arc identity in a parallel Vec or HashMap<usize, ...>):

      • State: Closed | Open { until: Instant } | HalfOpen
      • consecutive_failures: u32
      • Config: failure_threshold (e.g. 5), probe_interval (e.g. 30 s)
    2. Integration point — In CacheEngine::pull_through (or wherever run_with_retry is called per-origin), check the breaker before issuing any attempt:

      • Closed → proceed normally; on OriginPullError::Transient increment counter; on success reset counter.
      • Open and Instant::now() < until → immediately return OriginPullError::Permanent (or a new CircuitOpen variant) so the fallback-to-next-origin logic can proceed.
      • Open and cooldown elapsed → transition to HalfOpen, allow one probe attempt; success → Closed; failure → re-Open with reset timer.
    3. Config — Extend RetryPolicy in crates/config-types with optional circuit-breaker fields (circuit_breaker_threshold, circuit_breaker_probe_interval_secs). Default to off or conservative values.

    4. Metrics — Expose circuit_open_total and circuit_probe_success_total / circuit_probe_failure_total counters via CacheMetrics in crates/cache/src/metrics.rs.

    5. Tests — Add a unit test in crates/cache/tests/ that configures a mock origin that always fails, fires N concurrent get calls, and asserts that origin is contacted at most threshold + 1 probe times rather than N * max_retries times.

    Sub-tasks checklist

    • Add OriginCircuitBreaker state machine (Closed / Open / HalfOpen) to crates/cache
    • Thread per-origin breaker state through CacheEngine::Inner
    • Gate run_with_retry calls on breaker check in the pull-through path
    • Add circuit_breaker_threshold + circuit_breaker_probe_interval_secs to RetryPolicy in crates/config-types
    • Expose circuit state metrics in CacheMetrics
    • Unit/integration tests covering open→half-open→closed transitions under concurrent load

    Generated by Agentic Triage for issue #963 · ◷

    Add this agentic workflows to your repo

    To install this agentic workflow, run

    gh aw add githubnext/agentics/workflows/issue-triage.md@94ec5db57374c5b04a4b8eef8b4413f9af44d63f
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind:bugkind:featureprio:high

Type

No type

Fields

Priority

None yet

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions