Circuit breaker for downstream backpressure#37
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Backpressure, from the research plan: a fleet of agents retrying into a struggling downstream makes the outage worse.
CircuitBreakerHttpClientwraps anyHttpClient(compose it around the retry client, so it counts an outage only after retries are spent):failure_thresholdconsecutive outages (5xx or connection-level errors) to a service, the breaker opens and calls fail fast withCircuitOpenforreset_afterseconds, not touching the downstream.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.