Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@
"minimatch": "^10.2.1",
"glob": "^11.0.0",
"serialize-javascript": "^7.0.5"
}
},
"hono": "^4.12.26",
"undici": "^7.28.0"
Comment thread
andyMrtnzP marked this conversation as resolved.
}
}
7 changes: 4 additions & 3 deletions src/lib/agent-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,10 @@ export class ProfileNotFoundError extends UpgradeError {
}

// Upgrade statuses where a one-shot retry cannot help: bad request (400),
// bad auth (401), forbidden by plan/policy (403), or missing resource (404).
// Retrying just wastes time and emits a misleading "second attempt failed".
const NON_RETRYABLE_UPGRADE_STATUSES = new Set([400, 401, 403, 404]);
// bad auth (401), forbidden by plan/policy (403), missing resource (404), or
// concurrency limit (429). Retrying a 429 just opens another session and
// stacks more lingering sessions against the same limit, so stop instead.
const NON_RETRYABLE_UPGRADE_STATUSES = new Set([400, 401, 403, 404, 429]);

export const isRetryableUpgradeError = (err: unknown): boolean => {
if (err instanceof UpgradeError) {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/agent-format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export const formatConnectError = (err: unknown): string => {
case 403:
return `Forbidden (403) — your plan does not include this feature${detail ? ` (server says: ${detail})` : ''}.`;
case 429:
return `Concurrency limit reached (429)${detail ? `: ${detail}` : ''}. Wait for in-flight sessions to finish, or upgrade the plan.`;
return `Concurrency limit reached (429)${detail ? `: ${detail}` : ''}. Stop retrying — each new attempt opens another session and stacks more against the limit. Close any sessions you still have open (call browserless_agent with method "close"), wait for in-flight sessions to finish, or upgrade the plan, then start over.`;
default: {
const fallback = detail || err.statusMessage || '';
return `Failed to connect to browser agent (HTTP ${err.statusCode})${fallback ? `: ${fallback}` : ''}.`;
Expand Down
10 changes: 6 additions & 4 deletions test/lib/agent-client.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,17 +234,19 @@ describe('agent-client proxyFingerprint', () => {
describe('agent-client isRetryableUpgradeError', () => {
// The retry guard exists so the agent tool doesn't burn a second WS
// handshake when the server already returned a definitive 4xx.
it('does not retry on 400/401/403/404', () => {
for (const status of [400, 401, 403, 404]) {
it('does not retry on 400/401/403/404/429', () => {
// 429 is non-retryable: a retry opens another session and stacks more
// lingering sessions against the same concurrency limit.
for (const status of [400, 401, 403, 404, 429]) {
expect(
isRetryableUpgradeError(new UpgradeError(status, 'msg', 'body')),
`status=${status}`,
).to.equal(false);
}
});

it('retries on 5xx and 429 (transient)', () => {
for (const status of [429, 500, 502, 503]) {
it('retries on 5xx (transient)', () => {
for (const status of [500, 502, 503]) {
expect(
isRetryableUpgradeError(new UpgradeError(status, 'msg', 'body')),
`status=${status}`,
Expand Down
5 changes: 3 additions & 2 deletions test/tools/agent.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,8 @@ describe('formatConnectError', () => {
),
);
expect(out).to.match(/^Concurrency limit reached \(429\)/);
expect(out).to.include('Wait for');
expect(out).to.include('Stop retrying');
expect(out).to.include('wait for');
});

it('falls back to a generic upgrade message for unrecognized statuses', () => {
Expand Down Expand Up @@ -461,7 +462,7 @@ describe('formatConnectError with proxy-injected errors', () => {
const out = formatConnectError(
new UpgradeError(429, 'Too Many Requests', ''),
);
expect(out).to.match(/^Concurrency limit reached \(429\)\. Wait for/);
expect(out).to.match(/^Concurrency limit reached \(429\)\. Stop retrying/);
});

it('renders nginx HTML 502 body as cleaned text', () => {
Expand Down