fix(agents): land #31007 from @HOYALIM

Co-authored-by: Ho Lim <subhoya@gmail.com>
This commit is contained in:
Peter Steinberger
2026-03-02 01:05:54 +00:00
parent 085c23ce5a
commit 250f9e15f5
3 changed files with 14 additions and 4 deletions

View File

@@ -461,6 +461,11 @@ describe("classifyFailoverReason", () => {
expect(classifyFailoverReason("invalid api key")).toBe("auth");
expect(classifyFailoverReason("no credentials found")).toBe("auth");
expect(classifyFailoverReason("no api key found")).toBe("auth");
expect(
classifyFailoverReason(
'No API key found for provider "openai". Auth store: /tmp/openclaw-agent-abc/auth-profiles.json (agentDir: /tmp/openclaw-agent-abc).',
),
).toBe("auth");
expect(classifyFailoverReason("You have insufficient permissions for this operation.")).toBe(
"auth",
);

View File

@@ -47,6 +47,11 @@ function isReasoningConstraintErrorMessage(raw: string): boolean {
);
}
function hasRateLimitTpmHint(raw: string): boolean {
const lower = raw.toLowerCase();
return /\btpm\b/i.test(lower) || lower.includes("tokens per minute");
}
export function isContextOverflowError(errorMessage?: string): boolean {
if (!errorMessage) {
return false;
@@ -54,7 +59,7 @@ export function isContextOverflowError(errorMessage?: string): boolean {
const lower = errorMessage.toLowerCase();
// Groq uses 413 for TPM (tokens per minute) limits, which is a rate limit, not context overflow.
if (lower.includes("tpm") || lower.includes("tokens per minute")) {
if (hasRateLimitTpmHint(errorMessage)) {
return false;
}
@@ -103,8 +108,7 @@ export function isLikelyContextOverflowError(errorMessage?: string): boolean {
}
// Groq uses 413 for TPM (tokens per minute) limits, which is a rate limit, not context overflow.
const lower = errorMessage.toLowerCase();
if (lower.includes("tpm") || lower.includes("tokens per minute")) {
if (hasRateLimitTpmHint(errorMessage)) {
return false;
}
@@ -622,7 +626,7 @@ const ERROR_PATTERNS = {
"quota exceeded",
"resource_exhausted",
"usage limit",
"tpm",
/\btpm\b/i,
"tokens per minute",
],
overloaded: [