Skip to content

Commit a0a6244

Browse files
fix(producer): retry capture on a CDP Page.captureScreenshot refusal (#3892)
Chromium's CDP layer can refuse a screenshot capture outright ("Protocol error (Page.captureScreenshot): Unable to capture screenshot") with no timeout wording at all. classifyCaptureFailure() didn't recognize the message, so it fell through to the fatal "authoring" bucket and neither capture-retry path (the disk-capture retry loop, or the streaming-capture pinned-fallback retry) ever attempted a retry — including under --low-memory-mode, whose single-worker plain-screenshot capture never engages either path's other retry conditions. Adds the literal error text to classifyCaptureFailure()'s transient_browser bucket, and threads the resulting classification into shouldRetryViaPinnedFallback() as a routing-independent retry condition, so the streaming path recovers on a fresh session the same way the disk path already does for other transient browser failures. Co-authored-by: Miguel Angel <[email protected]>
1 parent cfe5dcf commit a0a6244

4 files changed

Lines changed: 71 additions & 5 deletions

File tree

‎packages/engine/src/services/captureFailure.test.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ describe("classifyCaptureFailure", () => {
1717
["JavaScript heap out of memory", "memory_exhaustion"],
1818
["drawElement self-verify failed", "verification"],
1919
["Composition has zero duration. Runtime ready: true", "authoring"],
20+
["Protocol error (Page.captureScreenshot): Unable to capture screenshot", "transient_browser"],
21+
[
22+
"[Parallel] Capture failed: Worker 0: Protocol error (Page.captureScreenshot): Unable to capture screenshot",
23+
"transient_browser",
24+
],
25+
// The timed-out variant of the same call stays protocol_timeout (checked first).
26+
["Protocol error (Page.captureScreenshot): waiting for debugger timed out", "protocol_timeout"],
2027
] as const)("classifies %s as %s", (message, kind) => {
2128
expect(classifyCaptureFailure(new Error(message)).kind).toBe(kind);
2229
});

‎packages/engine/src/services/captureFailure.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ const TRANSIENT_BROWSER_ERROR_PATTERNS = [
5252
/ECONNREFUSED/i,
5353
/net::ERR_NETWORK_CHANGED/i,
5454
/Composition has zero duration[\s\S]*Runtime ready: false/,
55+
// CDP can refuse a capture call outright with this exact wording; timed-out
56+
// variants of the same call hit PROTOCOL_TIMEOUT_PATTERNS, checked first.
57+
// Anchored to this literal reason (not just the CDP method) so an unrelated,
58+
// genuinely deterministic Page.captureScreenshot error isn't swept in too.
59+
/Protocol error \(Page\.captureScreenshot\): Unable to capture screenshot/i,
5560
];
5661

5762
const PROTOCOL_TIMEOUT_PATTERNS = [

‎packages/producer/src/services/renderOrchestrator.test.ts‎

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -302,18 +302,27 @@ describe("executeDiskCaptureWithAdaptiveRetry — transient Target-closed single
302302
vi.mocked(mergeWorkerFrames).mockReset();
303303
});
304304

305-
it("retries ONCE at the same worker count on a transient Target closed with zero progress", async () => {
305+
// Both shapes classify as transient_browser: the tab dying mid-capture, and a
306+
// CDP refusal of the capture call itself (no timeout wording, so it used to
307+
// fall through to the fatal "authoring" bucket and was never retried).
308+
it.each([
309+
["a transient Target closed", "Protocol error (Page.captureScreenshot): Target closed"],
310+
[
311+
"a non-timeout captureScreenshot protocol refusal",
312+
"[Parallel] Capture failed: Worker 0: Protocol error (Page.captureScreenshot): Unable to capture screenshot",
313+
],
314+
])("retries ONCE at the same worker count on %s with zero progress", async (_label, message) => {
306315
const workDir = mkdtempSync(join(tmpdir(), "hf-transient-work-"));
307316
const framesDir = mkdtempSync(join(tmpdir(), "hf-transient-frames-"));
308317
const log = makeLog();
309318
let call = 0;
310-
// First attempt: the tab dies before any frame is captured (frame 0) — zero
311-
// forward progress, which the worker-halving retry deliberately bails on.
312-
// The transient retry recovers it without changing the worker count.
319+
// First attempt fails before any frame is captured (frame 0) — zero forward
320+
// progress, which the worker-halving retry deliberately bails on. The
321+
// transient retry recovers it without changing the worker count.
313322
vi.mocked(executeParallelCapture).mockImplementation(async () => {
314323
call++;
315324
if (call === 1) {
316-
throw new Error("Protocol error (Page.captureScreenshot): Target closed");
325+
throw new Error(message);
317326
}
318327
writeAllFrames(framesDir, 4);
319328
return [];
@@ -1629,6 +1638,13 @@ describe("adaptive missing-frame retry helpers", () => {
16291638
),
16301639
),
16311640
).toBe(true);
1641+
expect(
1642+
isRecoverableParallelCaptureError(
1643+
new Error(
1644+
"[Parallel] Capture failed: Worker 0: Protocol error (Page.captureScreenshot): Unable to capture screenshot",
1645+
),
1646+
),
1647+
).toBe(true);
16321648
expect(isRecoverableParallelCaptureError(new Error("Encoding failed: ffmpeg exited"))).toBe(
16331649
false,
16341650
);
@@ -2748,6 +2764,32 @@ describe("shouldRetryViaPinnedFallback (widen the self-verify retry to generic c
27482764
}),
27492765
).toBe(false);
27502766
});
2767+
2768+
// --low-memory-mode is single-worker with no drawElement, so nothing ever
2769+
// pins a count and that mode had no whole-render fallback at all.
2770+
it("retries a transient capture-call refusal even with no pinned routing", () => {
2771+
expect(
2772+
shouldRetryViaPinnedFallback({
2773+
isVerifyError: false,
2774+
isCancellation: false,
2775+
deWorkerInversion: undefined,
2776+
deParallelRouter: undefined,
2777+
isTransientCaptureError: true,
2778+
}),
2779+
).toBe(true);
2780+
});
2781+
2782+
it("never retries a transient capture-call refusal after cancellation", () => {
2783+
expect(
2784+
shouldRetryViaPinnedFallback({
2785+
isVerifyError: false,
2786+
isCancellation: true,
2787+
deWorkerInversion: undefined,
2788+
deParallelRouter: undefined,
2789+
isTransientCaptureError: true,
2790+
}),
2791+
).toBe(false);
2792+
});
27512793
});
27522794

