Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix(browser): cite the browser-socket discovery message budget
WebSocket discovery enforces the 64 MiB protocol budget. Timeout
recovery no longer advertises the 8 MiB HTTP document budget.

Co-authored-by: morluto <morluto@users.noreply.github.com>
  • Loading branch information
cursoragent and morluto committed Oct 21, 2026
commit ae15a71957981af381bc095b21b4f0e2f6038f4d
6 changes: 4 additions & 2 deletions docs/browser-observation.md
Original file line number Diff line number Diff line change
Expand Up @@ -434,8 +434,10 @@ an invalid supplied size remains unknown with incomplete resource coverage while
the resource's other facts are retained. Zero and nonnegative fractional sizes
are preserved.

CDP discovery has a 10-second response deadline and an 8 MiB document budget.
Neither has a runtime override. `list_browser_targets` accepts no
CDP discovery has a 10-second response deadline. HTTP discovery documents
use an 8 MiB budget. Browser-socket discovery (`Browser.getVersion`,
`Target.getTargets`) uses the 64 MiB protocol message budget. Neither budget
nor the discovery deadline has a runtime override. `list_browser_targets` accepts no
`command_timeout_ms`: HTTP discovery and browser-socket discovery
(`Browser.getVersion`, `Target.getTargets`) stay on that fixed deadline, and
the socket closes without a later command. Other CDP tools use
Expand Down
44 changes: 44 additions & 0 deletions src/browser/CdpEndpoint.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { once } from "node:events";

import { AnalysisCancelledError } from "../domain/analysisErrorCore.js";
import { BrowserObservationError } from "../domain/browserObservationError.js";
import { WEB_RUNTIME_LIMITS } from "../domain/webRuntime.js";

import { afterEach, describe, expect, it } from "vitest";

Expand Down Expand Up @@ -206,6 +207,49 @@ describe("CDP discovery cancellation ownership", () => {
});
});

it("names the browser-socket message budget when that discovery deadline expires", async () => {
const failure = await withCdpDiscoveryDeadline(
"list_browser_targets",
undefined,
(signal) =>
new Promise((_resolve, reject) => {
signal.addEventListener("abort", () => reject(signal.reason), {
once: true,
});
}),
1,
).catch((error: unknown) => error);

expect(failure).toBeInstanceOf(BrowserObservationError);
if (!(failure instanceof BrowserObservationError)) return;
expect(failure.userMessage).toContain(
`${String(WEB_RUNTIME_LIMITS.protocolBytes)}-byte browser-socket message budget`,
);
expect(failure.userMessage).not.toContain(
"8388608-byte discovery document budget",
);
});

it("names the HTTP discovery document budget when that response deadline expires", async () => {
const { endpoint } = await listen(() => undefined);
const failure = await readCdpJson(
new URL(endpoint),
"list_browser_targets",
undefined,
{ bytes: 8 * 1024 * 1024, timeoutMs: 20 },
).catch((error: unknown) => error);

expect(failure).toBeInstanceOf(BrowserObservationError);
if (!(failure instanceof BrowserObservationError)) return;
expect(failure.userMessage).toContain(
"8388608-byte discovery document budget",
);
expect(failure.userMessage).toContain("20 ms");
expect(failure.userMessage).not.toContain(
`${String(WEB_RUNTIME_LIMITS.protocolBytes)}-byte browser-socket message budget`,
);
});

it("preserves an independent typed cancellation when the discovery deadline also expires", async () => {
const primary = new AnalysisCancelledError("inspect_web_page", {
cause: "independent cancellation",
Expand Down
8 changes: 7 additions & 1 deletion src/browser/CdpEndpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import type { BrowserObservationOperation } from "../domain/browserObservationEr
import { sanitizeBrowserUrl } from "../domain/browserObservation.js";
import { urlDeclaresQueryOrFragment } from "../domain/urlComponents.js";
import { safeParseJson } from "../domain/safeJson.js";
import { WEB_RUNTIME_LIMITS } from "../domain/webRuntime.js";
import type { CdpConnection } from "./CdpConnection.js";

const endpointVersionSchema = z.object({
Expand Down Expand Up @@ -41,6 +42,11 @@ const CDP_DISCOVERY_RESPONSE_LIMITS = {
timeoutMs: CDP_DISCOVERY_RESPONSE_TIMEOUT_MS,
} as const;

const discoveryBudget = (phase: "response" | "browser-socket"): string =>
phase === "response"
? `The ${String(CDP_DISCOVERY_RESPONSE_LIMITS.bytes)}-byte discovery document budget`
: `The ${String(WEB_RUNTIME_LIMITS.protocolBytes)}-byte browser-socket message budget`;

const discoveryTimeout = (
operation: BrowserObservationOperation,
timeoutMs: number,
Expand All @@ -51,7 +57,7 @@ const discoveryTimeout = (
? `CDP discovery response exceeded its ${String(timeoutMs)} ms deadline.`
: `CDP browser-socket discovery exceeded its ${String(timeoutMs)} ms deadline.`;
const fixed = noRuntimeOverrideSentence(
`The ${String(CDP_DISCOVERY_RESPONSE_LIMITS.bytes)}-byte discovery document budget and the ${String(timeoutMs)} ms discovery deadline stay fixed.`,
`${discoveryBudget(phase)} and the ${String(timeoutMs)} ms discovery deadline stay fixed.`,
cdpCommandTimeoutUnrelatedControl(operation),
);
return new BrowserObservationError(operation, "timeout", {
Expand Down