Skip to content

feat(beta): add CircuitBreakerMiddleware for LLM failure isolation#2532

Open
amabito wants to merge 2 commits intoag2ai:mainfrom
amabito:feat/circuit-breaker-middleware
Open

feat(beta): add CircuitBreakerMiddleware for LLM failure isolation#2532
amabito wants to merge 2 commits intoag2ai:mainfrom
amabito:feat/circuit-breaker-middleware

Conversation

@amabito
Copy link
Copy Markdown
Contributor

@amabito amabito commented Mar 31, 2026

Why are these changes needed?

Extracts the circuit breaker from GovernanceMiddleware (#2501, closed) into
a standalone middleware. Three states (CLOSED, OPEN, HALF_OPEN), atomic probe
claiming for the recovery path, and proper CancelledError handling that
releases the probe without recording a failure.

Same motivation as the BudgetMiddleware split (#2531): one middleware per
concern, composable via the middleware chain. Prior art in #2430 (circuit
breaker docs, merged).

Related issue number

Replaces the circuit breaker portion of #2501 (closed).
Related: #2430 (docs, merged), #2531 (BudgetMiddleware).

Checks

Single-responsibility middleware implementing the circuit breaker
pattern for LLM calls. Blocks calls after consecutive failures and
allows recovery probes after a configurable timeout.

- CircuitBreakerConfig: failure_threshold, recovery_timeout_s
- Three states: CLOSED, OPEN, HALF_OPEN with atomic probe claiming
- CancelledError releases probe without recording failure
- Thread-safe state machine with mutex
@amabito amabito requested a review from Lancetnik as a code owner March 31, 2026 02:16
@github-actions github-actions bot added the beta label Mar 31, 2026
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 31, 2026

Codecov Report

❌ Patch coverage is 94.49541% with 6 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
autogen/beta/middleware/builtin/circuit_breaker.py 94.44% 3 Missing and 3 partials ⚠️
Files with missing lines Coverage Δ
autogen/beta/middleware/builtin/__init__.py 93.33% <100.00%> (+0.47%) ⬆️
autogen/beta/middleware/builtin/circuit_breaker.py 94.44% <94.44%> (ø)

... and 13 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant