fix(producer): a cloud chunk is not stopped as stalled while its video frames are still extracting (#8632)

This commit is contained in:
Miguel Ángel
2026-11-24 03:39:50 +00:00
committed by GitHub
parent d04d8fe468
commit 8cdf5b22dc
8 changed files with 41 additions and 15 deletions
@@ -199,6 +199,7 @@ export async function extractDeferredVideoFramesForChunk(input: {
cfg: Pick<EngineConfig, "ffmpegProcessTimeout">;
remoteSources?: PlanV2RemoteSources;
shownBoxes?: ReadonlyMap<string, ShownBox>;
onProgress?: () => void;
}): Promise<ExtractedFrames[]> {
const deferred = input.planVideos.extracted.filter((video) => video.deferredRange);
const remoteSources = input.remoteSources ?? {};
@@ -224,6 +225,7 @@ export async function extractDeferredVideoFramesForChunk(input: {
outputRoot: input.outputRoot,
cfg: input.cfg,
shownBoxes: input.shownBoxes,
...(input.onProgress && { onProgress: input.onProgress }),
sourceOf: (video) => {
const range = planned.get(video.videoId)!.deferredRange!;
const remoteUrl = remoteSources[range.sourcePath];
@@ -132,7 +132,7 @@ export {
rebuildExtractedFramesFromPlanDir,
RenderChunkValidationError,
} from "./chunkFrames.js";
import { noteStaticDedupActivity } from "../render/shared.js";
import { noteCaptureActivity } from "../render/shared.js";
const LEGACY_DISTRIBUTED_VP9_CPU_USED = 2;
@@ -750,7 +750,7 @@ export async function renderChunk(
deferredVideos.filter((video) => remoteVideoIds.has(video.videoId)),
),
});
captureOptions.onStaticDedupActivity = () => noteStaticDedupActivity(job);
captureOptions.onStaticDedupActivity = () => noteCaptureActivity(job);
// Resolve worker count up-front. Sequential capture reuses the initialized
// session below. Parallel BeginFrame capture pays one bounded preflight
@@ -901,6 +901,7 @@ export async function renderChunk(
cfg,
remoteSources,
shownBoxes,
onProgress: () => noteCaptureActivity(job),
}).then((frames) => {
videoExtractMs = Date.now() - extractStarted;
return frames;
@@ -104,6 +104,27 @@ describe("extractDeferredFrames", () => {
await expect(extraction).rejects.toBe(missingError);
expect(reported).toEqual([{ videoId: "clip", index: 45 }]);
});
// fails without the fix: a cloud chunk's workers wait on this extraction in frame_capture, and with no progress
// of its own a clip that took over 5 min to extract was stopped as stalled at frame 0.
it("reports FFmpeg's frames written as progress while it extracts, and still returns every frame", async () => {
let reports = 0;
const extracted = await extractDeferredFrames({
videos: [element("clip", 0, 4)],
extracted: [deferredVideo("clip", 45)],
frames: span(0, 45),
fps,
outputRoot: join(root, "progress"),
cfg: {},
sourceOf: () => sourcePath,
onMissingFrame: (_video, index) => new Error(`missing frame ${index}`),
onProgress: () => {
reports += 1;
},
});
expect(extracted[0]!.framePaths.size).toBe(45);
expect(reports).toBeGreaterThan(0);
});
describe("extractAllDeferredFrames", () => {
const framesOf = (dir: string) =>
new Map(readdirSync(dir).map((name) => [name, readFileSync(join(dir, name))] as const));
@@ -66,6 +66,7 @@ export async function extractDeferredFrames(input: {
shownBoxes?: ReadonlyMap<string, ShownBox>;
/** The error to throw when the extractor returns no frame for an index the video shows. */
onMissingFrame: (video: ExtractedFrames, index: number) => Error;
onProgress?: () => void;
}): Promise<ExtractedFrames[]> {
const deferred = input.extracted.filter((video) => video.deferredRange);
if (deferred.length === 0) return [];
@@ -89,6 +90,7 @@ export async function extractDeferredFrames(input: {
format: range.format,
frameRanges: contiguousRuns(indexes),
shownBox: input.shownBoxes?.get(video.videoId),
...(input.onProgress && { onProgress: input.onProgress }),
},
input.signal,
input.cfg,
@@ -436,15 +436,15 @@ export function forgetWorkerPhases(job: object): void {
workerPhasesByJob.delete(job);
}
const staticDedupActivityByJob = new WeakMap<object, number>();
const captureActivityByJob = new WeakMap<object, number>();
/** Counts a render's still-frame check screenshots; the capture stall watcher reads it as activity. */
export function noteStaticDedupActivity(job: object): void {
staticDedupActivityByJob.set(job, (staticDedupActivityByJob.get(job) ?? 0) + 1);
/** Counts capture work between frames (still checks, a chunk's video frames); the stall watcher reads it. */
export function noteCaptureActivity(job: object): void {
captureActivityByJob.set(job, (captureActivityByJob.get(job) ?? 0) + 1);
}
export function staticDedupActivity(job: object): number {
return staticDedupActivityByJob.get(job) ?? 0;
export function captureActivity(job: object): number {
return captureActivityByJob.get(job) ?? 0;
}
export function describeWorkerPhases(job: object): string | undefined {
@@ -233,7 +233,7 @@ mock.module("../../htmlCompiler.js", () => ({
const notedStaticDedupActivity: object[] = [];
mock.module("../shared.js", () => ({
noteStaticDedupActivity: (job: object) => notedStaticDedupActivity.push(job),
noteCaptureActivity: (job: object) => notedStaticDedupActivity.push(job),
BROWSER_MEDIA_EPSILON: 0.0001,
projectBrowserEndToCompositionTimeline: (
existingStart: number,
@@ -83,7 +83,7 @@ import { servedPath } from "../../servedPath.js";
import type { ProducerLogger } from "../../../logger.js";
import {
BROWSER_MEDIA_EPSILON,
noteStaticDedupActivity,
noteCaptureActivity,
projectBrowserEndToCompositionTimeline,
resolveBrowserMediaEnd,
writeCompiledArtifacts,
@@ -664,7 +664,7 @@ export async function runProbeStage(input: ProbeStageInput): Promise<ProbeStageR
staticDedupMemo,
compositionHash: computeCompositionObservabilityHash(compiled.html),
deferStaticDedup: true,
onStaticDedupActivity: () => noteStaticDedupActivity(job),
onStaticDedupActivity: () => noteCaptureActivity(job),
};
const PROBE_MAX_ATTEMPTS = 2;
@@ -158,8 +158,8 @@ import {
createMemorySampler,
describeWorkerPhases,
forgetWorkerPhases,
noteStaticDedupActivity,
staticDedupActivity,
noteCaptureActivity,
captureActivity,
type MemorySampler,
reportExtractProgress,
updateJobStatus,
@@ -1280,7 +1280,7 @@ export function frameStallRule(
tailMs: Math.max(TAIL_STALL_MS, noProgressMs),
detail: () => describeWorkerPhases(job),
attemptOpened: () => forgetWorkerPhases(job),
activity: () => staticDedupActivity(job),
activity: () => captureActivity(job),
};
}
@@ -3936,7 +3936,7 @@ async function executeRenderPipeline(input: {
subTimelineWaitMemo,
staticDedupMemo,
compositionHash,
onStaticDedupActivity: () => noteStaticDedupActivity(job),
onStaticDedupActivity: () => noteCaptureActivity(job),
// Probe-resolved duration: drawElement self-verification derives its
// sample frame indices from this so they land inside the drained range.
compositionDurationSeconds: job.duration,