mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 19:24:31 +00:00
Agent: repair malformed tool calls and session files
This commit is contained in:
@@ -351,6 +351,14 @@ export function formatAssistantErrorText(
|
||||
);
|
||||
}
|
||||
|
||||
if (isMissingToolCallInputError(raw)) {
|
||||
return (
|
||||
"Session history looks corrupted (tool call input missing). " +
|
||||
"Use /new to start a fresh session. " +
|
||||
"If this keeps happening, reset the session or delete the corrupted session transcript."
|
||||
);
|
||||
}
|
||||
|
||||
const invalidRequest = raw.match(/"type":"invalid_request_error".*?"message":"([^"]+)"/);
|
||||
if (invalidRequest?.[1]) {
|
||||
return `LLM request rejected: ${invalidRequest[1]}`;
|
||||
@@ -465,6 +473,11 @@ const ERROR_PATTERNS = {
|
||||
],
|
||||
} as const;
|
||||
|
||||
const TOOL_CALL_INPUT_MISSING_RE =
|
||||
/tool_(?:use|call)\.(?:input|arguments).*?(?:field required|required)/i;
|
||||
const TOOL_CALL_INPUT_PATH_RE =
|
||||
/messages\.\d+\.content\.\d+\.tool_(?:use|call)\.(?:input|arguments)/i;
|
||||
|
||||
const IMAGE_DIMENSION_ERROR_RE =
|
||||
/image dimensions exceed max allowed size for many-image requests:\s*(\d+)\s*pixels/i;
|
||||
const IMAGE_DIMENSION_PATH_RE = /messages\.(\d+)\.content\.(\d+)\.image/i;
|
||||
@@ -505,6 +518,13 @@ export function isBillingErrorMessage(raw: string): boolean {
|
||||
);
|
||||
}
|
||||
|
||||
export function isMissingToolCallInputError(raw: string): boolean {
|
||||
if (!raw) {
|
||||
return false;
|
||||
}
|
||||
return TOOL_CALL_INPUT_MISSING_RE.test(raw) || TOOL_CALL_INPUT_PATH_RE.test(raw);
|
||||
}
|
||||
|
||||
export function isBillingAssistantError(msg: AssistantMessage | undefined): boolean {
|
||||
if (!msg || msg.stopReason !== "error") {
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user