27532795
describe("sequential capture stall recovery", () => {

‎packages/producer/src/services/renderOrchestrator.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ import {
8787
classifyCaptureFailure,
8888
cloneCaptureWarning,
8989
isMemoryExhaustionError,
90+
isTransientBrowserError,
9091
isDrawElementVerificationError,
9192
isDrawElementCaptureError,
9293
getDrawElementVerificationDetails,
@@ -1903,10 +1904,20 @@ export function shouldRetryViaPinnedFallback(args: {
19031904
isDeRendererStall?: boolean;
19041905
/** The producer's no-progress watchdog tripped around a sequential capture call. */
19051906
isSequentialCaptureStall?: boolean;
1907+
/**
1908+
* A transient browser failure around the capture call itself
1909+
* (`classifyCaptureFailure` → `transient_browser`, e.g. a CDP
1910+
* `Page.captureScreenshot` refusal). Routing-independent like the stalls
1911+
* above: `--low-memory-mode` pins single-worker screenshot capture with no
1912+
* drawElement, so neither inversion nor the router ever pins a count, and
1913+
* that mode otherwise had no whole-render fallback for a one-off refusal.
1914+
*/
1915+
isTransientCaptureError?: boolean;
19061916
}): boolean {
19071917
if (args.isCancellation || args.isEncoderInterrupted) return false;
19081918
if (args.isVerifyError || args.isDeCaptureError) return true;
19091919
if (args.isDeRendererStall === true || args.isSequentialCaptureStall === true) return true;
1920+
if (args.isTransientCaptureError === true) return true;
19101921
return args.deWorkerInversion === "inverted" || args.deParallelRouter === "routed";
19111922
}
19121923

@@ -3742,6 +3753,7 @@ async function executeRenderPipeline(input: {
37423753
deParallelRouter,
37433754
isDeRendererStall: isDeStall,
37443755
isSequentialCaptureStall: isSequentialStall,
3756+
isTransientCaptureError: isTransientBrowserError(err),
37453757
})
37463758
)
37473759
throw err;

0 commit comments

Comments
 (0)