From 448394a0de2c90ef146804351c7718db4e22ac14 Mon Sep 17 00:00:00 2001 From: Mykyta Bozhenko <1245729+cheeeee@users.noreply.github.com> Date: Sun, 18 Jan 2026 01:29:48 +0000 Subject: [PATCH] fix(agent): Enable model fallback for prompt-phase quota/rate limit errors When a prompt submission fails with quota or rate limit errors, throw FailoverError instead of the raw promptError. This enables the model fallback system to try alternative models. Previously, rate limit errors during the prompt phase (before streaming) were thrown directly, bypassing fallback. Only response-phase errors triggered model fallback. Now checks if fallback models are configured and the error is failover- eligible. If so, wraps in FailoverError to trigger the fallback chain. --- src/agents/pi-embedded-runner/run.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/agents/pi-embedded-runner/run.ts b/src/agents/pi-embedded-runner/run.ts index 0e0946428..25f36a712 100644 --- a/src/agents/pi-embedded-runner/run.ts +++ b/src/agents/pi-embedded-runner/run.ts @@ -318,6 +318,19 @@ export async function runEmbeddedPiAgent( thinkLevel = fallbackThinking; continue; } + // FIX: Throw FailoverError for prompt errors when fallbacks configured + // This enables model fallback for quota/rate limit errors during prompt submission + const promptFallbackConfigured = + (params.config?.agents?.defaults?.model?.fallbacks?.length ?? 0) > 0; + if (promptFallbackConfigured && isFailoverErrorMessage(errorText)) { + throw new FailoverError(errorText, { + reason: promptFailoverReason ?? "unknown", + provider, + model: modelId, + profileId: lastProfileId, + status: resolveFailoverStatus(promptFailoverReason ?? "unknown"), + }); + } throw promptError; }