Skip to content

Commit ec7eebf

Browse files
committed
fix(engine): a render stops and warns when a frame's image never arrives, with no cloud retries
1 parent 25062f0 commit ec7eebf

10 files changed

Lines changed: 62 additions & 10 deletions

File tree

‎examples/aws-lambda/template.yaml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,7 @@ Resources:
460460
- PlanV2IntegrityError
461461
- PLAN_ARTIFACT_DIGEST_MISMATCH
462462
- ChromeBinaryUnavailableError
463+
- ImageMissingFromFrameError
463464
MaxAttempts: 0
464465
- ErrorEquals: [Lambda.TooManyRequestsException]
465466
IntervalSeconds: 5

‎packages/aws-lambda/src/cdk/HyperframesRenderStack.snapshot.test.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,14 @@ describe("HyperframesRenderStack — snapshot", () => {
234234
}
235235
});
236236

237+
it("stops a chunk's retries for an image a frame shows but never got, in SAM and CDK", () => {
238+
for (const definition of [SYNTHED.definition, readSamDefinition()]) {
239+
const errors = new Set<string>();
240+
collectNonRetryableErrors(getV2TaskStates(definition).RenderChunkV2, errors);
241+
expect(errors.has("ImageMissingFromFrameError")).toBe(true);
242+
}
243+
});
244+
237245
it("lists the error the SDK checks for before rendering in every SAM and CDK plan task", () => {
238246
for (const definition of [SYNTHED.definition, readSamDefinition()]) {
239247
const errors = new Set<string>();

‎packages/aws-lambda/src/cdk/HyperframesRenderStack.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ export class HyperframesRenderStack extends Construct {
250250
"PlanV2IntegrityError",
251251
"PLAN_ARTIFACT_DIGEST_MISMATCH",
252252
"ChromeBinaryUnavailableError",
253+
"ImageMissingFromFrameError",
253254
];
254255
const NON_RETRYABLE_ASSEMBLE = [
255256
"FFMPEG_VERSION_MISMATCH",

‎packages/cli/src/ui/renderDiagnostic.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ describe("render diagnostic wire", () => {
136136
[
137137
new CaptureFailure({
138138
kind: "authoring",
139-
message: `Frame 0 shows ${PRIVATE}, which did not load in time, so the video would be missing it.`,
139+
message: `Frame 0 shows ${PRIVATE}, which did not load in time, so the render stopped rather than make a video missing it.`,
140140
}),
141141
"IMAGE_MISSING_FROM_FRAME",
142142
],

‎packages/cli/src/ui/renderDiagnostic.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ function producerCodeOf(error: unknown): string | undefined {
4242
function captureCodeOf(error: unknown, message: string): string | undefined {
4343
if (/Composition has zero duration/.test(message)) return "COMPOSITION_ZERO_DURATION";
4444
if (/Composition setup did not finish/.test(message)) return "COMPOSITION_SETUP_TIMEOUT";
45-
if (/did not load in time, so the video would be missing it/.test(message))
45+
if (/so the render stopped rather than make a video missing it/.test(message))
4646
return "IMAGE_MISSING_FROM_FRAME";
4747
if (!(error instanceof CaptureFailure)) return undefined;
4848
return error.pageErrorLines.length > 0 ? "PAGE_ERROR" : `CAPTURE_${error.kind.toUpperCase()}`;

‎packages/engine/src/services/frameCapture-lateImages.test.ts‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ function sessionReading(readings: Reading[], late: string[], playerReadyTimeout
1313
const session = {
1414
page: { evaluate } as unknown as Page,
1515
lateImages: new Set(late),
16+
warnings: [],
1617
config: { playerReadyTimeout },
1718
} as unknown as CaptureSession;
1819
return { session, evaluate };
@@ -53,17 +54,24 @@ describe("waitForShownLateImages", () => {
5354
const { session } = sessionReading([{ arrived: [], waiting: [PHOTO], broken: [] }], [PHOTO], 0);
5455
const stopped = await waitForShownLateImages(session, 360).catch((error: unknown) => error);
5556
expect(stopped).toBeInstanceOf(ImageMissingFromFrameError);
56-
expect(stopped).toMatchObject({ frameIndex: 360, sources: [PHOTO] });
57+
expect(stopped).toMatchObject({ frameIndex: 360, sources: [PHOTO], failedToLoad: false });
58+
expect((stopped as Error).message).toContain("did not load in time");
59+
expect(session.warnings).toEqual([
60+
expect.objectContaining({
61+
code: "image_missing_from_frame",
62+
message: (stopped as Error).message,
63+
}),
64+
]);
5765
});
5866

5967
it("stops at once for a shown image that failed to load, since waiting cannot help", async () => {
6068
const { session, evaluate } = sessionReading(
6169
[{ arrived: [], waiting: [], broken: [PHOTO] }],
6270
[PHOTO],
6371
);
64-
await expect(waitForShownLateImages(session, 5)).rejects.toBeInstanceOf(
65-
ImageMissingFromFrameError,
66-
);
72+
const stopped = await waitForShownLateImages(session, 5).catch((error: unknown) => error);
73+
expect(stopped).toBeInstanceOf(ImageMissingFromFrameError);
74+
expect((stopped as Error).message).toContain("failed to load");
6775
expect(evaluate).toHaveBeenCalledTimes(1);
6876
});
6977
});

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

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2537,10 +2537,14 @@ export class ImageMissingFromFrameError extends Error {
25372537
constructor(
25382538
readonly frameIndex: number,
25392539
readonly sources: readonly string[],
2540+
readonly failedToLoad: boolean,
25402541
) {
25412542
super(
2542-
`Frame ${frameIndex} shows ${sources.join(", ")}, which did not load in time, so the video would be missing it. ` +
2543-
`Try fewer workers (--workers 1) or a longer --player-ready-timeout.`,
2543+
`Frame ${frameIndex} shows ${sources.join(", ")}, which ${failedToLoad ? "failed to load" : "did not load in time"}, ` +
2544+
`so the render stopped rather than make a video missing it. ` +
2545+
(failedToLoad
2546+
? `Check that the image exists and can be opened.`
2547+
: `Try fewer workers (--workers 1) or a longer --player-ready-timeout.`),
25442548
);
25452549
this.name = "ImageMissingFromFrameError";
25462550
}
@@ -2591,11 +2595,21 @@ export async function waitForShownLateImages(
25912595
}, Array.from(lateImages));
25922596
for (const source of arrived) lateImages.delete(source);
25932597
const missing = Date.now() >= deadline ? [...waiting, ...broken] : broken;
2594-
if (missing.length > 0)
2595-
throw new ImageMissingFromFrameError(
2598+
if (missing.length > 0) {
2599+
const stopped = new ImageMissingFromFrameError(
25962600
frameIndex,
25972601
[...new Set(missing.map(sanitizeDiagnosticUrl))].sort(),
2602+
broken.length > 0,
25982603
);
2604+
recordCaptureWarnings(session, [
2605+
{
2606+
code: "image_missing_from_frame",
2607+
message: stopped.message,
2608+
details: { mediaType: "image", sources: [...stopped.sources] },
2609+
},
2610+
]);
2611+
throw stopped;
2612+
}
25992613
if (waiting.length === 0) return;
26002614
await new Promise((resolve) => setTimeout(resolve, LATE_IMAGE_POLL_MS));
26012615
}

‎packages/engine/src/types.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export interface SubTimelineWaitMemo {
4141
export type CaptureWarningCode =
4242
| "media_readiness_timeout"
4343
| "media_load_failed"
44+
| "image_missing_from_frame"
4445
| "audio_processing_failed"
4546
| "sub_timeline_readiness_timeout"
4647
| "sub_timeline_script_failure"

‎packages/gcp-cloud-run/src/server.test.ts‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,24 @@ describe("createApp HTTP mapping", () => {
429429
expect(await res.json()).toMatchObject({ error: "PLAN_PROTOCOL_UNSUPPORTED" });
430430
});
431431

432+
it("does not retry an image a frame shows but never got", async () => {
433+
const gcs = new FakeGcs();
434+
await seedProjectTar(gcs, planBody.ProjectGcsUri);
435+
const app = createApp(
436+
depsWith(gcs, {
437+
planV2WithPublisher: async () => {
438+
throw Object.assign(new Error("test"), { name: "ImageMissingFromFrameError" });
439+
},
440+
}),
441+
);
442+
const res = await app.request("/", {
443+
method: "POST",
444+
headers: { "content-type": "application/json" },
445+
body: JSON.stringify(planBody),
446+
});
447+
expect(res.status).toBe(400);
448+
});
449+
432450
it.each([
433451
["INVALID_VIDEO_METADATA", 400],
434452
[PLAN_V2_INTEGRITY_UNRECOVERABLE, 400],

‎packages/gcp-cloud-run/src/server.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,7 @@ const NON_RETRYABLE_ERROR_NAMES = new Set([
683683
"BROWSER_GPU_NOT_SOFTWARE",
684684
"FONT_FETCH_FAILED",
685685
"ChromeBinaryUnavailableError",
686+
"ImageMissingFromFrameError",
686687
]);
687688

688689
/**

0 commit comments

Comments
 (0)