Skip to content

Circuit breaker for downstream backpressure#37

Merged
Jacobobber merged 1 commit into
mainfrom
feat/circuit-breaker
Jul 8, 2026
Merged

Circuit breaker for downstream backpressure#37
Jacobobber merged 1 commit into
mainfrom
feat/circuit-breaker

Conversation

@Jacobobber

Copy link
Copy Markdown
Owner

Backpressure, from the research plan: a fleet of agents retrying into a struggling downstream makes the outage worse. CircuitBreakerHttpClient wraps any HttpClient (compose it around the retry client, so it counts an outage only after retries are spent):

  • After failure_threshold consecutive outages (5xx or connection-level errors) to a service, the breaker opens and calls fail fast with CircuitOpen for reset_after seconds, not touching the downstream.
  • Then one half-open probe closes it on success or re-opens it on failure.
  • Client errors (401/403/404) are real answers, not outages, and never trip it; any success resets the count.
  • The clock is injected, so the state machine is tested without waiting on real time.

6 new tests: opens after threshold then fails fast, half-open probe closes on success, failed probe re-opens, client errors don't trip, success resets the streak, connection-level errors trip. 279 tests, mypy --strict, ruff (whole repo), catalog-freshness green. Backward compatible; v1.4.0.

After a run of outages (5xx / connection errors) to a service, the breaker
opens and calls fail fast (CircuitOpen) for a cooldown, then a half-open probe
closes or re-opens it. Stops a fleet of agents from hammering a struggling
downstream. Compose it around the retry client so it counts an outage only
after retries are spent. Client errors (401/403/404) are answers, not outages,
and never trip it; a success resets the count; the clock is injected.

279 tests (+6), mypy --strict, ruff (whole repo), catalog freshness all green.
v1.4.0.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@Jacobobber Jacobobber merged commit bac9be0 into main Jul 8, 2026
12 checks passed
@Jacobobber Jacobobber deleted the feat/circuit-breaker branch July 8, 2026 20:13
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.

1 participant