Skip to content

Commit 8b0d18d

Browse files
committed
fix(producer): a failure after the effect scan reports frame capture, with a stable code
1 parent c73eb98 commit 8b0d18d

8 files changed

Lines changed: 67 additions & 7 deletions

File tree

‎packages/cli/src/commands/render.test.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2370,6 +2370,9 @@ describe("normalizeStageCode", () => {
23702370
expect(normalizeStageCode("Encoding frame 600/600")).toBe("encoding_video");
23712371
expect(normalizeStageCode("Encoding frame 12/90")).toBe("encoding_video");
23722372
expect(normalizeStageCode("Capturing frame 120/600 (6 workers)")).toBe("capturing_frame");
2373+
expect(normalizeStageCode("Checking effects, 240 of 240 frames")).toBe(
2374+
normalizeStageCode("Checking effects, 12 of 90 frames"),
2375+
);
23732376
expect(normalizeStageCode("Streaming frame 3/40 (segment 1/2, 2 workers)")).toBe(
23742377
"streaming_frame",
23752378
);

‎packages/cli/src/commands/render.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1854,7 +1854,7 @@ const KNOWN_STAGE_CODES: Readonly<Record<string, string>> = {
18541854
};
18551855

18561856
// Live counts in a progress label ("Capturing frame 120/600 (6 workers)") would make a code per render.
1857-
const STAGE_COUNTS = /\([^)]*\)|\d+\/\d+/g;
1857+
const STAGE_COUNTS = /\([^)]*\)|\d+\/\d+|\d+ of \d+/g;
18581858

18591859
export function normalizeStageCode(stage: string): string {
18601860
const base = stage.replace(STAGE_COUNTS, "").trim();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1361,7 +1361,7 @@ async function cssEffectRiskFrames(
13611361
fps,
13621362
totalFrames,
13631363
totalFrames * MAX_RISK_FRAME_FRACTION,
1364-
{ onProgress: session.options.onEffectScanProgress },
1364+
{ onProgress: session.options.onEffectScanProgress, onEnd: session.options.onEffectScanEnd },
13651365
);
13661366
return live && withFramesAfterCallback(live, scan.callbackFrom, fps, totalFrames);
13671367
} catch (error) {

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,28 @@ describe("scanCssEffectLiveFrames", () => {
140140
}
141141
});
142142

