Skip to content

Write HTML. Render video. Built for agents.

fix(producer): fail loudly when a capture route cannot blur (#4026)

miga-heygen77a45f6080da
diff --git a/packages/producer/src/services/render/motionBlurRoute.test.ts b/packages/producer/src/services/render/motionBlurRoute.test.ts
new file mode 100644
index 0000000000..79a1b206de
--- /dev/null
+++ b/packages/producer/src/services/render/motionBlurRoute.test.ts
@@ -0,0 +1,40 @@
+import { describe, expect, it } from "bun:test";
+import { readFileSync } from "node:fs";
+import { join } from "node:path";
+import { assertMotionBlurSupported } from "./motionBlurRoute.js";
+
+describe("assertMotionBlurSupported", () => {
+ it("lets the SDR capture routes through", () => {
+ expect(() => assertMotionBlurSupported({ samplesPerFrame: 16 }, "sdr_streaming")).not.toThrow();
+ expect(() => assertMotionBlurSupported({ samplesPerFrame: 16 }, "sdr_disk")).not.toThrow();
+ });
+
+ it("lets any route through when motion blur was not asked for", () => {
+ expect(() => assertMotionBlurSupported(undefined, "hdr_layered")).not.toThrow();
+ });
+
+ // The defect this locks: the layered HDR compositor captures through its own loop, so a
+ // render that asked for motion blur got frames with no blur in them and no error. The
+ // engine's own guard cannot catch it, because the session looks supported from inside:
+ // screenshot capture mode, PNG frames, and no video injector on a composition with no
+ // video.
+ // The reason must not blame HDR: this route is also how a composition with shader
+ // transitions and no HDR content at all gets captured.
+ it("names the route and a reason that covers both ways into it", () => {
+ expect(() => assertMotionBlurSupported({}, "hdr_layered")).toThrow(
+ /hdr_layered.*shader transitions.*own capture loop/s,
+ );
+ });
+
+ // Reachability, not mechanism. The unit assertions above pass even if nothing ever calls
+ // the function, which is exactly how the blur shipped dead once already. This pins the
+ // call to the single place the producer decides the route.
+ it("is called on the resolved capture plan, and only there", () => {
+ const orchestrator = readFileSync(join(import.meta.dir, "..", "renderOrchestrator.ts"), "utf8");
+ const calls = orchestrator.match(/assertMotionBlurSupported\(/g) ?? [];
+ expect(calls).toHaveLength(1);
+ expect(orchestrator).toContain(
+ "assertMotionBlurSupported(job.config.motionBlur, capturePlan.kind)",
+ );
+ });
+});
diff --git a/packages/producer/src/services/render/motionBlurRoute.ts b/packages/producer/src/services/render/motionBlurRoute.ts
new file mode 100644
index 0000000000..6d5eb95276
--- /dev/null
+++ b/packages/producer/src/services/render/motionBlurRoute.ts
@@ -0,0 +1,52 @@
+/**
+ * One owner for "does this capture route support sub-frame motion blur".
+ *
+ * The question has been answered implicitly three times and come out wrong and silent
+ * each time, because whichever capture path happened to run decided it. The engine's own
+ * guard covers what the engine can see, the capture mode and the frame format, but it
+ * cannot see which producer route built the session. This module holds that half.
+ *
+ * The route is the capture plan's own `kind`, which is already the single value the capture
+ * stages consume, so this cannot drift from the route that actually runs. A new plan kind
+ * with no entry in the table below fails the typecheck, which forces an explicit answer
+ * instead of inheriting silence.
+ *
+ * Out of scope on purpose: distributed renders. `DistributedRenderConfig` has no
+ * `motionBlur` field and is not built from `RenderConfig`, so motion blur cannot be
+ * requested on one. There is nothing to reject, and threading it through the frozen plan
+ * is a feature rather than a fix.
+ */
+
+import type { MotionBlurOptions } from "@hyperframes/engine";
+import type { CapturePlan } from "./capturePlan.js";
+
+/** Why a capture route cannot honour motion blur, or null when it can. */
+const UNSUPPORTED_REASON: Record<CapturePlan["kind"], string | null> = {
+ sdr_streaming: null,
+ sdr_disk: null,
+ // Named for HDR but reached by shader transitions with no HDR content at all
+ // (`shouldUseLayeredComposite`), so the reason must not blame HDR for a composition
+ // that has none.
+ hdr_layered:
+ "the layered compositor, used for HDR content and for shader transitions, runs its " +
+ "own capture loop, seeking and blitting each layer itself, so a frame never reaches " +
+ "the sub-frame accumulation branch",
+};
+
+/**
+ * Throw a named error when motion blur was asked for on a route that cannot deliver it.
+ *
+ * Failing loudly is the whole point: the alternative, which is what main did until now,
+ * is a render that accepts `motionBlur` and returns frames with no blur in them.
+ */
+export function assertMotionBlurSupported(
+ motionBlur: MotionBlurOptions | undefined,
+ route: CapturePlan["kind"],
+): void {
+ if (!motionBlur) return;
+ const reason = UNSUPPORTED_REASON[route];
+ if (reason === null) return;
+ throw new Error(
+ `[MotionBlur] sub-frame motion blur is not supported on the "${route}" capture route: ${reason}`,
+ );
+}
diff --git a/packages/producer/src/services/renderOrchestrator.ts b/packages/producer/src/services/renderOrchestrator.ts
index ef4faddd2a..6e9cba3c30 100644
--- a/packages/producer/src/services/renderOrchestrator.ts
+++ b/packages/producer/src/services/renderOrchestrator.ts
@@ -190,6 +190,7 @@ import { runEncodeStage } from "./render/stages/encodeStage.js";
import { runAssembleStage } from "./render/stages/assembleStage.js";
import { shouldUseLayeredComposite } from "./hdrCompositor.js";
import { resolveCaptureImageFormat } from "./render/captureImageFormat.js";
+import { assertMotionBlurSupported } from "./render/motionBlurRoute.js";
function sampleDirectoryBytes(dir: string): number {
let total = 0;
@@ -3971,6 +3972,9 @@ async function executeRenderPipeline(input: {
routing: captureRouting,
});
const syncCapturePlan = (): void => {
+ // Every route the render can end up on passes through here, including the ones a
+ // replan lands on, so this is where motion blur's one supported-route answer belongs.
+ assertMotionBlurSupported(job.config.motionBlur, capturePlan.kind);
workerCount = capturePlan.workerCount;
captureForceScreenshot = capturePlan.forceScreenshot;
useStreamingEncode = capturePlan.kind === "sdr_streaming";