fix: hide raw provider errors from chat replies

This commit is contained in:
ImLukeF
2026-04-01 18:33:58 +11:00
parent fbe3ca4d7d
commit 4e63dc0b1c
2 changed files with 143 additions and 3 deletions

View File

@@ -119,6 +119,23 @@ function isPureTransientRateLimitSummary(err: unknown): boolean {
);
}
function isToolResultTurnMismatchError(message: string): boolean {
const lower = message.toLowerCase();
return (
lower.includes("toolresult") &&
lower.includes("tooluse") &&
lower.includes("exceeds the number") &&
lower.includes("previous turn")
);
}
function buildExternalRunFailureText(message: string): string {
if (isToolResultTurnMismatchError(message)) {
return "⚠️ Session history got out of sync. Please try again, or use /new to start a fresh session.";
}
return "⚠️ Something went wrong while processing your request. Please try again, or use /new to start a fresh session.";
}
export async function runAgentTurnWithFallback(params: {
commandBody: string;
followupRun: FollowupRun;
@@ -769,7 +786,9 @@ export async function runAgentTurnWithFallback(params: {
? "⚠️ Context overflow — prompt too large for this model. Try a shorter message or a larger-context model."
: isRoleOrderingError
? "⚠️ Message ordering conflict - please try again. If this persists, use /new to start a fresh session."
: `⚠️ Agent failed before reply: ${trimmedMessage}.\nLogs: openclaw logs --follow`;
: shouldSurfaceToControlUi
? `⚠️ Agent failed before reply: ${trimmedMessage}.\nLogs: openclaw logs --follow`
: buildExternalRunFailureText(message);
return {
kind: "final",