143+
it("says the scan ended when it finishes, stops early over budget, or the page fails", async () => {
144+
let ended = 0;
145+
const onEnd = () => ended++;
146+
await scanCssEffectLiveFrames(makePage(between(0, 0)), 10, 500, 500, { onEnd });
147+
expect(ended).toBe(1);
148+
149+
let clock = 0;
150+
const stoppedEarly = await scanCssEffectLiveFrames(makePage(between(0, 0)), 10, 5_000, 5_000, {
151+
budgetMs: 1_000,
152+
now: () => (clock += 500),
153+
onEnd,
154+
});
155+
expect(stoppedEarly).toBeNull();
156+
expect(ended).toBe(2);
157+
158+
const failing = { evaluate: () => Promise.reject(new Error("page gone")) } as unknown as Page;
159+
await expect(scanCssEffectLiveFrames(failing, 10, 500, 500, { onEnd })).rejects.toThrow(
160+
"page gone",
161+
);
162+
expect(ended).toBe(3);
163+
});
164+
143165
it("reports the frames scanned after each chunk", async () => {
144166
const seen: Array<[number, number]> = [];
145167

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ interface ScanOptions {
8282
budgetMs?: number;
8383
now?: () => number;
8484
onProgress?: (scannedFrames: number, totalFrames: number) => void;
85+
onEnd?: () => void;
8586
}
8687

8788
/**
@@ -93,7 +94,21 @@ export async function scanCssEffectLiveFrames(
9394
fps: number,
9495
totalFrames: number,
9596
maxFrames: number,
96-
{ budgetMs = SCAN_BUDGET_MS, now = () => performance.now(), onProgress }: ScanOptions = {},
97+
options: ScanOptions = {},
98+
): Promise<Set<number> | null> {
99+
try {
100+
return await scanLiveFrames(page, fps, totalFrames, maxFrames, options);
101+
} finally {
102+
options.onEnd?.();
103+
}
104+
}
105+
106+
async function scanLiveFrames(
107+
page: Page,
108+
fps: number,
109+
totalFrames: number,
110+
maxFrames: number,
111+
{ budgetMs = SCAN_BUDGET_MS, now = () => performance.now(), onProgress }: ScanOptions,
97112
): Promise<Set<number> | null> {
98113
const live = new Set<number>();
99114
const started = now();

‎packages/engine/src/types.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ export interface CaptureOptions {
262262
deVerifySamples?: number;
263263
deFrameFallback?: boolean;
264264
onEffectScanProgress?: (scannedFrames: number, totalFrames: number) => void;
265+
onEffectScanEnd?: () => void;
265266
}
266267

267268
export interface CaptureVideoMetadataHint {

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

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ import { afterEach, beforeEach, expect, it, vi } from "vitest";
22
import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
33
import { tmpdir } from "node:os";
44
import { join } from "node:path";
5-
import { resolveConfig } from "@hyperframes/engine";
5+
import { type CaptureOptions, resolveConfig } from "@hyperframes/engine";
66
import { CaptureStageError } from "./render/captureStageError.js";
77
import { extractSafeRenderErrorMetadata } from "../server.js";
88
import { createRenderJob, executeRenderJob } from "./renderOrchestrator.js";
99

1010
// Entry: executeRenderJob on the streaming route; calibration and the streaming stage are scripted.
1111
const { state } = vi.hoisted(() => ({
12-
state: { calibrationEvaluateTimedOut: false, framesBeforeFailure: 0 },
12+
state: { calibrationEvaluateTimedOut: false, framesBeforeFailure: 0, effectScanRan: false },
1313
}));
1414

1515
vi.mock("@hyperframes/engine", async (importOriginal) => ({
@@ -90,8 +90,16 @@ vi.mock("./render/captureCost.js", async (importOriginal) => ({
9090
}));
9191
vi.mock("./render/stages/captureStreamingStage.js", async (importOriginal) => ({
9292
...(await importOriginal<typeof import("./render/stages/captureStreamingStage.js")>()),
93-
runCaptureStreamingStage: async (input: { job: { framesRendered?: number } }) => {
93+
runCaptureStreamingStage: async (input: {
94+
job: { framesRendered?: number };
95+
buildCaptureOptions: () => CaptureOptions;
96+
}) => {
9497
input.job.framesRendered = state.framesBeforeFailure;
98+
if (state.effectScanRan) {
99+
const options = input.buildCaptureOptions();
100+
options.onEffectScanProgress?.(240, 240);
101+
options.onEffectScanEnd?.();
102+
}
95103
throw new CaptureStageError({ cause: new Error(EVALUATE_TIMEOUT), browserConsole: [] });
96104
},
97105
}));
@@ -102,6 +110,7 @@ const dirs: string[] = [];
102110
beforeEach(() => {
103111
state.calibrationEvaluateTimedOut = false;
104112
state.framesBeforeFailure = 0;
113+
state.effectScanRan = false;
105114
vi.stubEnv("HF_SEGMENTED_CAPTURE", "false");
106115
});
107116
afterEach(() => {
@@ -129,6 +138,12 @@ function render(config: { lowMemoryMode?: boolean } = {}): Promise<void> {
129138

130139
let lastJob: ReturnType<typeof createRenderJob>;
131140

141+
it("names frame capture as the failed stage for a failure after the effect scan, before frame one", async () => {
142+
state.effectScanRan = true;
143+
await render().catch(() => undefined);
144+
expect(lastJob.failedStage).toBe("Starting frame capture");
145+
});
146+
132147
it.each([
133148
["after calibration", {}],
134149
["with no calibration, straight after the GPU check", { lowMemoryMode: true }],

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3689,6 +3689,7 @@ async function executeRenderPipeline(input: {
36893689

36903690
// ── Stage 4: Frame capture ──────────────────────────────────────────
36913691
const stage4Start = Date.now();
3692+
const EFFECT_SCAN_STAGE = "Checking effects";
36923693
const startingFrameCapture = () =>
36933694
updateJobStatus(job, "rendering", "Starting frame capture", 25, onProgress, {
36943695
code: "start_browsers",
@@ -3810,10 +3811,13 @@ async function executeRenderPipeline(input: {
38103811
updateJobStatus(
38113812
job,
38123813
"rendering",
3813-
`Checking effects, ${scanned} of ${total} frames`,
3814+
`${EFFECT_SCAN_STAGE}, ${scanned} of ${total} frames`,
38143815
25,
38153816
onProgress,
38163817
),
3818+
onEffectScanEnd: () => {
3819+
if (job.currentStage.startsWith(EFFECT_SCAN_STAGE)) startingFrameCapture();
3820+
},
38173821
requiresWebGpu: compositionRequiresWebGpu(compiled.html),
38183822
// Live route for Chrome memory (spec §5 Phase −1). The aggregate route
38193823
// through CapturePerfSummary only exists on success; a mid-capture

0 commit comments

Comments
 (0)