Skip to content

armgit / 67.js

Public Imported from GitHub
0

3D engine that AI agents drive

Estimate a render job's time and memory before it runs and report what it used (#905)

Nguyen Xuan An481dea64a7b9
diff --git a/changes/905-estimate.md b/changes/905-estimate.md
new file mode 100644
index 00000000..c81cd2c0
--- /dev/null
+++ b/changes/905-estimate.md
@@ -0,0 +1 @@
+- `scene_render_submit` returns the expected time and peak memory of a render job before it runs, and `scene_render_result` ends with one report of the measured time, peak memory, samples drawn and what fell back and why (#905)
diff --git a/docs/mcp.md b/docs/mcp.md
index 30991f4d..5c713eb6 100644
--- a/docs/mcp.md
+++ b/docs/mcp.md
@@ -190,6 +190,18 @@ Imported clip sampling remains available through `set-animation`.
`scene_ask_user` is for a change the person cannot put in words. It renders the current view, opens it in their default browser on a loopback address under a random path, and waits up to `timeoutSeconds` (default 300, at most 900) for them to pin up to 16 points with a note of at most 280 characters each and press Send. Each mark comes back with its pixel, the `partId` and world `point` and `normal` the pin lands on (all `null` on empty sky), the `distance` from the camera and the part's `material`, plus the `view` camera and a PNG with the numbered pins. A cancelled or timed-out page returns `outcome` `cancelled` or `timeout` with no marks. Nothing leaves the machine and the tool takes no code or remote URL. Not yet marks: lasso regions, dragged transforms, colours, saved views and film times (issue #922 lists them).
+### Render estimate and report
+
+`scene_render_submit` returns `estimate` beside the job record, so an agent can see what a job costs on this device before it waits for it: `seconds`, `peakMemoryMiB` (Node plus browser heap), `framesPerSecond`, `basis` and the scene numbers it used (`parts`, `triangles` counting every placed node, `materials`, `textures`, `lights`). `scene_capabilities` topic `jobs` has the one-line summary.
+
+The estimate is a fixed cost model in `scripts/agent-render-estimate.mjs` (`COST_MODEL`): a start-up cost, a scene build cost per triangle, a per-frame cost from pixels, triangles, lights and passes, and for the path tracer a cost per pixel, sample and bounce (capped by `renderer.maxSeconds`) plus a build cost per triangle. The first GPU path trace in a server process adds about 10 s for its kernel. The same scene and settings always give the same numbers. The constants were fitted to jobs measured with `node scripts/measure-render-estimate.mjs`, which renders a small, a medium and a large scene and prints estimate against measurement; run it again after changing the model.
+
+The runtime keeps the last 16 jobs on this machine in `render-history.json` in the jobs folder: each entry holds the model's estimate and the measurement of one finished job, with its kind (raster or path tracer, image or video, backend). Once two jobs of the same kind are there, the estimate is multiplied by the median measured-over-estimated ratio of those jobs, never by more than 4 either way, and `basis` says so. The file stays on the machine; a damaged file counts as no history. `modelSeconds` and `modelPeakMemoryMiB` are the numbers before this correction.
+
+When a job completes, `scene_render_result` has `metrics.report`, one record of what happened: `measured` (`seconds`, `peakMemoryMiB`, `frames`, `secondsPerFrame`), the `estimate` it was compared with and `secondsRatio` (measured over estimated), `samplesDrawn` and `samplesRequested` for a path trace, and `fallbacks`, a list of sentences for everything that ran differently from the request (a frame cut down to fit `--memory`, a backend that fell back, a denoiser that was swapped). `report` stays in the concise answer; the raw counters it is built from (`peakNodeBytes`, `peakBrowserHeap`, `elapsedSeconds`) are in the detailed one.
+
+Limits of the estimate: it covers a job's own time, not the wait for a busy machine; memory is the sampled Node RSS plus the browser JS heap, which is a lower bound for GPU memory; path tracer estimates assume the CPU or GPU backend named in the settings, and a native tracer that cannot run falls back (see `fallbacks`).
+
### Response format
`scene_review`, `scene_render_status`, `scene_render_result` and `scene_capabilities` take `response_format`: `concise` or `detailed`.
diff --git a/scripts/agent-render-estimate.mjs b/scripts/agent-render-estimate.mjs
new file mode 100644
index 00000000..568ef5a4
--- /dev/null
+++ b/scripts/agent-render-estimate.mjs
@@ -0,0 +1,197 @@
+// What a render job will cost on this machine, and what it did cost. The estimate comes from the scene's size and the job's
+// settings alone, so the same inputs give the same answer. A correction learned from the last few jobs on this machine
+// (kept in the jobs folder, never sent anywhere) can move it, within a fixed bound.
+
+const MIB = 1024 ** 2;
+
+/** What scene_capabilities topic jobs says about the estimate and the report. The details are in docs/mcp.md. */
+export const RENDER_ESTIMATE_NOTE = 'scene_render_submit returns estimate { seconds, peakMemoryMiB, basis } for this device before the job runs (from the scene size, the settings and the last 16 jobs here; about 2x either way). scene_render_result metrics.report holds measured time and peak memory, the ratio to the estimate, samplesDrawn for the path tracer, and fallbacks (what ran differently and why).';
+
+/** Jobs kept in the history, newest last. Older ones are dropped. */
+export const HISTORY_LIMIT = 16;
+/** The history may scale the estimate by at most this factor either way, so one odd run cannot make it useless. */
+export const CORRECTION_BOUND = 4;
+/** The history needs this many runs of the same kind before it changes anything. */
+const MINIMUM_HISTORY_RUNS = 2;
+
+/**
+ * Seconds and bytes per unit of work, fitted to jobs measured with scripts/measure-render-estimate.mjs. A frame costs a fixed
+ * part, a part per pixel and a part per triangle; the scene is built once per job, which dominates large scenes. The path
+ * tracer's trace cost is per pixel, sample and bounce, and its acceleration structure costs per triangle.
+ */
+export const COST_MODEL = Object.freeze({
+ startupSeconds: 0.25,
+ setupSecondsPerTriangle: 3.3e-6,
+ drawFrameSeconds: 0.004,
+ drawSecondsPerPixel: 5e-8,
+ drawSecondsPerTriangle: 1e-8,
+ drawSecondsPerLight: 5e-4,
+ passFactor: 0.6,
+ imageCaptureSeconds: 0.02,
+ videoEncodeSeconds: 0.005,
+ pathTracerSecondsPerSampleBounce: Object.freeze({ cpu: 5e-7, gpu: 1e-7, native: 1e-7 }),
+ // The first GPU path trace in a runtime compiles its kernel; measured at about 10 s, and later traces do not pay it.
+ gpuTracerColdStartSeconds: 9.5,
+ pathTracerBuildSecondsPerTriangle: 3.7e-6,
+ pathTracerOutputSeconds: 0.03,
+ nodeBaseMiB: 185,
+ extraMiBPerPart: 1,
+ extraMiBPerThousandTriangles: 0.3,
+ maximumSceneExtraMiB: 250,
+ pathTracerExtraMiB: 30,
+ miBPerTexture: 4,
+ nodeBytesPerPixel: 24,
+});
+
+function textureCount(recipe) {
+ const text = JSON.stringify(recipe?.materials ?? []);
+ return (text.match(/"(?:map|texture|image|[a-zA-Z]+Map)"s*:/g) ?? []).length;
+}
+
+/**
+ * The numbers about the scene that the estimate uses, from the scene's inspection result (listing every node) and its recipe.
+ * Triangles count each placed node, so ten spheres cost ten spheres even when they share one geometry.
+ */
+export function sceneSizeFrom(inspection, recipe) {
+ const look = inspection?.look ?? {};
+ const listed = inspection?.nodes ?? [];
+ const listedTriangles = listed.reduce((total, node) => total + (node.triangles ?? 0), 0);
+ const scale = inspection?.truncated && listed.length ? (inspection.counts?.parts ?? listed.length) / listed.length : 1;
+ return {
+ parts: inspection?.counts?.parts ?? 0,
+ triangles: Math.round(listedTriangles * scale) || Math.round((inspection?.counts?.vertices ?? 0) / 2),
+ materials: inspection?.counts?.materials ?? 0,
+ textures: textureCount(recipe),
+ lights: (look.pointLights ?? 0) + (look.spotLights ?? 0) + (look.areaLights ?? 0) + 1,
+ };
+}
+
+function round(value, digits) {
+ const scale = 10 ** digits;
+ return Math.round(value * scale) / scale;
+}
+
+function pathTracerFrameSeconds({ size, settings, backend }) {
+ const renderer = settings.renderer;
+ const secondsPerSampleBounce = COST_MODEL.pathTracerSecondsPerSampleBounce[renderer.backend ?? backend] ?? COST_MODEL.pathTracerSecondsPerSampleBounce.cpu;
+ const traceSeconds = settings.width * settings.height * renderer.samples * renderer.bounces * secondsPerSampleBounce;
+ return Math.min(renderer.maxSeconds, traceSeconds) + size.triangles * COST_MODEL.pathTracerBuildSecondsPerTriangle + COST_MODEL.pathTracerOutputSeconds;
+}
+
+function rasterFrameSeconds({ size, settings }) {
+ const drawSeconds = COST_MODEL.drawFrameSeconds + settings.width * settings.height * COST_MODEL.drawSecondsPerPixel
+ + size.triangles * COST_MODEL.drawSecondsPerTriangle + size.lights * COST_MODEL.drawSecondsPerLight;
+ const outputSeconds = settings.kind === 'video' ? COST_MODEL.videoEncodeSeconds : COST_MODEL.imageCaptureSeconds;
+ return drawSeconds * (1 + (settings.passes?.length ?? 0) * COST_MODEL.passFactor) + outputSeconds;
+}
+
+function peakMemoryMiB({ size, settings }) {
+ const sceneMiB = Math.min(COST_MODEL.maximumSceneExtraMiB, size.parts * COST_MODEL.extraMiBPerPart + (size.triangles / 1000) * COST_MODEL.extraMiBPerThousandTriangles);
+ return COST_MODEL.nodeBaseMiB + sceneMiB + size.textures * COST_MODEL.miBPerTexture
+ + (settings.renderer ? COST_MODEL.pathTracerExtraMiB : 0) + (settings.width * settings.height * COST_MODEL.nodeBytesPerPixel) / MIB;
+}
+
+/** The kind of job a history entry and a new job share: same output kind and same way of rendering. */
+export function jobKind(settings, backend) {
+ return `${settings.renderer ? `pathTracer-${settings.renderer.backend ?? backend}` : 'raster'}-${settings.kind === 'video' ? 'video' : 'image'}-${backend}`;
+}
+
+function medianOf(values) {
+ const sorted = [...values].sort((first, second) => first - second);
+ const middle = Math.floor(sorted.length / 2);
+ return sorted.length % 2 ? sorted[middle] : (sorted[middle - 1] + sorted[middle]) / 2;
+}
+
+function boundedRatio(ratio) {
+ return Math.min(CORRECTION_BOUND, Math.max(1 / CORRECTION_BOUND, ratio));
+}
+
+/** Median of measured over estimated, from the last runs of the same kind; 1 when there are too few. */
+export function correctionFromHistory(history, kind) {
+ const runs = (history ?? []).filter(entry => entry.kind === kind && entry.estimatedSeconds > 0 && entry.measuredSeconds > 0);
+ if (runs.length < MINIMUM_HISTORY_RUNS) return { seconds: 1, memory: 1, runs: runs.length };
+ const seconds = boundedRatio(medianOf(runs.map(entry => entry.measuredSeconds / entry.estimatedSeconds)));
+ const memoryRuns = runs.filter(entry => entry.estimatedPeakMemoryMiB > 0 && entry.measuredPeakMemoryMiB > 0);
+ const memory = memoryRuns.length >= MINIMUM_HISTORY_RUNS ? boundedRatio(medianOf(memoryRuns.map(entry => entry.measuredPeakMemoryMiB / entry.estimatedPeakMemoryMiB))) : 1;
+ return { seconds, memory, runs: runs.length };
+}
+
+/**
+ * Expected time and peak memory of a job. `settings` is the normalized job settings (width, height, kind, frameCount, passes,
+ * renderer). The raw size-only numbers are `modelSeconds` and `modelPeakMemoryMiB`; the headline numbers apply the history.
+ */
+export function estimateRenderJob({ size, settings, backend, memoryBudgetMiB, history = [], gpuTracerWarm = true }) {
+ const frameSeconds = settings.renderer ? pathTracerFrameSeconds({ size, settings, backend }) : rasterFrameSeconds({ size, settings });
+ const coldStartSeconds = settings.renderer?.backend === 'gpu' && !gpuTracerWarm ? COST_MODEL.gpuTracerColdStartSeconds : 0;
+ const modelSeconds = COST_MODEL.startupSeconds + coldStartSeconds + size.triangles * COST_MODEL.setupSecondsPerTriangle + frameSeconds * settings.frameCount;
+ const modelPeakMemoryMiB = peakMemoryMiB({ size, settings });
+ const correction = correctionFromHistory(history, jobKind(settings, backend));
+ const estimate = {
+ seconds: round(modelSeconds * correction.seconds, 1),
+ peakMemoryMiB: Math.round(modelPeakMemoryMiB * correction.memory),
+ framesPerSecond: round(settings.frameCount / Math.max(0.001, modelSeconds * correction.seconds), 2),
+ basis: correction.runs >= MINIMUM_HISTORY_RUNS ? `scene size and the last ${correction.runs} ${jobKind(settings, backend)} jobs on this machine` : 'scene size',
+ modelSeconds: round(modelSeconds, 1),
+ modelPeakMemoryMiB: Math.round(modelPeakMemoryMiB),
+ scene: size,
+ };
+ if (memoryBudgetMiB !== undefined) estimate.renderTargetBudgetMiB = memoryBudgetMiB;
+ return estimate;
+}
+
+/** Facts about what did not run as asked: a budget that shrank the frame, a backend that fell back, a denoiser that was swapped. */
+function fallbacksFrom(settings, metrics) {
+ const fallbacks = [];
+ if (metrics.width && metrics.requestedWidth && (metrics.width < metrics.requestedWidth || metrics.height < metrics.requestedHeight)) {
+ fallbacks.push(`The memory budget reduced the frame from ${metrics.requestedWidth}x${metrics.requestedHeight} to ${metrics.width}x${metrics.height}.`);
+ }
+ if (metrics.pathTracer?.backendNote) fallbacks.push(metrics.pathTracer.backendNote);
+ if (metrics.pathTracer?.denoiserNote) fallbacks.push(metrics.pathTracer.denoiserNote);
+ return fallbacks;
+}
+
+/** The one record of a finished job: estimate beside what was measured, the samples drawn and what fell back. */
+export function renderReport({ estimate, settings, metrics }) {
+ const measuredSeconds = metrics.elapsedSeconds;
+ const measuredPeakMemoryMiB = Math.round(((metrics.peakNodeBytes ?? 0) + (metrics.peakBrowserHeap ?? 0)) / MIB);
+ const report = {
+ measured: { seconds: round(measuredSeconds, 2), peakMemoryMiB: measuredPeakMemoryMiB, frames: settings.frameCount, secondsPerFrame: round(measuredSeconds / settings.frameCount, 3) },
+ fallbacks: fallbacksFrom(settings, metrics),
+ };
+ if (estimate) {
+ report.estimate = { seconds: estimate.seconds, peakMemoryMiB: estimate.peakMemoryMiB, basis: estimate.basis };
+ report.secondsRatio = round(measuredSeconds / estimate.seconds, 2);
+ }
+ const traced = metrics.pathTracer;
+ if (traced) {
+ // The path tracer's report describes the last frame; the samples asked for are in the job's settings.
+ if (traced.averageSamples !== undefined) report.samplesDrawn = traced.averageSamples;
+ if (settings.renderer) report.samplesRequested = settings.renderer.samples;
+ }
+ return report;
+}
+
+/** The history with this job added, trimmed to the newest HISTORY_LIMIT entries. */
+export function historyWithJob(history, { settings, backend, estimate, report }) {
+ if (!estimate || !report.measured.seconds) return history;
+ const entry = {
+ kind: jobKind(settings, backend),
+ estimatedSeconds: estimate.modelSeconds,
+ measuredSeconds: report.measured.seconds,
+ estimatedPeakMemoryMiB: estimate.modelPeakMemoryMiB,
+ measuredPeakMemoryMiB: report.measured.peakMemoryMiB,
+ };
+ return [...history, entry].slice(-HISTORY_LIMIT);
+}
+
+/** Accepts only a plain list of well-formed entries from the history file; anything else is treated as no history. */
+export function parseHistory(text) {
+ try {
+ const parsed = JSON.parse(text);
+ if (!Array.isArray(parsed)) return [];
+ const numeric = ['estimatedSeconds', 'measuredSeconds', 'estimatedPeakMemoryMiB', 'measuredPeakMemoryMiB'];
+ return parsed.filter(entry => entry && typeof entry.kind === 'string' && numeric.every(field => Number.isFinite(entry[field]))).slice(-HISTORY_LIMIT);
+ } catch {
+ return [];
+ }
+}
diff --git a/scripts/agent-render-jobs.mjs b/scripts/agent-render-jobs.mjs
index c5182980..2b9d1bcc 100644
--- a/scripts/agent-render-jobs.mjs
+++ b/scripts/agent-render-jobs.mjs
@@ -40,7 +40,9 @@ const MAXIMUM_JSON_BYTES = 1024 ** 2;
const MAXIMUM_ASSET_BYTES = AGENT_ASSET_LIMITS.maxBytes;
/** Sibling folder of the job directories where the runtime keeps GLB exports; the store never reads or counts it. */
export const EXPORT_DIRECTORY_NAME = 'exports';
-const STORE_FILES = ['store.json', 'store.lock', EXPORT_DIRECTORY_NAME];
+/** Recent estimate-versus-measured pairs the runtime keeps beside the jobs; the store counts its bytes and never reads it. */
+export const RENDER_HISTORY_FILE = 'render-history.json';
+const STORE_FILES = ['store.json', 'store.lock', EXPORT_DIRECTORY_NAME, RENDER_HISTORY_FILE];
const INTERNAL_FILES =new Set(['owner.json', 'snapshot.json', 'asset.glb', 'status.json', 'status.json.pending']);
function objectKeys(value, allowed, label) {
@@ -94,6 +96,11 @@ function playsPhysics(recipe) {
return Boolean(recipe?.physics || recipe?.cloth || recipe?.particles);
}
+/** The settings of a job as the store keeps them: every default filled in, every limit checked. */
+export function normalizeJobSettings(input, clips, recipe) {
+ return settingsFrom(input, clips, recipe);
+}
+
function settingsFrom(input, clips, recipe) {
objectKeys(input, ['kind', 'width', 'height', 'fps', 'duration', 'animation', 'motion', 'rendererTime', 'passes', 'renderer', 'timeline', 'audio', 'encoder', 'transparent', 'format', 'multilayer', 'region'], 'settings');
if (!['image', 'stills', 'video'].includes(input.kind)) throw new TypeError('kind must be image, stills or video.');
@@ -394,7 +401,7 @@ export async function createAgentRenderJobs({ root, run, limits: inputLimits = {
let bytes = 0;
for (const name of await readdir(root)) {
if (name === EXPORT_DIRECTORY_NAME) continue;
- if (['store.json', 'store.lock'].includes(name)) {
+ if (['store.json', 'store.lock', RENDER_HISTORY_FILE].includes(name)) {
bytes += (await regularFile(join(root, name))).size;
} else {
if (isPending(name)) {
diff --git a/scripts/agent-runtime.mjs b/scripts/agent-runtime.mjs
index ec7ee173..98e4b359 100644
--- a/scripts/agent-runtime.mjs
+++ b/scripts/agent-runtime.mjs
@@ -31,7 +31,8 @@ import { catalogLookReferences, BUNDLED_ENVIRONMENT_NAMES, BUNDLED_CUBE_LOOK_NAM
import { TEXTURE_SEQUENCE_CAPABILITIES } from '../src/texture-sequence-limits.js';
import { writeWebBuild } from './web-export.mjs';
import { gameAssetIds } from '../src/game-assets.js';
-import { createAgentRenderJobs, EXPORT_DIRECTORY_NAME, HIGH_PRECISION_FRAME_FACTOR } from './agent-render-jobs.mjs';
+import { createAgentRenderJobs, EXPORT_DIRECTORY_NAME, HIGH_PRECISION_FRAME_FACTOR, RENDER_HISTORY_FILE, normalizeJobSettings } from './agent-render-jobs.mjs';
+import { RENDER_ESTIMATE_NOTE, estimateRenderJob, historyWithJob, parseHistory, renderReport, sceneSizeFrom } from './agent-render-estimate.mjs';
import { encodeRenderOutput, encodeMultilayerExr } from './render-output-encoders.mjs';
import { createFrameEncoder } from './frame-encoder.mjs';
import { DEFAULT_PAGE_ENCODER_QUANTIZER, createFrameReceiver, startVideoEncoderInPage } from './gpu-frame-reader.mjs';
@@ -139,6 +140,25 @@ export function createAgentRuntime({ kernelWorkers = true, backend = 'gpu', brow
let catalogPromise;
let packsPromise;
let jobsPromise;
+ // Set by submitJob for the one job that may run; runJob takes it. Kept in the job folder, the history never leaves the machine.
+ let estimateForNextJob;
+ let gpuTracerWarm = false;
+ async function readRenderHistory() {
+ try {
+ return parseHistory(await readFile(join(jobRoot, RENDER_HISTORY_FILE), 'utf8'));
+ } catch {
+ return [];
+ }
+ }
+ // The history only sharpens later estimates, so a failed write never fails the job that finished.
+ async function rememberRenderJob({ settings, estimate, report }) {
+ try {
+ const history = historyWithJob(await readRenderHistory(), { settings, backend, estimate, report });
+ await writeFile(join(jobRoot, RENDER_HISTORY_FILE), JSON.stringify(history), { mode: 0o600 });
+ } catch (error) {
+ console.error(`67js could not save the render history: ${error.message}`);
+ }
+ }
const savedGlbPaths = [];
const savedWebBuildPaths = [];
function jobs() {
@@ -518,6 +538,7 @@ export function createAgentRuntime({ kernelWorkers = true, backend = 'gpu', brow
async function runJob({ jobId, sessionId, directory, snapshot, settings, signal, progress }) {
let jobPage;
+ let session;
let encoder;
let frameReceiver;
// A stills or video job of native frames renders them all through one session; it is closed when the job ends.
@@ -525,8 +546,18 @@ export function createAgentRuntime({ kernelWorkers = true, backend = 'gpu', brow
let pageEncodes = false;
let suspended = false;
const started = performance.now();
+ // One job runs at a time, so the estimate made at submission belongs to the job that starts next.
+ const estimate = estimateForNextJob;
+ estimateForNextJob = undefined;
const metrics = { backend, requestedWidth: settings.width, requestedHeight: settings.height,
renderSeconds: 0, captureSeconds: 0, peakNodeBytes: 0, peakBrowserHeap: 0, maximumPendingFrames: 1 };
+ async function recordPeakMemory() {
+ metrics.peakNodeBytes = Math.max(metrics.peakNodeBytes, process.memoryUsage().rss);
+ metrics.peakBrowserHeap = Math.max(metrics.peakBrowserHeap, await sampleBrowserHeap(session));
+ if (exceedsMemoryGuard({ nodeBytes: metrics.peakNodeBytes, browserHeapBytes: metrics.peakBrowserHeap })) {
+ throw new Error('Render job exceeded its Node RSS or sampled browser heap guard.');
+ }
+ }
const abort = () => { jobPage?.close().catch(() => {}); };
signal.addEventListener('abort', abort, { once: true });
try {
@@ -551,7 +582,7 @@ export function createAgentRuntime({ kernelWorkers = true, backend = 'gpu', brow
const height = settings.kind === 'video' ? Math.floor(created.render.height / 2) * 2 : created.render.height;
if (width < 64 || height < 64) throw new Error('Render budget reduced the job below its minimum output size.');
await jobPage.setViewportSize({ width, height });
- const session = await jobPage.context().newCDPSession(jobPage);
+ session = await jobPage.context().newCDPSession(jobPage);
const region = settings.region;
if (settings.format && settings.format !== 'png') await jobPage.evaluate(prepareInput => window.__agentPreview.prepareFloatOutput(prepareInput), { sessionId: jobId });
if (settings.passes?.includes('wireframe')) await jobPage.evaluate(prepareInput => window.__agentPreview.prepareWireframe(prepareInput), { sessionId: jobId });
@@ -668,6 +699,7 @@ export function createAgentRuntime({ kernelWorkers = true, backend = 'gpu', brow
await writeFile(join(directory, `${filename}.partial`), tracedBytes, { flag: 'wx' });
artifacts.push({ temporary: `${filename}.partial`, filename, mimeType: 'image/png' });
}
+ await recordPeakMemory();
await progress({ frames: frame + 1, maximumPendingFrames: 1 });
continue;
}
@@ -774,12 +806,7 @@ export function createAgentRuntime({ kernelWorkers = true, backend = 'gpu', brow
}
}
}
- metrics.peakNodeBytes = Math.max(metrics.peakNodeBytes, process.memoryUsage().rss);
- const heapBytes = await sampleBrowserHeap(session);
- metrics.peakBrowserHeap = Math.max(metrics.peakBrowserHeap, heapBytes);
- if (exceedsMemoryGuard({ nodeBytes: metrics.peakNodeBytes, browserHeapBytes: metrics.peakBrowserHeap })) {
- throw new Error('Render job exceeded its Node RSS or sampled browser heap guard.');
- }
+ await recordPeakMemory();
await progress({ frames: frame + 1, maximumPendingFrames: 1 });
}
if (encoder) {
@@ -789,6 +816,9 @@ export function createAgentRuntime({ kernelWorkers = true, backend = 'gpu', brow
artifacts.push({ temporary: 'render.mp4.partial', filename: 'render.mp4', mimeType: 'video/mp4' });
}
metrics.elapsedSeconds = (performance.now() - started) / 1000;
+ metrics.report = renderReport({ estimate, settings, metrics });
+ if (settings.renderer?.backend === 'gpu') gpuTracerWarm = true;
+ await rememberRenderJob({ settings, estimate, report: metrics.report });
return { artifacts, metrics };
} finally {
signal.removeEventListener('abort', abort);
@@ -866,7 +896,7 @@ export function createAgentRuntime({ kernelWorkers = true, backend = 'gpu', brow
maximumFileBytes: MAXIMUM_PACK_FILE_BYTES, maximumJsonBytes: MAXIMUM_PACK_JSON_BYTES, maximumItemsPerKind: MAXIMUM_PACK_ITEMS_PER_KIND,
use: 'scene_asset_catalog lists packs: name, version, license, author, description and item ids. GLBs, images, looks and environments carry assetId values that work in scene_create_asset, look, hdri and texture fields. Materials and recipes are read with scene_asset_catalog { pack, material } or { pack, recipe }: pass a recipe to scene_create, and a material as a materials entry or a scene_apply set-material. Packs are installed by the user (unzip into the --packs folder); a tool call never downloads one. Invalid packs are skipped and listed under packs.rejected with the reason.',
},
- jobs: { configured: Boolean(jobRoot), kinds: ['image', 'stills', 'video'], passes: RENDER_PASS_NAMES, pathTracer: PATH_TRACER_CAPABILITIES, maximumActiveJobs: 1,
+ jobs: { configured: Boolean(jobRoot), kinds: ['image', 'stills', 'video'], passes: RENDER_PASS_NAMES, pathTracer: PATH_TRACER_CAPABILITIES, maximumActiveJobs: 1, estimate: RENDER_ESTIMATE_NOTE,
maximumWidth: MAXIMUM_JOB_SIDE, maximumHeight: MAXIMUM_JOB_SIDE, maximumPixels: MAXIMUM_JOB_PIXELS,
maximumDuration: MAXIMUM_VIDEO_SECONDS, maximumFps: 30, maximumFrames: 900, maximumStills: 8,
encoder: 'H.264', encoders: VIDEO_ENCODERS, audio: Boolean(audioRoot), timeline: true, previewSuspendedDuringJob: true,
@@ -1228,8 +1258,18 @@ export function createAgentRuntime({ kernelWorkers = true, backend = 'gpu', brow
const assetBytes = snapshot.recipe.format === '67js.asset' ? await (await catalog()).read(snapshot.recipe.assetId) : undefined;
phase = 'rendering';
try {
- return await controller.submit({ sessionId, sourceRevision: snapshot.sourceRevision,
- snapshot: { recipe: snapshot.recipe, clips: snapshot.clips, ...(assetBytes ? { assetBytes } : {}) }, settings });
+ // The estimate is made before the job exists, because the job suspends the scene and starts at once.
+ const size = sceneSizeFrom(await invoke('inspect', { sessionId, limit: Math.max(1, snapshot.recipe.nodes?.length ?? 1) }), snapshot.recipe);
+ const estimate = estimateRenderJob({ size, settings: normalizeJobSettings(settings, snapshot.clips, snapshot.recipe), backend, memoryBudgetMiB: memory, history: await readRenderHistory(), gpuTracerWarm });
+ estimateForNextJob = estimate;
+ try {
+ const submitted = await controller.submit({ sessionId, sourceRevision: snapshot.sourceRevision,
+ snapshot: { recipe: snapshot.recipe, clips: snapshot.clips, ...(assetBytes ? { assetBytes } : {}) }, settings });
+ return { ...submitted, estimate };
+ } catch (error) {
+ if (estimateForNextJob === estimate) estimateForNextJob = undefined;
+ throw error;
+ }
} catch (error) {
phase = 'ready';
throw error;
diff --git a/scripts/measure-render-estimate.mjs b/scripts/measure-render-estimate.mjs
new file mode 100644
index 00000000..94c59fe0
--- /dev/null
+++ b/scripts/measure-render-estimate.mjs
@@ -0,0 +1,102 @@
+// Compares the render estimate with real jobs. Builds a small, a medium and a large scene, renders short previews of each through
+// the MCP runtime and prints the estimate next to the measured time and memory as a table.
+// node scripts/measure-render-estimate.mjs [--backend gpu|cpu] [--json]
+// On a shared machine run it through your GPU job lock, so it waits for a free card.
+import { mkdtemp } from 'node:fs/promises';
+import { tmpdir, constants, setPriority } from 'node:os';
+import { join, resolve } from 'node:path';
+import { setTimeout as delay } from 'node:timers/promises';
+import { Client } from '@modelcontextprotocol/client';
+import { StdioClientTransport } from '@modelcontextprotocol/client/stdio';
+
+setPriority(0, constants.priority.PRIORITY_BELOW_NORMAL);
+const backendArgument = process.argv.indexOf('--backend');
+const backend = backendArgument > 0 ? process.argv[backendArgument + 1] : 'gpu';
+const printJson = process.argv.includes('--json');
+
+const SCENES = [
+ { name: 'small', spheres: 3, segments: 16, rings: 10, pointLights: 1 },
+ { name: 'medium', spheres: 120, segments: 32, rings: 20, pointLights: 4 },
+ { name: 'large', spheres: 400, segments: 64, rings: 40, pointLights: 8, rasterOnly: true },
+];
+
+const JOBS = [
+ { label: 'image 640x360', settings: { kind: 'image', width: 640, height: 360 } },
+ { label: 'video 24f 480x270', settings: { kind: 'video', width: 480, height: 270, fps: 12, duration: 2 } },
+ { label: 'path trace cpu 160x90', settings: { kind: 'image', width: 160, height: 90, renderer: { type: 'pathTracer', backend: 'cpu', samples: 16, bounces: 2, maxSeconds: 20 } } },
+ { label: 'path trace gpu 256x144', settings: { kind: 'image', width: 256, height: 144, renderer: { type: 'pathTracer', backend: 'gpu', samples: 32, bounces: 3, maxSeconds: 20 } } },
+];
+
+function recipeFor({ spheres, segments, rings, pointLights }) {
+ const columns = Math.ceil(Math.sqrt(spheres));
+ const nodes = [{ id: 'floor', geometry: 'box', material: 'matte', translation: [0, -0.1, 0], scale: [columns * 1.2 + 4, 0.2, columns * 1.2 + 4] }];
+ for (let index = 0; index < spheres; index++) {
+ const column = index % columns;
+ const row = Math.floor(index / columns);
+ nodes.push({ id: `ball-${index}`, geometry: 'sphere', material: index % 2 ? 'matte' : 'glow', translation: [(column - columns / 2) * 1.2, 0.5, (row - columns / 2) * 1.2], scale: [0.5, 0.5, 0.5] });
+ }
+ const span = columns * 0.6 + 4;
+ return {
+ format: '67js.scene', schemaVersion: 1,
+ geometries: [{ id: 'box', type: 'box' }, { id: 'sphere', type: 'sphere', segments, rings }],
+ materials: [{ id: 'matte', color: [0.7, 0.7, 0.7], roughness: 0.6 }, { id: 'glow', color: [0.1, 0.3, 0.9], emission: 1 }],
+ nodes,
+ environment: { pointLights: Array.from({ length: pointLights }, (_, index) => ({ position: [index - pointLights / 2, 3, 2], intensity: 20, color: [1, 1, 1] })) },
+ camera: { eye: [0, span * 0.5, span], target: [0, 0, 0], fov: 40 },
+ };
+}
+
+const directory = await mkdtemp(join(tmpdir(), '67js-estimate-'));
+const transport = new StdioClientTransport({ command: process.execPath,
+ args: [resolve('bin/67js-mcp.mjs'), '--backend', backend, '--memory', '256', '--jobs', join(directory, 'jobs')], cwd: directory, stderr: 'pipe' });
+const client = new Client({ name: '67js-estimate-measure', version: '1' });
+
+async function call(name, argumentsValue = {}, timeout = 120000) {
+ const result = await client.callTool({ name, arguments: argumentsValue }, { timeout });
+ if (result.isError) throw new Error(result.content?.find(item => item.type === 'text')?.text);
+ return result;
+}
+
+async function untilFinished(jobId) {
+ const deadline = Date.now() + 300000;
+ while (Date.now() < deadline) {
+ const record = (await call('scene_render_status', { jobId })).structuredContent;
+ if (['completed', 'cancelled', 'failed'].includes(record.state)) return record;
+ await delay(100);
+ }
+ throw new Error('Job did not finish within 300 seconds.');
+}
+
+const rows = [];
+try {
+ await client.connect(transport);
+ for (const scene of SCENES) {
+ const created = (await call('scene_create', { recipe: recipeFor(scene) }, 300000)).structuredContent;
+ for (const job of JOBS.filter(job => !(scene.rasterOnly && job.settings.renderer))) {
+ try {
+ const started = performance.now();
+ const submitted = (await call('scene_render_submit', { sessionId: created.sessionId, expectedRevision: created.revision ?? 0, settings: job.settings })).structuredContent;
+ const record = await untilFinished(submitted.jobId);
+ const wallSeconds = (performance.now() - started) / 1000;
+ const result = record.state === 'completed' ? (await call('scene_render_result', { jobId: submitted.jobId, response_format: 'detailed' })).structuredContent : undefined;
+ rows.push({ scene: scene.name, job: job.label, state: record.state, reason: record.reason, wallSeconds, estimate: submitted.estimate, report: result?.metrics?.report, metrics: result?.metrics });
+ if (result) await call('scene_render_release', { jobId: submitted.jobId });
+ } catch (error) {
+ rows.push({ scene: scene.name, job: job.label, state: 'error', reason: error.message });
+ }
+ }
+ await call('scene_dispose', { sessionId: created.sessionId });
+ }
+} finally {
+ await client.close();
+}
+
+if (printJson) console.log(JSON.stringify(rows, null, 2));
+console.log('| scene | job | estimate s | model-only s | measured s | ratio | estimate MiB | measured MiB |');
+console.log('| --- | --- | --- | --- | --- | --- | --- | --- |');
+for (const row of rows) {
+ const measuredSeconds = row.metrics?.elapsedSeconds;
+ const measuredMiB = row.report?.measured?.peakMemoryMiB;
+ const ratio = row.estimate && measuredSeconds ? (row.estimate.seconds / measuredSeconds).toFixed(2) : '-';
+ console.log(`| ${row.scene} | ${row.job} | ${row.estimate?.seconds ?? "-"} | ${row.estimate?.modelSeconds ?? "-"} | ${measuredSeconds?.toFixed(2) ?? row.state + ' ' + (row.reason ?? '')} | ${ratio} | ${row.estimate?.peakMemoryMiB ?? '-'} | ${measuredMiB ?? '-'} |`);
+}
diff --git a/tests/agent-runtime.test.js b/tests/agent-runtime.test.js
index c11accc6..d89efbc8 100644
--- a/tests/agent-runtime.test.js
+++ b/tests/agent-runtime.test.js
@@ -9,13 +9,14 @@ import { tmpdir } from 'node:os';
import { isAbsolute, join } from 'node:path';
import { fileURLToPath, pathToFileURL } from 'node:url';
import { writeWebBuild } from '../scripts/web-export.mjs';
-import { EXPORT_DIRECTORY_NAME } from '../scripts/agent-render-jobs.mjs';
+import { EXPORT_DIRECTORY_NAME, RENDER_HISTORY_FILE, normalizeJobSettings } from '../scripts/agent-render-jobs.mjs';
import { createServer } from 'node:http';
import { createHash, randomUUID } from 'node:crypto';
import { createContext, Script } from 'node:vm';
import { VEGETATION_CAPABILITY_NOTE } from '../src/agent-vegetation-notes.js';
import { CROWD_CAPABILITY_NOTE } from '../src/agent-crowd-notes.js';
import { SETTLE_CAPABILITY_NOTE } from '../src/settle-notes.js';
+import { RENDER_ESTIMATE_NOTE, estimateRenderJob, historyWithJob, parseHistory, renderReport, sceneSizeFrom } from '../scripts/agent-render-estimate.mjs';
import { GAME_CAPABILITIES } from '../src/game-setup-notes.js';
import { USER_PASS_CAPABILITIES } from '../src/user-pass.js';
import { MESH_BLEND_CAPABILITIES } from '../src/mesh-blend.js';
@@ -131,7 +132,7 @@ async function reviewRuntimeHarness({ failShot, blockShot = false, oversize = fa
audioInputArguments, createAudioLibrary, measureStreamSeconds, filmTimelineDuration, filmTimelineShotStarts, sampleFilmTimeline, normalizeReview, REVIEW_LIMITS, isPreviewHost, BRANCH_LIMITS, validateBranchName, sessionProblem, SCENE_STORE_LIMITS,
runAnnotateSession: async () => ({ outcome: 'timeout' }), openInDefaultBrowser: async () => {}, ANNOTATE_LIMITS,
...packLimits, createPackRegistry,
- sampleBrowserHeap, exceedsMemoryGuard,
+ sampleBrowserHeap, exceedsMemoryGuard, RENDER_ESTIMATE_NOTE, estimateRenderJob, historyWithJob, parseHistory, renderReport, sceneSizeFrom, RENDER_HISTORY_FILE, normalizeJobSettings,
chromium: { launch: async () => browser }, URL, Buffer, process, performance, clearTimeout,
runtimeOptions, mkdir, rm, join, isAbsolute, fileURLToPath, writeWebBuild, EXPORT_DIRECTORY_NAME, createAgentRenderJobs: async () => ({ list: () => [], close: async () => {} }), ...contextOverrides,
setTimeout: (callback, delay) => { deadlines.push(delay); return setTimeout(callback, delay); },
diff --git a/tests/render-estimate.test.js b/tests/render-estimate.test.js
new file mode 100644
index 00000000..659b4c51
--- /dev/null
+++ b/tests/render-estimate.test.js
@@ -0,0 +1,145 @@
+import test from 'node:test';
+import assert from 'node:assert/strict';
+import { mkdtemp, writeFile, readFile, rm } from 'node:fs/promises';
+import { tmpdir } from 'node:os';
+import { join } from 'node:path';
+import { createAgentRenderJobs, normalizeJobSettings, RENDER_HISTORY_FILE } from '../scripts/agent-render-jobs.mjs';
+import {
+ CORRECTION_BOUND, HISTORY_LIMIT, correctionFromHistory, estimateRenderJob, historyWithJob, jobKind, parseHistory, renderReport, sceneSizeFrom,
+} from '../scripts/agent-render-estimate.mjs';
+
+const recipe = { format: '67js.scene', materials: [{ id: 'wood', map: 'planks' }, { id: 'steel', normalMap: 'dents' }, { id: 'plain' }] };
+
+function inspection({ nodeCount, trianglesEach, truncated = false, parts = nodeCount }) {
+ return {
+ counts: { nodes: nodeCount, parts, geometries: 1, materials: 3, vertices: trianglesEach },
+ look: { pointLights: 2, spotLights: 1, areaLights: 0 },
+ nodes: Array.from({ length: nodeCount }, (_, index) => ({ id: `part-${index}`, triangles: trianglesEach })),
+ truncated,
+ };
+}
+
+function settingsFor(overrides) {
+ return normalizeJobSettings({ kind: 'image', width: 640, height: 360, ...overrides }, [], { format: '67js.scene' });
+}
+
+test('scene size counts every placed node, textures and lights', () => {
+ const size = sceneSizeFrom(inspection({ nodeCount: 10, trianglesEach: 1200 }), recipe);
+ assert.deepEqual(size, { parts: 10, triangles: 12000, materials: 3, textures: 2, lights: 4 });
+});
+
+test('a truncated node list is scaled up to the part count', () => {
+ const size = sceneSizeFrom(inspection({ nodeCount: 64, trianglesEach: 100, truncated: true, parts: 640 }), recipe);
+ assert.equal(size.triangles, 64000);
+});
+
+test('with no node list the vertex count stands in for the triangle count', () => {
+ const size = sceneSizeFrom({ counts: { parts: 1, vertices: 3000 }, nodes: [] }, {});
+ assert.equal(size.triangles, 1500);
+});
+
+test('the same scene and settings always give the same estimate', () => {
+ const size = sceneSizeFrom(inspection({ nodeCount: 50, trianglesEach: 2000 }), recipe);
+ const settings = settingsFor({ kind: 'video', width: 480, height: 270, fps: 12, duration: 2 });
+ const first = estimateRenderJob({ size, settings, backend: 'gpu' });
+ const second = estimateRenderJob({ size, settings, backend: 'gpu' });
+ assert.deepEqual(first, second);
+ assert.equal(first.basis, 'scene size');
+ assert.equal(first.seconds, first.modelSeconds);
+});
+
+test('more triangles, more frames and bigger frames cost more time', () => {
+ const small = sceneSizeFrom(inspection({ nodeCount: 5, trianglesEach: 500 }), recipe);
+ const large = sceneSizeFrom(inspection({ nodeCount: 300, trianglesEach: 5000 }), recipe);
+ const image = settingsFor({});
+ const video = settingsFor({ kind: 'video', fps: 12, duration: 4, width: 640, height: 360 });
+ const estimate = (size, settings) => estimateRenderJob({ size, settings, backend: 'gpu' });
+ assert.ok(estimate(large, image).seconds > estimate(small, image).seconds);
+ assert.ok(estimate(small, video).seconds > estimate(small, image).seconds);
+ assert.ok(estimate(large, image).peakMemoryMiB > estimate(small, image).peakMemoryMiB);
+ assert.ok(estimate(large, settingsFor({ kind: 'video', width: 1920, height: 1080, fps: 24, duration: 5 })).seconds > estimate(large, settingsFor({ kind: 'video', width: 480, height: 270, fps: 24, duration: 5 })).seconds);
+});
+
+test('the path tracer is capped by maxSeconds and the first GPU trace pays for its kernel', () => {
+ const size = sceneSizeFrom(inspection({ nodeCount: 20, trianglesEach: 1000 }), recipe);
+ const longTrace = settingsFor({ width: 640, height: 360, renderer: { type: 'pathTracer', backend: 'cpu', samples: 1024, bounces: 8, maxSeconds: 5 } });
+ assert.ok(estimateRenderJob({ size, settings: longTrace, backend: 'gpu' }).seconds < 5 + 5);
+ const gpuTrace = settingsFor({ width: 256, height: 144, renderer: { type: 'pathTracer', backend: 'gpu', samples: 32, bounces: 3, maxSeconds: 30 } });
+ const cold = estimateRenderJob({ size, settings: gpuTrace, backend: 'gpu', gpuTracerWarm: false });
+ const warm = estimateRenderJob({ size, settings: gpuTrace, backend: 'gpu', gpuTracerWarm: true });
+ assert.ok(cold.seconds - warm.seconds > 5);
+});
+
+function historyEntry(ratio, kind = 'raster-image-gpu') {
+ return { kind, estimatedSeconds: 2, measuredSeconds: 2 * ratio, estimatedPeakMemoryMiB: 200, measuredPeakMemoryMiB: 200 * ratio };
+}
+
+test('history needs two runs of the same kind and moves the estimate by their median', () => {
+ assert.deepEqual(correctionFromHistory([historyEntry(3)], 'raster-image-gpu'), { seconds: 1, memory: 1, runs: 1 });
+ assert.equal(correctionFromHistory([historyEntry(3), historyEntry(2), historyEntry(1.5)], 'raster-image-gpu').seconds, 2);
+ assert.equal(correctionFromHistory([historyEntry(3), historyEntry(2)], 'raster-video-gpu').runs, 0);
+ const size = sceneSizeFrom(inspection({ nodeCount: 5, trianglesEach: 500 }), recipe);
+ const settings = settingsFor({});
+ const base = estimateRenderJob({ size, settings, backend: 'gpu' });
+ const corrected = estimateRenderJob({ size, settings, backend: 'gpu', history: [historyEntry(2), historyEntry(2)] });
+ assert.equal(corrected.modelSeconds, base.modelSeconds);
+ assert.ok(Math.abs(corrected.seconds - base.modelSeconds * 2) < 0.1);
+ assert.match(corrected.basis, /last 2 raster-image-gpu jobs/);
+});
+
+test('the correction is bounded either way', () => {
+ assert.equal(correctionFromHistory([historyEntry(100), historyEntry(100)], 'raster-image-gpu').seconds, CORRECTION_BOUND);
+ assert.equal(correctionFromHistory([historyEntry(0.001), historyEntry(0.001)], 'raster-image-gpu').seconds, 1 / CORRECTION_BOUND);
+});
+
+test('the history keeps the newest entries only', () => {
+ const settings = settingsFor({});
+ const estimate = { modelSeconds: 1, modelPeakMemoryMiB: 200 };
+ const report = { measured: { seconds: 1.5, peakMemoryMiB: 220 } };
+ let history = [];
+ for (let run = 0; run < HISTORY_LIMIT + 5; run++) history = historyWithJob(history, { settings, backend: 'gpu', estimate, report });
+ assert.equal(history.length, HISTORY_LIMIT);
+ assert.equal(history[0].kind, jobKind(settings, 'gpu'));
+ assert.equal(historyWithJob(history, { settings, backend: 'gpu', estimate: undefined, report }), history);
+});
+
+test('a damaged history file counts as no history', () => {
+ assert.deepEqual(parseHistory('not json'), []);
+ assert.deepEqual(parseHistory('{"kind":"x"}'), []);
+ assert.deepEqual(parseHistory(JSON.stringify([{ kind: 'x', estimatedSeconds: 'slow' }, historyEntry(2)])), [historyEntry(2)]);
+ assert.equal(parseHistory(JSON.stringify(Array.from({ length: 100 }, () => historyEntry(2)))).length, HISTORY_LIMIT);
+});
+
+test('the report puts the estimate, the measurement and what fell back in one record', () => {
+ const settings = settingsFor({ width: 1920, height: 1080, renderer: { type: 'pathTracer', backend: 'native', samples: 64 } });
+ const metrics = {
+ elapsedSeconds: 12.345, peakNodeBytes: 300 * 1024 ** 2, peakBrowserHeap: 100 * 1024 ** 2, requestedWidth: 1920, requestedHeight: 1080, width: 1280, height: 720,
+ pathTracer: { averageSamples: 48, backendNote: 'No native tracer was found. The gpu backend ran instead.', denoiserNote: 'OIDN is not installed; the wavelet denoiser ran.' },
+ };
+ const report = renderReport({ estimate: { seconds: 10, peakMemoryMiB: 350, basis: 'scene size' }, settings, metrics });
+ assert.deepEqual(report.measured, { seconds: 12.35, peakMemoryMiB: 400, frames: 1, secondsPerFrame: 12.345 });
+ assert.equal(report.secondsRatio, 1.23);
+ assert.equal(report.samplesDrawn, 48);
+ assert.equal(report.samplesRequested, 64);
+ assert.equal(report.fallbacks.length, 3);
+ assert.match(report.fallbacks[0], /1920x1080 to 1280x720/);
+ assert.deepEqual(renderReport({ settings: settingsFor({}), metrics: { elapsedSeconds: 1 } }).fallbacks, []);
+});
+
+test('the job store keeps the history file beside its jobs and counts it', async context => {
+ const root = await mkdtemp(join(tmpdir(), '67js-render-history-'));
+ context.after(() => rm(root, { recursive: true, force: true }));
+ const run = async ({ directory, progress }) => {
+ await writeFile(join(directory, 'render.png.partial'), Buffer.from('fixture PNG bytes'));
+ await progress({ frames: 1, maximumPendingFrames: 1 });
+ return { artifacts: [{ temporary: 'render.png.partial', filename: 'render.png', mimeType: 'image/png' }], metrics: {} };
+ };
+ const first = await createAgentRenderJobs({ root, run });
+ await first.close();
+ await writeFile(join(root, RENDER_HISTORY_FILE), JSON.stringify([historyEntry(2)]));
+ const second = await createAgentRenderJobs({ root, run });
+ const { jobId } = await second.submit({ sourceRevision: 0, snapshot: { recipe: { format: 'fixture' } }, settings: { kind: 'image', width: 64, height: 64 } });
+ while (second.status(jobId).state !== 'completed') await new Promise(resolve => setTimeout(resolve, 5));
+ await second.close();
+ assert.equal(JSON.parse(await readFile(join(root, RENDER_HISTORY_FILE), 'utf8')).length, 1);
+});