Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix: only count AI-provider failures the circuit that survive the defer window (#2328)
Adam Eivy9a97c430e4d7
diff --git a/server/services/autoFixer.js b/server/services/autoFixer.jsindex 49d16455e8..123d6538b8 100644--- a/server/services/autoFixer.js+++ b/server/services/autoFixer.js@@ -262,14 +262,6 @@ async function handleAIProviderError(error) {return;}- // Circuit breaker: a provider/model that keeps failing this often won't be- // fixed by scheduling yet another investigation task — suppress to avoid a- // retry loop that floods the plan queue. Auto-closes once failures age out.- if (tripCircuit(errorKey)) {- console.log(`🔌 Auto-fix circuit OPEN for ${ctx.provider} (${ctx.model}) — >${CIRCUIT_MAX_FAILURES} failures within the last hour; suppressing investigation task`);- return;- }-// Surface the actual failure reason + category inline so pm2 logs explain// WHY a run failed without spelunking into data/runs/<id>/metadata.json. The// reason is collapsed to a single line and capped (logging convention: no@@ -280,6 +272,15 @@ async function handleAIProviderError(error) {const timer = setTimeout(() => {deferredTasks.delete(errorKey);+ // Circuit breaker: only count a failure that actually survives the defer+ // window (a fallback that recovered the failure has already cancelled this+ // timer, so it never reaches here). A provider/model that keeps producing+ // real investigation tasks this often won't be fixed by yet another — trip+ // the circuit and suppress. Auto-closes once failures age out of the window.+ if (tripCircuit(errorKey)) {+ console.log(`🔌 Auto-fix circuit OPEN for ${ctx.provider} (${ctx.model}) — >${CIRCUIT_MAX_FAILURES} failures within the last hour; suppressing investigation task`);+ return;+ }createAIProviderInvestigationTask(error).catch(err => {console.error(`❌ Deferred AI provider task creation failed: ${err.message}`);// Clear the dedupe entry so the next identical failure isn'tdiff --git a/server/services/autoFixer.test.js b/server/services/autoFixer.test.jsindex 439e6caef8..13e54b6725 100644--- a/server/services/autoFixer.test.js+++ b/server/services/autoFixer.test.js@@ -401,6 +401,28 @@ describe('autoFixer — circuit breaker (guardrail #3)', () => {expect(cos.addTask).toHaveBeenCalledTimes(4);});+ it('AI-provider path: fallback-recovered failures do NOT count toward the circuit', async () => {+ // A failure that a fallback recovers never produces an investigation task,+ // so it must not push the resource toward the circuit threshold. Otherwise+ // a provider that always recovers via fallback would eventually suppress a+ // GENUINE unrecovered failure's investigation task.+ const { noteFallbackStarted, noteFallbackHandled } = await import('./autoFixer.js');+ for (let i = 0; i < 4; i++) {+ emitProviderFailure({ provider: 'Ollama', model: 'command-r', runId: `f-${i}` });+ await vi.advanceTimersByTimeAsync(0);+ noteFallbackStarted({ provider: 'Ollama', model: 'command-r' }); // cancels the deferred timer+ noteFallbackHandled({ provider: 'Ollama', model: 'command-r' }); // success — clears dedupe/in-flight+ await vi.advanceTimersByTimeAsync(DEDUPE_GAP_MS);+ }+ expect(cos.addTask).not.toHaveBeenCalled();++ // A genuine unrecovered failure now STILL raises a task — the circuit never+ // opened because recovered failures were never counted.+ emitProviderFailure({ provider: 'Ollama', model: 'command-r', runId: 'real' });+ await vi.advanceTimersByTimeAsync(5500);+ expect(cos.addTask).toHaveBeenCalledTimes(1);+ });+it('generic critical-error path: suppresses the fix task once the same error fires >3 times within the hour', async () => {for (let i = 0; i < 3; i++) {emitCriticalError({ message: 'recurring boom' });