fix: stop LLM retry loop when browser control service is unavailable (#17673)

Merged via /review-pr -> /prepare-pr -> /merge-pr.

Prepared head SHA: 90f47fe132
Co-authored-by: tag-assistant <260167501+tag-assistant@users.noreply.github.com>
Co-authored-by: sebslight <19554889+sebslight@users.noreply.github.com>
Reviewed-by: @sebslight
This commit is contained in:
Tag
2026-02-15 21:53:49 -05:00
committed by GitHub
parent 17a148c8a8
commit 6802b155a8
2 changed files with 15 additions and 5 deletions

View File

@@ -90,9 +90,16 @@ function withLoopbackBrowserAuth(
}
function enhanceBrowserFetchError(url: string, err: unknown, timeoutMs: number): Error {
const hint = isAbsoluteHttp(url)
? "If this is a sandboxed session, ensure the sandbox browser is running and try again."
: `Start (or restart) the OpenClaw gateway (OpenClaw.app menubar, or \`${formatCliCommand("openclaw gateway")}\`) and try again.`;
const isLocal = !isAbsoluteHttp(url);
// Human-facing hint for logs/diagnostics.
const operatorHint = isLocal
? `Restart the OpenClaw gateway (OpenClaw.app menubar, or \`${formatCliCommand("openclaw gateway")}\`).`
: "If this is a sandboxed session, ensure the sandbox browser is running.";
// Model-facing suffix: explicitly tell the LLM NOT to retry.
// Without this, models see "try again" and enter an infinite tool-call loop.
const modelHint =
"Do NOT retry the browser tool — it will keep failing. " +
"Use an alternative approach or inform the user that the browser is currently unavailable.";
const msg = String(err);
const msgLower = msg.toLowerCase();
const looksLikeTimeout =
@@ -103,10 +110,12 @@ function enhanceBrowserFetchError(url: string, err: unknown, timeoutMs: number):
msgLower.includes("aborterror");
if (looksLikeTimeout) {
return new Error(
`Can't reach the OpenClaw browser control service (timed out after ${timeoutMs}ms). ${hint}`,
`Can't reach the OpenClaw browser control service (timed out after ${timeoutMs}ms). ${operatorHint} ${modelHint}`,
);
}
return new Error(`Can't reach the OpenClaw browser control service. ${hint} (${msg})`);
return new Error(
`Can't reach the OpenClaw browser control service. ${operatorHint} ${modelHint} (${msg})`,
);
}
async function fetchHttpJson<T>(