mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 11:51:23 +00:00
fix(agents): avoid classifying reasoning-required errors as context overflow (#24593)
* Agents: exclude reasoning-required errors from overflow detection * Tests: cover reasoning-required overflow classification guard * Tests: format reasoning-required endpoint errors
This commit is contained in:
@@ -34,6 +34,19 @@ function formatRateLimitOrOverloadedErrorCopy(raw: string): string | undefined {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function isReasoningConstraintErrorMessage(raw: string): boolean {
|
||||
if (!raw) {
|
||||
return false;
|
||||
}
|
||||
const lower = raw.toLowerCase();
|
||||
return (
|
||||
lower.includes("reasoning is mandatory") ||
|
||||
lower.includes("reasoning is required") ||
|
||||
lower.includes("requires reasoning") ||
|
||||
(lower.includes("reasoning") && lower.includes("cannot be disabled"))
|
||||
);
|
||||
}
|
||||
|
||||
export function isContextOverflowError(errorMessage?: string): boolean {
|
||||
if (!errorMessage) {
|
||||
return false;
|
||||
@@ -45,6 +58,10 @@ export function isContextOverflowError(errorMessage?: string): boolean {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isReasoningConstraintErrorMessage(errorMessage)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const hasRequestSizeExceeds = lower.includes("request size exceeds");
|
||||
const hasContextWindow =
|
||||
lower.includes("context window") ||
|
||||
@@ -85,6 +102,10 @@ export function isLikelyContextOverflowError(errorMessage?: string): boolean {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isReasoningConstraintErrorMessage(errorMessage)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (CONTEXT_WINDOW_TOO_SMALL_RE.test(errorMessage)) {
|
||||
return false;
|
||||
}
|
||||
@@ -464,6 +485,13 @@ export function formatAssistantErrorText(
|
||||
);
|
||||
}
|
||||
|
||||
if (isReasoningConstraintErrorMessage(raw)) {
|
||||
return (
|
||||
"Reasoning is required for this model endpoint. " +
|
||||
"Use /think minimal (or any non-off level) and try again."
|
||||
);
|
||||
}
|
||||
|
||||
// Catch role ordering errors - including JSON-wrapped and "400" prefix variants
|
||||
if (
|
||||
/incorrect role information|roles must alternate|400.*role|"message".*role.*information/i.test(
|
||||
|
||||
Reference in New Issue
Block a user