fix(browser): tighten 429 detection and unify rate limit messages

- Remove errMsg.includes("429") fallback from retry-skip logic in
  pw-session.ts; the "rate limit" check alone is sufficient and avoids
  false positives from unrelated errors containing "429" (e.g. timeouts,
  port numbers, API paths)
- Export BROWSER_RATE_LIMIT_MESSAGE from client-fetch.ts and use it in
  cdp.helpers.ts instead of hand-rolled message for consistent wording

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Matt Van Horn 2026-03-09 18:57:50 -07:00 committed by Altay
parent 7a93c93de4
commit cda54bc778
No known key found for this signature in database
3 changed files with 4 additions and 4 deletions

View File

@ -3,6 +3,7 @@ import { isLoopbackHost } from "../gateway/net.js";
import { rawDataToString } from "../infra/ws.js";
import { getDirectAgentForCdp, withNoProxyForCdpUrl } from "./cdp-proxy-bypass.js";
import { CDP_HTTP_REQUEST_TIMEOUT_MS, CDP_WS_HANDSHAKE_TIMEOUT_MS } from "./cdp-timeouts.js";
import { BROWSER_RATE_LIMIT_MESSAGE } from "./client-fetch.js";
import { getChromeExtensionRelayAuthHeaders } from "./extension-relay.js";
export { isLoopbackHost };
@ -176,8 +177,7 @@ export async function fetchCdpChecked(
const text = await res.text().catch(() => "");
const detail = text ? ` (${text.slice(0, 200)})` : "";
throw new Error(
`Browserbase rate limit reached (max concurrent sessions).${detail} ` +
`Do NOT retry - wait for the current session to complete, or upgrade your plan.`,
`${BROWSER_RATE_LIMIT_MESSAGE}${detail} Do NOT retry - wait for the current session to complete, or upgrade your plan.`,
);
}
throw new Error(`HTTP ${res.status}`);

View File

@ -102,7 +102,7 @@ const BROWSER_TOOL_MODEL_HINT =
"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 BROWSER_RATE_LIMIT_MESSAGE =
export const BROWSER_RATE_LIMIT_MESSAGE =
"Browserbase rate limit reached (max concurrent sessions). " +
"Wait for the current session to complete, or upgrade your plan.";

View File

@ -367,7 +367,7 @@ async function connectBrowser(cdpUrl: string): Promise<ConnectedBrowser> {
lastErr = err;
// Don't retry rate-limit errors; retrying worsens the 429.
const errMsg = err instanceof Error ? err.message : String(err);
if (errMsg.includes("rate limit") || errMsg.includes("429")) {
if (errMsg.includes("rate limit")) {
break;
}
const delay = 250 + attempt * 250;