feat: provider cooldown / circuit breaker#5442
Open
kshitijk4poor wants to merge 1 commit into
Open
Conversation
This was referenced Apr 6, 2026
45e1ec5 to
b2ac277
Compare
Collaborator
|
Related to merged #15134 (consolidated retry fix with cooldown logic). Verify overlap before merging. |
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.
Fixes #5436. Also addresses #5451 (provider runtime health observability).
Summary
Adds a process-scoped provider cooldown tracker (circuit breaker) and runtime health observability.
1. Provider cooldown / circuit breaker
Problem: When a provider returns 401/403/429, Hermes retries then possibly falls back, but on the next iteration it hits the same broken provider again with no memory of prior failures.
Introduces
agent/provider_cooldown.pywith:CooldownEntrydataclass tracking error count, cooldown expiry, failure reasonProviderCooldownTracker(thread-safe singleton) with escalating backoff:record_failure()opens/escalates,record_success()closesIntegration: checked before each API call → fallback or wait. Reset on success.
2. Provider health observability
Extends the tracker with
ProviderHealthStats:get_health_summary()returns a compact dict suitable for/statusdisplayIndependent of #5441 (P0 error classification) — uses plain string reason codes.
Tests
63 tests covering escalating backoff, circuit close on success, thread safety, expired auto-clear, singleton pattern, health stats accumulation/persistence/filtering, and diagnostics.