Skip to content

3D engine that AI agents drive

Let the explosion timing script choose the bake cache (#1050)

Nguyen Xuan Ande0d4cf0a797
diff --git a/docs/agent-scene.md b/docs/agent-scene.md
index c9854cda..0dee6346 100644
--- a/docs/agent-scene.md
+++ b/docs/agent-scene.md
@@ -450,7 +450,7 @@ What it writes (read it back with `scene_export_recipe`, then tweak any part):
It needs a scene with no grid volume yet (a scene draws one), a free local volume, 3 of the 4 particle systems, and a free flash and distortion slot, and fails naming the field otherwise.
Gaps: the grid is 32 cubed, so the detail is coarser than the 64 cubed preview and the smoke holds its last frame after the simulation ends; the dust is a puff, not a flat ring; there is no crater.
-Timing: `node scripts/measure-explosion-render-time.mjs --runs 3` builds a blast over a floor disc through the MCP runtime, submits an 8 s 1080p video job and prints, per run, the seconds from `scene_create` to the encoded MP4 split into `scene_apply` (the grid bake and the first draw), drawing, frame capture and encoding. Each run starts a fresh server, so the bake is cold. Run it through `gpu-lock.sh`; it stops a run that passes `--max-seconds` (180).
+Timing: `node scripts/measure-explosion-render-time.mjs --runs 3` builds a blast over a floor disc through the MCP runtime, submits an 8 s 1080p video job and prints, per run, the seconds from `scene_create` to the encoded MP4 split into `scene_apply` (the grid bake and the first draw), drawing, frame capture and encoding. Each run starts a fresh server; with the default bake cache (#1876) only the first run on a machine bakes, and `--bake-cache off` forces a cold bake every run (or pass an absolute folder for a clean cache). Run it through `gpu-lock.sh`; it stops a run that passes `--max-seconds` (180).
Reparenting changes hierarchy while preserving each node's local transform.
Commands can add or remove nodes and resources.
diff --git a/scripts/measure-explosion-render-time.mjs b/scripts/measure-explosion-render-time.mjs
index 585dcf51..b18dc09b 100644
--- a/scripts/measure-explosion-render-time.mjs
+++ b/scripts/measure-explosion-render-time.mjs
@@ -8,14 +8,14 @@
// Options: --runs <n>, --duration <seconds>, --width, --height, --fps, --size <metres>, --seed, --backend gpu|cpu, --out <folder>, --max-seconds <limit that aborts a run>.
import { mkdir, writeFile } from 'node:fs/promises';
import { tmpdir, constants, setPriority } from 'node:os';
-import { join, resolve } from 'node:path';
+import { isAbsolute, join, resolve } from 'node:path';
import { pathToFileURL } from 'node:url';
import { setTimeout as delay } from 'node:timers/promises';
-export const DEFAULT_OPTIONS = { runs: 3, duration: 8, width: 1920, height: 1080, fps: 24, size: 4, seed: 1, backend: 'gpu', out: 'artifacts/1050/timing', maxSeconds: 180 };
+export const DEFAULT_OPTIONS = { runs: 3, duration: 8, width: 1920, height: 1080, fps: 24, size: 4, seed: 1, backend: 'gpu', out: 'artifacts/1050/timing', maxSeconds: 180, bakeCache: 'default' };
const NUMBER_OPTIONS = ['runs', 'duration', 'width', 'height', 'fps', 'size', 'seed', 'maxSeconds'];
-const OPTION_NAMES = { 'max-seconds': 'maxSeconds' };
-const USAGE = 'use [--runs 3] [--duration 8] [--width 1920] [--height 1080] [--fps 24] [--size 4] [--seed 1] [--backend gpu|cpu] [--out <folder>] [--max-seconds 180].';
+const OPTION_NAMES = { 'max-seconds': 'maxSeconds', 'bake-cache': 'bakeCache' };
+const USAGE = 'use [--runs 3] [--duration 8] [--width 1920] [--height 1080] [--fps 24] [--size 4] [--seed 1] [--backend gpu|cpu] [--out <folder>] [--max-seconds 180] [--bake-cache off|<absolute folder>].';
export const SCENE = {
format: 'crucible.scene', schemaVersion: 1,
@@ -39,6 +39,7 @@ export function parseArguments(argv) {
}
}
if (!['gpu', 'cpu'].includes(options.backend)) throw new Error(`--backend takes gpu or cpu, got ${options.backend}.`);
+ if (options.bakeCache !== 'default' && options.bakeCache !== 'off' && !isAbsolute(options.bakeCache)) throw new Error(`--bake-cache takes off or an absolute folder, got ${options.bakeCache}.`);
return options;
}
@@ -69,12 +70,17 @@ export function shapeReport({ options, runIndex, buildSeconds, submitSeconds, jo
};
}
+// The server reads CRUCIBLE_BAKE_CACHE (#1876): "off" times a cold bake every run; a folder is empty on its first run and warm after it.
+export function serverEnvironment(options, baseEnvironment) {
+ return options.bakeCache === 'default' ? baseEnvironment : { ...baseEnvironment, CRUCIBLE_BAKE_CACHE: options.bakeCache };
+}
+
async function openClient(options, runIndex) {
const { Client } = await import('@modelcontextprotocol/client');
- const { StdioClientTransport } = await import('@modelcontextprotocol/client/stdio');
+ const { StdioClientTransport, getDefaultEnvironment } = await import('@modelcontextprotocol/client/stdio');
const directory = join(tmpdir(), `crucible-explosion-time-${process.pid}-${runIndex}`);
await mkdir(directory, { recursive: true });
- const transport = new StdioClientTransport({ command: process.execPath, args: [resolve('bin/crucible-mcp.mjs'), '--backend', options.backend, '--memory', '512', '--jobs', join(directory, 'jobs')], cwd: directory, stderr: 'pipe' });
+ const transport = new StdioClientTransport({ command: process.execPath, args: [resolve('bin/crucible-mcp.mjs'), '--backend', options.backend, '--memory', '512', '--jobs', join(directory, 'jobs')], cwd: directory, env: serverEnvironment(options, getDefaultEnvironment()), stderr: 'pipe' });
const client = new Client({ name: 'measure-explosion-render-time', version: '1' });
await client.connect(transport, { timeout: 240000 });
return client;
diff --git a/tests/explosion-render-time.test.js b/tests/explosion-render-time.test.js
index 6b814cea..c38fc01c 100644
--- a/tests/explosion-render-time.test.js
+++ b/tests/explosion-render-time.test.js
@@ -1,6 +1,7 @@
import test from 'node:test';
import assert from 'node:assert/strict';
-import { DEFAULT_OPTIONS, parseArguments, shapeReport } from '../scripts/measure-explosion-render-time.mjs';
+import { resolve } from 'node:path';
+import { DEFAULT_OPTIONS, parseArguments, serverEnvironment, shapeReport } from '../scripts/measure-explosion-render-time.mjs';
// The argument and report shaping of scripts/measure-explosion-render-time.mjs (#1050); the render itself needs a GPU and runs by hand.
@@ -45,3 +46,12 @@ test('a job report without phases leaves them out instead of inventing them', ()
assert.deepEqual(shaped.phases, {});
assert.equal(shaped.jobReportSeconds, undefined);
});
+
+test('--bake-cache reaches the server as CRUCIBLE_BAKE_CACHE, and the default leaves the environment alone', () => {
+ const base = { PATH: 'x' };
+ assert.deepEqual(serverEnvironment(parseArguments([]), base), base);
+ assert.equal(serverEnvironment(parseArguments(['--bake-cache', 'off']), base).CRUCIBLE_BAKE_CACHE, 'off');
+ const folder = resolve('bakes');
+ assert.equal(serverEnvironment(parseArguments(['--bake-cache', folder]), base).CRUCIBLE_BAKE_CACHE, folder);
+ assert.throws(() => parseArguments(['--bake-cache', 'relative/folder']), /--bake-cache takes off or an absolute folder, got relative\/folder/);
+});