fix: add nested fallback retry (#432)

This commit is contained in:
Charles Packer
2025-12-30 18:27:23 -08:00
committed by GitHub
parent 6a97519afa
commit aeadf27938
2 changed files with 51 additions and 3 deletions

View File

@@ -972,10 +972,30 @@ export async function handleHeadlessCommand(
error_type?: string;
message?: string;
detail?: string;
// Handle nested error structure (error.error) that can occur in some edge cases
error?: { error_type?: string; detail?: string };
}
| undefined;
if (metaError?.error_type === "llm_error") {
// Check for llm_error at top level or nested (handles error.error nesting)
const errorType =
metaError?.error_type ?? metaError?.error?.error_type;
// Fallback: detect LLM provider errors from detail even if misclassified as internal_error
// Patterns are derived from handle_llm_error() message formats in the backend
const detail = metaError?.detail ?? metaError?.error?.detail ?? "";
const llmProviderPatterns = [
"Anthropic API error", // anthropic_client.py:759
"OpenAI API error", // openai_client.py:1034
"Google Vertex API error", // google_vertex_client.py:848
"overloaded", // anthropic_client.py:753 - used for LLMProviderOverloaded
"api_error", // Anthropic SDK error type field
];
const isLlmErrorFromDetail =
errorType === "internal_error" &&
llmProviderPatterns.some((pattern) => detail.includes(pattern));
if (errorType === "llm_error" || isLlmErrorFromDetail) {
const attempt = llmApiErrorRetries + 1;
const baseDelayMs = 1000;
const delayMs = baseDelayMs * 2 ** (attempt - 1);