From 9ff00ccbd2e5921ff4c0a49472695cc09b36324a Mon Sep 17 00:00:00 2001 From: Tag Date: Sun, 15 Feb 2026 21:30:30 -0500 Subject: [PATCH] fix: stop LLM retry loop on browser service unavailable --- src/browser/client-fetch.ts | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/browser/client-fetch.ts b/src/browser/client-fetch.ts index 3fe71934b3e..c8617d0f79c 100644 --- a/src/browser/client-fetch.ts +++ b/src/browser/client-fetch.ts @@ -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(