Write HTML. Render video. Built for agents.
JavaScript aiai-agentsanimationclaude-codeffmpegframeworkgsaphtmlhtml-to-videomcpmotion-graphicspuppeteerrenderingtypescriptvideo-editor
fix(engine): emit pipelined frame diagnostics before the recoverable wrapper
Vance Ingalls4c7fbde51e80
diff --git a/packages/engine/src/services/frameCapture-freshFallback.test.ts b/packages/engine/src/services/frameCapture-freshFallback.test.tsindex 62fee23174..ab7575da65 100644--- a/packages/engine/src/services/frameCapture-freshFallback.test.ts+++ b/packages/engine/src/services/frameCapture-freshFallback.test.ts@@ -1,5 +1,5 @@import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";-import { mkdtempSync, rmSync } from "node:fs";+import { existsSync, mkdtempSync, rmSync } from "node:fs";import { tmpdir } from "node:os";import { join } from "node:path";import {@@ -102,6 +102,26 @@ describe("fresh screenshot fallback", () => {});}+ // The recoverable-error wrapper used to throw before the diagnostics call,+ // so exactly the NCPR/canvas failures worth debugging produced no bundle.+ it("still writes per-frame diagnostics when a recoverable pipelined failure aborts the attempt", async () => {+ vi.mocked(produceDrawElementFrame).mockRejectedValueOnce(+ new Error("No cached paint record for element"),+ );+ const s = await session();+ // The shared mock page fails its diagnostic screenshot; give this one a+ // working page so the bundle can actually land on disk.+ Object.assign(s.page, {+ screenshot: async () => Buffer.alloc(0),+ content: async () => "<html></html>",+ });++ await expect(captureFrameToBufferPipelined(s, 7, 7 / 30)).rejects.toBeInstanceOf(+ DrawElementCaptureError,+ );+ expect(existsSync(join(s.outputDir, "diagnostics", "frame-error-7.json"))).toBe(true);+ });+it("rejects a suspect tiny frame without substituting a stale screenshot", async () => {vi.mocked(captureDrawElementFrame).mockResolvedValueOnce(Buffer.alloc(100));await expect(captureFrameToBuffer(await session(), 7, 7 / 30)).rejects.toThrow(diff --git a/packages/engine/src/services/frameCapture.ts b/packages/engine/src/services/frameCapture.tsindex 4a3e257624..9c66f065ba 100644--- a/packages/engine/src/services/frameCapture.ts+++ b/packages/engine/src/services/frameCapture.ts@@ -3893,17 +3893,16 @@ export async function captureFrameToBufferPipelined(return { encodeResult, captureTimeMs };} catch (captureError) {- // The viewport can contain the last injected bitmap, not the sought frame.- if (isRecoverableDrawElementError(captureError)) {- session.deNcprFallbacks = (session.deNcprFallbacks ?? 0) + 1;- const reason = isCanvasNotInitializedError(captureError)- ? "drawElement canvas not initialized"- : "No cached paint record";- throw new DrawElementCaptureError(frameIndex, reason, captureError);- }// Mirror captureFrameCore: capture per-frame diagnostics (frame-error// PNG/HTML/JSON + console tail) before rethrowing so pipelined-path- // failures are debuggable like the serial path.+ // failures are debuggable like the serial path. Runs BEFORE the+ // recoverable-error wrapper below because the serial path's diagnostics+ // sit in an outer catch that its own DrawElementCaptureError throw+ // propagates through — ordering it after the wrapper would silently skip+ // the bundle for exactly the NCPR/canvas failures worth debugging.+ // Bounded: a recoverable error aborts the whole attempt, so this fires at+ // most once per attempt. captureFrameErrorDiagnostics self-catches, so a+ // dead page cannot mask the structural error the producer retries on.if (session.isInitialized) {await captureFrameErrorDiagnostics(session,@@ -3912,6 +3911,14 @@ export async function captureFrameToBufferPipelined(captureError instanceof Error ? captureError : new Error(String(captureError)),);}+ // The viewport can contain the last injected bitmap, not the sought frame.+ if (isRecoverableDrawElementError(captureError)) {+ session.deNcprFallbacks = (session.deNcprFallbacks ?? 0) + 1;+ const reason = isCanvasNotInitializedError(captureError)+ ? "drawElement canvas not initialized"+ : "No cached paint record";+ throw new DrawElementCaptureError(frameIndex, reason, captureError);+ }throw captureError;}}