- Category: B. Software Architecture
- English term: Retry Limits and Circuit Breakers
- Related: Uncertain State / In-Doubt State · Watchdog Timer / Watchdog Process · Fallback Chain (Cascading Fallback) · Human-in-the-Loop and Escalation · Free Tier as an Architectural Constraint
General Meaning
External API calls, network requests, and automated tests occasionally fail due to transient glitches. While retrying helps with brief blips, unrestricted retries against a broken server or buggy code cause severe secondary damage.
A Retry Limit sets a hard cap (such as at most 3 attempts) before declaring failure. A Circuit Breaker acts like an electrical breaker: when failures or quota usage cross a threshold, it 'opens the circuit' to block subsequent requests immediately without even attempting execution, preserving quotas and giving downstream systems time to recover.
Why It Matters
- Preventing retry storms: Stops multiple workers from bombarding a struggling service with retries and causing a cascading collapse.
- Preventing cost and quota explosions: Unrestricted retries against metered APIs or rate-limited LLMs can exhaust a full month's quota in minutes.
- Enabling clean escalation to higher tiers or humans: Provides a clear boundary where automated retries stop and higher-tier AI review (
operator_review) takes over.
How the Site Factory Uses It
The Site Factory enforces concrete retry limits and circuit breakers across its pipeline: (1) Automated PR fixes stop after 3 failed attempts, marking the ticket 状態: 保留 (hold) and routing through operator_review; (2) Pipeline review rejections cap at 5 retries per section (requiring a strategy change if the same finding repeats twice, and dropping the failing section after 5 tries so passing sections can still publish); and (3) Service lease renewal relinquishes leadership after 3 consecutive failures so another Mac can fail over.
In addition, (4) mini-queue jobs move failing tasks to failed/ after hitting their cap (learned after a past bug retried 201 times in 8 minutes), while quota exits (42/75) re-queue to another runner; and (5) D1 free-tier circuit breaker halts new task dispatch for the day once reads hit 4M or writes hit 80k (80% of the daily free tier) until UTC midnight.
Caveats & Operational Rules
- Never retry mechanically with the exact same prompt or input: Repeating identical input yields identical failure; the Site Factory requires changing the fix approach after 2 identical findings or escalating one model tier.
- Never disguise a capped failure as success: Do not swallow errors when the retry limit is reached; record
holdorfailed/history honestly so the root cause can be inspected. - Maintain minimal observability while the circuit is open: Even when D1 quota breakers pause new task dispatch, workers still send an empty capability heartbeat every 5 minutes to report liveness and detect the next day's reset.
Related Terms
- Uncertain State / In-Doubt State
- Watchdog Timer / Watchdog Process
- Fallback Chain (Cascading Fallback)
- Human-in-the-Loop and Escalation
- Free Tier as an Architectural Constraint
References
- Book: Michael T. Nygard, *Release It!*, Chapter 5 (Circuit Breakers, Timeouts); Martin Kleppmann, *Designing Data-Intensive Applications*
Verified: 2026-11-08