Skip to content

Write HTML. Render video. Built for agents.

feat(producer): carry Chrome memory and capture path on observability and perf summary

Vance Ingalls119dafc005f8
diff --git a/packages/producer/src/services/render/capturePlan.ts b/packages/producer/src/services/render/capturePlan.ts
index 3b5eac1c25..909d2f72b2 100644
--- a/packages/producer/src/services/render/capturePlan.ts
+++ b/packages/producer/src/services/render/capturePlan.ts
@@ -9,6 +9,8 @@
* transition between variants.
*/
+import type { CapturePath } from "./observability.js";
+
export type CapturePlanTarget = Readonly<{
kind: "sdr_streaming" | "sdr_disk";
workerCount: number;
@@ -51,6 +53,22 @@ export interface HdrLayeredCapturePlan extends CapturePlanBase {
export type CapturePlan = SdrStreamingCapturePlan | SdrDiskCapturePlan | HdrLayeredCapturePlan;
+/**
+ * Telemetry name for the stage a plan runs on. Exhaustive over `CapturePlan`,
+ * so a new plan kind fails to compile until it declares its capture path
+ * rather than silently reporting the wrong one.
+ */
+export function capturePathForPlanKind(kind: CapturePlan["kind"]): CapturePath {
+ switch (kind) {
+ case "sdr_streaming":
+ return "streaming";
+ case "sdr_disk":
+ return "disk";
+ case "hdr_layered":
+ return "hdr_layered";
+ }
+}
+
export interface CreateCapturePlanInput {
workerCount: number;
forceScreenshot: boolean;
diff --git a/packages/producer/src/services/render/observability.ts b/packages/producer/src/services/render/observability.ts
index 705756b66a..a1d1a2c6c6 100644
--- a/packages/producer/src/services/render/observability.ts
+++ b/packages/producer/src/services/render/observability.ts
@@ -30,6 +30,12 @@ export interface BrowserDiagnosticSummary {
consoleWarnings: number;
}
+/**
+ * Which capture stage produced the frames. Maps 1:1 from `CapturePlan.kind`
+ * (see `capturePathForPlanKind`); named in render telemetry as `capture_path`.
+ */
+export type CapturePath = "streaming" | "disk" | "segmented" | "hdr_layered";
+
export interface RenderCaptureObservability {
forceScreenshot: boolean;
captureMode: "screenshot" | "beginframe";
@@ -176,6 +182,23 @@ export interface RenderCaptureObservability {
*/
transientRetries?: number;
memoryExhaustionDetected?: boolean;
+ /**
+ * Chrome process memory from the engine's per-session sampler (Phase −1 of
+ * the long-form render plan). Updated live during capture so a
+ * render_error still carries the last known state — the failure path never
+ * builds a RenderPerfSummary, so this is the only channel that survives a
+ * mid-capture target loss.
+ */
+ chromeBrowserRssPeakMb?: number;
+ chromeRendererRssPeakMb?: number;
+ chromeRssLastMb?: number;
+ chromeGpuProcessSeenLastSample?: boolean;
+ chromeMemorySamples?: number;
+ /** Which capture stage ran. Set once the capture plan resolves. */
+ capturePath?: CapturePath;
+ /** Segmented capture only (Phase 2): current segment and retries so far. */
+ segmentIndex?: number;
+ segmentRetries?: number;
}
export interface RenderExtractionObservability {
diff --git a/packages/producer/src/services/render/perfSummary-chromeMemory.test.ts b/packages/producer/src/services/render/perfSummary-chromeMemory.test.ts
new file mode 100644
index 0000000000..ec881e6c23
--- /dev/null
+++ b/packages/producer/src/services/render/perfSummary-chromeMemory.test.ts
@@ -0,0 +1,101 @@
+import { describe, it, expect } from "vitest";
+import type { CapturePerfSummary } from "@hyperframes/engine";
+import { buildRenderPerfSummary } from "./perfSummary.js";
+import { createRenderJob } from "../renderOrchestrator.js";
+
+function baseInput(
+ dedupPerfs: CapturePerfSummary[],
+ overrides: Partial<Parameters<typeof buildRenderPerfSummary>[0]> = {},
+) {
+ return {
+ job: createRenderJob({ fps: { num: 30, den: 1 }, quality: "high" }),
+ workerCount: dedupPerfs.length || 1,
+ enableChunkedEncode: false,
+ chunkedEncodeSize: 0,
+ compositionDurationSeconds: 5,
+ totalFrames: 150,
+ outputWidth: 1920,
+ outputHeight: 1080,
+ videoCount: 0,
+ audioCount: 0,
+ totalElapsedMs: 1000,
+ perfStages: {},
+ videoExtractBreakdown: undefined,
+ tmpPeakBytes: 0,
+ captureAttempts: [],
+ hdrDiagnostics: { videoExtractionFailures: 0, imageDecodeFailures: 0 },
+ peakRssBytes: 0,
+ peakHeapUsedBytes: 0,
+ dedupPerfs,
+ ...overrides,
+ };
+}
+
+function perf(overrides: Partial<CapturePerfSummary>): CapturePerfSummary {
+ return {
+ frames: 10,
+ avgTotalMs: 1,
+ avgSeekMs: 1,
+ avgBeforeCaptureMs: 0,
+ avgScreenshotMs: 0,
+ staticDedupReused: 0,
+ staticDedupEnabled: false,
+ staticDedupArmed: false,
+ staticDedupPredicted: 0,
+ ...overrides,
+ };
+}
+
+describe("aggregateChromeMemory", () => {
+ it("takes the max peak across workers and the sum of samples", () => {
+ const summary = buildRenderPerfSummary(
+ baseInput([
+ perf({
+ chromeBrowserRssPeakMb: 100,
+ chromeRendererRssPeakMb: 900,
+ chromeRssLastMb: 1000,
+ chromeGpuProcessSeenLastSample: true,
+ chromeMemorySamples: 5,
+ }),
+ perf({
+ chromeBrowserRssPeakMb: 120,
+ chromeRendererRssPeakMb: 700,
+ chromeRssLastMb: 800,
+ chromeGpuProcessSeenLastSample: false,
+ chromeMemorySamples: 4,
+ }),
+ ]),
+ );
+ expect(summary.chromeMemory).toEqual({
+ browserRssPeakMb: 120,
+ rendererRssPeakMb: 900,
+ rssLastMb: 1800,
+ gpuProcessSeenLastSample: true,
+ samples: 9,
+ });
+ });
+
+ it("is undefined when no session sampled", () => {
+ const summary = buildRenderPerfSummary(baseInput([perf({})]));
+ expect(summary.chromeMemory).toBeUndefined();
+ });
+
+ it("aggregates a mixed fleet where only some workers sampled", () => {
+ // A worker whose sampler never produced a reading must not drag the
+ // result: no renderer peak invented, and gpuProcessSeenLastSample stays
+ // false rather than inheriting the sampling worker's `undefined`.
+ const summary = buildRenderPerfSummary(
+ baseInput([
+ perf({ chromeMemorySamples: 0 }),
+ perf({ chromeBrowserRssPeakMb: 42, chromeRssLastMb: 42, chromeMemorySamples: 3 }),
+ ]),
+ );
+ expect(summary.chromeMemory).toEqual({
+ browserRssPeakMb: 42,
+ rendererRssPeakMb: undefined,
+ rssLastMb: 42,
+ gpuProcessSeenLastSample: false,
+ samples: 3,
+ });
+ });
+});
diff --git a/packages/producer/src/services/render/perfSummary.ts b/packages/producer/src/services/render/perfSummary.ts
index 187a462839..b77327005b 100644
--- a/packages/producer/src/services/render/perfSummary.ts
+++ b/packages/producer/src/services/render/perfSummary.ts
@@ -189,6 +189,30 @@ function aggregateDrawElement(
};
}
+function maxDefined(values: Array<number | undefined>): number | undefined {
+ const present = values.filter((v): v is number => typeof v === "number");
+ return present.length > 0 ? Math.max(...present) : undefined;
+}
+
+/**
+ * Chrome memory across capture sessions: max of per-session peaks, sum of the
+ * last samples. Sessions that never produced a reading are excluded so
+ * `samples: 0` cannot be published alongside another worker's real peaks.
+ */
+function aggregateChromeMemory(perfs: CapturePerfSummary[]): RenderPerfSummary["chromeMemory"] {
+ const sampled = perfs.filter((p) => (p.chromeMemorySamples ?? 0) > 0);
+ if (sampled.length === 0) return undefined;
+ return {
+ browserRssPeakMb: maxDefined(sampled.map((p) => p.chromeBrowserRssPeakMb)),
+ rendererRssPeakMb: maxDefined(sampled.map((p) => p.chromeRendererRssPeakMb)),
+ // Last samples are per session; summing approximates the whole fleet's
+ // footprint at the end of capture (workers run concurrently).
+ rssLastMb: sampled.reduce((sum, p) => sum + (p.chromeRssLastMb ?? 0), 0),
+ gpuProcessSeenLastSample: sampled.some((p) => p.chromeGpuProcessSeenLastSample === true),
+ samples: sampled.reduce((sum, p) => sum + (p.chromeMemorySamples ?? 0), 0),
+ };
+}
+
function aggregateDedup(perfs: CapturePerfSummary[]): RenderPerfSummary["staticDedup"] {
if (perfs.length === 0) return undefined;
const armed = perfs.some((p) => p.staticDedupArmed);
@@ -357,6 +381,7 @@ export function buildRenderPerfSummary(input: {
peakRssMb: Math.round(input.peakRssBytes / (1024 * 1024)),
peakHeapUsedMb: Math.round(input.peakHeapUsedBytes / (1024 * 1024)),
staticDedup: aggregateDedup(input.dedupPerfs),
+ chromeMemory: aggregateChromeMemory(input.dedupPerfs),
beginFrameReuse: aggregateBeginFrameReuse(input.dedupPerfs),
drawElement: aggregateDrawElement(
input.dedupPerfs,
diff --git a/packages/producer/src/services/renderOrchestrator.ts b/packages/producer/src/services/renderOrchestrator.ts
index 6863058201..973f6c03db 100644
--- a/packages/producer/src/services/renderOrchestrator.ts
+++ b/packages/producer/src/services/renderOrchestrator.ts
@@ -133,6 +133,7 @@ import {
commitArtifactTransaction,
} from "./render/artifactTransaction.js";
import {
+ capturePathForPlanKind,
createCapturePlan,
replanAfterFailure,
streamingCaptureFailure,
@@ -492,6 +493,14 @@ export interface RenderPerfSummary {
* inside the orchestrator. Optional for the same back-compat reason.
*/
peakHeapUsedMb?: number;
+ /** Chrome process memory aggregated across capture sessions (max of peaks, sum of samples). */
+ chromeMemory?: {
+ browserRssPeakMb?: number;
+ rendererRssPeakMb?: number;
+ rssLastMb?: number;
+ gpuProcessSeenLastSample?: boolean;
+ samples: number;
+ };
hdrDiagnostics?: HdrDiagnostics;
hdrPerf?: HdrPerfSummary;
/**
@@ -3291,6 +3300,20 @@ async function executeRenderPipeline(input: {
// sample frame indices from this so they land inside the drained range.
compositionDurationSeconds: job.duration,
requiresWebGpu: compositionRequiresWebGpu(compiled.html),
+ // Live route for Chrome memory (spec §5 Phase −1). The aggregate route
+ // through CapturePerfSummary only exists on success; a mid-capture
+ // target loss never builds one, and that is the case this telemetry is
+ // for. With parallel workers each session reports through the same
+ // callback, so the record holds the most recent session's stats.
+ onMemorySample: (stats) => {
+ updateCaptureObservability({
+ chromeBrowserRssPeakMb: stats.browserRssPeakMb,
+ chromeRendererRssPeakMb: stats.rendererRssPeakMb,
+ chromeRssLastMb: stats.rssLastMb,
+ chromeGpuProcessSeenLastSample: stats.gpuProcessSeenLastSample,
+ chromeMemorySamples: stats.samples,
+ });
+ },
});
// The URL-served frame path (PR #596) hands each injected `<img>` a
// fileServer URL instead of a base64 data URI, on the theory that
@@ -4056,6 +4079,10 @@ async function executeRenderPipeline(input: {
if (capturePlan.routing.kind === "parallel_router") {
deParallelRouter = capturePlan.routing.state === "active" ? "routed" : "reverted";
}
+ // Recorded here rather than beside the streaming-encode gate log: this
+ // runs for the initial plan AND every replan, so a render that falls
+ // back to disk reports the path it actually captured on.
+ updateCaptureObservability({ capturePath: capturePathForPlanKind(capturePlan.kind) });
};
syncCapturePlan();
updateCaptureObservability({