Skip to content

Never stop coding. Free MIT AI gateway: one endpoint, 375 providers (150+ free), 1,400+ models Kimi, Claude, GPT, Gemini, GLM, DeepSeek, MiniMax. Works with Claude Code, Codex, Cursor, OpenCode, Cline & Copilot. Quota-aware auto-fallback, RTK+Caveman compression saves 15-95% tokens, MCP/A2A, Desktop/PWA. Built by 900+ contributors

fix(resilience): prevent circuit breaker stuck OPEN in combo path

tombiic0da968af299
diff --git a/src/shared/utils/circuitBreaker.ts b/src/shared/utils/circuitBreaker.ts
index 4809bc4c7e..768178ed90 100644
--- a/src/shared/utils/circuitBreaker.ts
+++ b/src/shared/utils/circuitBreaker.ts
@@ -197,13 +197,20 @@ export class CircuitBreaker {
// ─── Internal Methods ────────────────────────
_onSuccess() {
- if (this.state === STATE.HALF_OPEN) {
+ if (this.state === STATE.OPEN) {
+ // Direct call from combo path: timeout elapsed and request succeeded
+ // without going through execute(), so transition OPEN → CLOSED directly
+ this._transition(STATE.CLOSED);
+ this.failureCount = 0;
+ this.successCount = 0;
+ } else if (this.state === STATE.HALF_OPEN) {
this.successCount++;
this._transition(STATE.CLOSED);
this.failureCount = 0;
+ } else {
+ // In CLOSED state, just reset failure count
+ this.failureCount = 0;
}
- // In CLOSED state, just reset failure count
- this.failureCount = 0;
this._persistToDb();
}
@@ -211,7 +218,9 @@ export class CircuitBreaker {
this.failureCount++;
this.lastFailureTime = Date.now();
- if (this.state === STATE.HALF_OPEN) {
+ if (this.state === STATE.OPEN) {
+ // Already OPEN — just update persistence (re-tripped by combo path)
+ } else if (this.state === STATE.HALF_OPEN) {
this._transition(STATE.OPEN);
} else if (this.failureCount >= this.failureThreshold) {
this._transition(STATE.OPEN);