Build and revise procedural 3D assets with your coding agent. Local MCP server, CLI and TypeScript engine with rendered review, editable source and GLB export.
JavaScript 3d3d-assets3d-modelingagent-skillsagent-toolsai-agentsasset-pipelinecligame-assetsglbgltfmcpmcp-servermodel-context-protocolprocedural-generationprocedural-modelingtext-to-3dthreejstypescript
Let KILN_EVALUATOR_TIMEOUT_MS raise the build limit above 60 seconds (#335)
Matthew Kissinger43d7564cf4f3
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 28a506c0..91f5a26e 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -7,6 +7,15 @@ does not publish a package.## Unreleased+- `KILN_EVALUATOR_TIMEOUT_MS` now works above 60,000, as documented. Only the host read it: the worker+ kept its own 60-second timer, so a build that yielded to the event loop after that failed with+ `DEADLINE_EXCEEDED` at any limit, usually once the abandoned build had run to its end. The worker now+ takes the protocol maximum and leaves the deadline to the host, which kills it at the limit in force.+ The worker's own timer moves from 60 to 120 seconds, so a worker left behind by a host that died stops a+ build that yields at 120 seconds rather than 60.+ The default stays 60 seconds, a host calling `evaluateEvaluatorRequestV2` directly keeps its own+ 60-second default, and the `isolated` transport keeps its fixed 65-second CPU-time limit, which the+ setting does not raise.- The maintainer toolchain moves to Node 22.23.4, a security release, retaining Bun 1.4.2, npm 12.2.0 andconsumer Node compatibility. The site takes `astro` 7.4.7 and `@astrojs/react` 7.1.4, which require it,and declares `@emnapi/runtime` 1.11.3: `@astrojs/astro2tsx` needs that runtime without declaring it, anddiff --git a/docs/install.md b/docs/install.mdindex 38986172..e82cdf90 100644--- a/docs/install.md+++ b/docs/install.md@@ -623,7 +623,8 @@ see [large assets](runtime.md#large-assets). Host callers can cancel through an`KILN_EVALUATOR_MODE=in-process` retains the trusted legacy path, with no hardsynchronous interruption. A separate process is not an operating-system securitysandbox. The isolated mode remains host-specific and requires its verified Linux-isolation setup.+isolation setup; its fixed 65-second CPU-time limit stays in force whatever+`KILN_EVALUATOR_TIMEOUT_MS` says.Optimize and instancing options are sent explicitly to the worker. The legacy`KILN_QA_MODE=observe|off` override is rejected in subprocess mode rather than silentlydiff --git a/docs/runtime.md b/docs/runtime.mdindex 51cbfd92..3cda9cd9 100644--- a/docs/runtime.md+++ b/docs/runtime.md@@ -124,7 +124,7 @@ Use `kiln_discover({ capabilities: true })` or `node kiln.mjs discover --capabil| Environment variable | Supported values || --- | --- || `KILN_EVALUATOR_MODE` | `subprocess` (local default), `in-process`, or the separately configured `isolated` transport |-| `KILN_EVALUATOR_TIMEOUT_MS` | 1–120,000; default 60,000 |+| `KILN_EVALUATOR_TIMEOUT_MS` | 1–120,000; default 60,000. In `subprocess` and `isolated` modes the host ends the worker at this limit, counted from the worker's launch, so it covers the whole build and export; `in-process` has no deadline. The `isolated` transport also has a fixed 65-second CPU-time limit, which this does not raise; a build stopped by that limit reports `WORKER_FAILED` || `KILN_EVALUATOR_HEAP_MB` | Node subprocess only, 64–4,096; default 512 || `KILN_EVALUATOR_MAX_GLB_BYTES` | Subprocess and isolated evaluators, 1–67,108,864; default 16,777,216. See [large assets](#large-assets) || `KILN_BUILD_CACHE` | `disk` (packaged default), `memory`, or `off` |diff --git a/src/__tests__/local-runtime.test.ts b/src/__tests__/local-runtime.test.tsindex c77e9c3c..678f5f58 100644--- a/src/__tests__/local-runtime.test.ts+++ b/src/__tests__/local-runtime.test.ts@@ -23,6 +23,16 @@ it('rejects unsupported policy and limit overrides instead of silently ignoring);});+it('takes the documented deadline range and keeps the 60-second default', () => {+ expect(createLocalToolContext({}, {}).localExecution.deadlineMs).toBe(60_000);+ expect(+ createLocalToolContext({}, { KILN_EVALUATOR_TIMEOUT_MS: '120000' }).localExecution.deadlineMs,+ ).toBe(120_000);+ expect(() => createLocalToolContext({}, { KILN_EVALUATOR_TIMEOUT_MS: '120001' })).toThrow(+ 'KILN_EVALUATOR_TIMEOUT_MS',+ );+});+it('keeps cancellation out of source and cached results', async () => {const controller = new AbortController();controller.abort();diff --git a/src/evaluator/handler.test.ts b/src/evaluator/handler.test.tsindex 0f88682b..ff670315 100644--- a/src/evaluator/handler.test.ts+++ b/src/evaluator/handler.test.ts@@ -1,6 +1,6 @@import { resolveRequirementsContext } from '../requirements-context';import { createRequirementsQaReport } from '../qa/requirements-report';-import { describe, expect, test } from 'bun:test';+import { describe, expect, spyOn, test } from 'bun:test';import type { RenderResult } from '../render';import {@@ -116,4 +116,27 @@ describe('transport-neutral evaluator handler', () => {error: { code: 'DEADLINE_EXCEEDED' },});});++ // The fd3 worker leaves its deadline to the host that kills it. A host calling this entry has+ // only this timer, so naming no deadline has to keep meaning the default.+ test('a host entry naming no deadline keeps the 60-second default', async () => {+ const built = createEvaluatorRequestV2({ requestId: 'http-default', code: 'fixture' });+ const timers = spyOn(globalThis, 'setTimeout');+ try {+ await evaluateEvaluatorRequestV2(built.json, { render: async () => RENDER });+ expect(timers.mock.calls.map(([, ms]) => ms)).toEqual([60_000]);+ } finally {+ timers.mockRestore();+ }+ });++ test('accepts a deadline up to the protocol maximum and refuses one above it', async () => {+ const built = createEvaluatorRequestV2({ requestId: 'http-maximum', code: 'fixture' });+ const render = { render: async () => RENDER };+ const accepted = await evaluateEvaluatorRequestV2(built.json, render, { deadlineMs: 120_000 });+ expect(decodeEvaluatorResultV2(accepted, 1024, 'http-maximum').ok).toBe(true);+ await expect(+ evaluateEvaluatorRequestV2(built.json, render, { deadlineMs: 120_001 }),+ ).rejects.toMatchObject({ code: 'INPUT_INVALID' });+ });});diff --git a/src/evaluator/handler.ts b/src/evaluator/handler.tsindex f21f3950..52c6cc2b 100644--- a/src/evaluator/handler.ts+++ b/src/evaluator/handler.ts@@ -15,6 +15,7 @@ import {evaluatorOutcomeMessage,EVALUATOR_RESULT_VERSION,EvaluatorPortError,+ MAX_EVALUATOR_DEADLINE_MS,MAX_EVALUATOR_RESPONSE_BYTES,type EvaluatorOutcomeCode,type EvaluatorOutputLimitDetails,@@ -64,7 +65,7 @@ function boundedMaxResponseBytes(value: number | undefined): number {function boundedDeadlineMs(value: number | undefined): number {const resolved = value ?? DEFAULT_EVALUATOR_DEADLINE_MS;- if (!Number.isInteger(resolved) || resolved < 1 || resolved > 120_000) {+ if (!Number.isInteger(resolved) || resolved < 1 || resolved > MAX_EVALUATOR_DEADLINE_MS) {throw new EvaluatorPortError('INPUT_INVALID');}return resolved;diff --git a/src/evaluator/protocol.ts b/src/evaluator/protocol.tsindex 8b2ba728..8e89d2aa 100644--- a/src/evaluator/protocol.ts+++ b/src/evaluator/protocol.ts@@ -34,6 +34,7 @@ export const MAX_EVALUATOR_CODE_BYTES = 512 * 1024;/** Includes bounded, host-approved PNG payloads; non-resource request data stays at 1 MiB. */export const MAX_EVALUATOR_REQUEST_BYTES = 24 * 1024 * 1024;export const DEFAULT_EVALUATOR_DEADLINE_MS = 60_000;+export const MAX_EVALUATOR_DEADLINE_MS = 120_000;export const DEFAULT_EVALUATOR_MAX_GLB_BYTES = 16 * 1024 * 1024;export const DEFAULT_EVALUATOR_MAX_RESPONSE_BYTES = 32 * 1024 * 1024;export const MAX_EVALUATOR_GLB_BYTES = 64 * 1024 * 1024;@@ -672,7 +673,7 @@ export function createEvaluatorPortV2(const deadlineMs = boundedControl(controls.deadlineMs ?? defaults.deadlineMs,DEFAULT_EVALUATOR_DEADLINE_MS,- 120_000,+ MAX_EVALUATOR_DEADLINE_MS,);const maxGlbBytes = boundedControl(controls.maxGlbBytes ?? defaults.maxGlbBytes,diff --git a/src/evaluator/subprocess-deadline.test.ts b/src/evaluator/subprocess-deadline.test.tsnew file mode 100644index 00000000..31f4ca74--- /dev/null+++ b/src/evaluator/subprocess-deadline.test.ts@@ -0,0 +1,116 @@+import { afterAll, beforeAll, describe, expect, spyOn, test } from 'bun:test';+import { mkdir, mkdtemp, rm, writeFile } from 'node:fs/promises';+import { join, resolve } from 'node:path';+import { pathToFileURL } from 'node:url';+import { createLocalToolContext } from '../local-runtime';+import {+ type EvaluatorProcessLaunch,+ renderGLBViaProcessLaunch,+ sanitizedEvaluatorEnv,+} from './subprocess';++const repo = resolve(import.meta.dir, '../..');+const BOX = `const meta = { name: 'DeadlineBox' };+function build() {+ const root = createRoot('DeadlineBox');+ createPart('Body', boxGeo(1, 1, 1), gameMaterial('#808080'), { parent: root });+ return root;+}`;+const NEVER = 'async function build(){ await new Promise(() => {}); }';++/**+ * The fault needs a build still running over a minute in, and a minute per run is too dear for+ * this suite, so the real worker starts with that time already gone: its preload takes this much+ * off every timer it arms. A box's export yields to the event loop within milliseconds, so the+ * worker's own deadline gets its turn exactly as it does when a long build first yields.+ */+const WORKER_CLOCK_AHEAD_MS = 90_000;+/** How soon the host's limit fires once a test has found the timer that carries it. */+const LIMIT_FIRES_AFTER_MS = 1_000;++let root: string;+let preload: string;++beforeAll(async () => {+ await mkdir(join(repo, 'tmp'), { recursive: true });+ root = await mkdtemp(join(repo, 'tmp/worker-clock-'));+ preload = join(root, 'clock-ahead.mjs');+ await writeFile(+ preload,+ `const setTimeoutOnRealClock = globalThis.setTimeout;+globalThis.setTimeout = (callback, ms = 0, ...args) =>+ setTimeoutOnRealClock(callback, Math.max(0, ms - ${WORKER_CLOCK_AHEAD_MS}), ...args);`,+ );+});++afterAll(async () => {+ await rm(root, { recursive: true, force: true });+});++const sourceWorker = (): EvaluatorProcessLaunch => ({+ command: process.execPath,+ args: ['--preload', preload, join(import.meta.dir, 'worker.ts')],+ env: sanitizedEvaluatorEnv(),+});+// What the CLI and MCP server start. `bun run test` refuses a stale dist/.+const packagedWorker = (): EvaluatorProcessLaunch => ({+ command: 'node',+ args: ['--import', pathToFileURL(preload).href, join(repo, 'dist/evaluator-worker.mjs')],+ env: sanitizedEvaluatorEnv(),+});++/**+ * Runs `work` with the host's timer for `limitMs` shortened and every other timer left alone. A+ * host that armed any other delay is left waiting on the worker, and runs out the test's budget.+ */+async function endsAtLimit(limitMs: number, work: () => Promise<unknown>): Promise<void> {+ const setTimeoutOnRealClock = globalThis.setTimeout;+ const clock = spyOn(globalThis, 'setTimeout').mockImplementation(((+ callback: (...args: unknown[]) => void,+ ms?: number,+ ...args: unknown[]+ ) =>+ setTimeoutOnRealClock(+ callback,+ ms === limitMs ? LIMIT_FIRES_AFTER_MS : ms,+ ...args,+ )) as unknown as typeof setTimeout);+ const started = performance.now();+ try {+ await expect(work()).rejects.toMatchObject({ code: 'DEADLINE_EXCEEDED' });+ } finally {+ clock.mockRestore();+ }+ // Sooner would mean the worker's own clock ended the build, not the limit that was set.+ expect(performance.now() - started).toBeGreaterThanOrEqual(LIMIT_FIRES_AFTER_MS - 50);+}++describe('the host owns the evaluator deadline', () => {+ // About 1 s per worker on a quiet machine; the worker's own timer leaves 30 s of real time.+ test.each([+ ['the source worker on Bun', sourceWorker],+ ['the packaged worker on Node', packagedWorker],+ ])(+ '%s finishes a build past the default deadline under a raised limit',+ async (_name, launch) => {+ const rendered = await renderGLBViaProcessLaunch(BOX, {}, { deadlineMs: 120_000 }, launch());+ expect(rendered.glb.byteLength).toBeGreaterThan(0);+ },+ 30_000,+ );++ test('a raised limit still ends the worker at that limit', async () => {+ await endsAtLimit(90_000, () =>+ renderGLBViaProcessLaunch(NEVER, {}, { deadlineMs: 90_000 }, packagedWorker()),+ );+ });++ test('a host naming no limit still ends the worker at the default', async () => {+ await endsAtLimit(60_000, () => renderGLBViaProcessLaunch(NEVER, {}, {}, packagedWorker()));+ });++ test('KILN_EVALUATOR_TIMEOUT_MS reaches the timer that ends the worker', async () => {+ const local = createLocalToolContext({}, { KILN_EVALUATOR_TIMEOUT_MS: '90000' });+ await endsAtLimit(90_000, () => local.evaluatorPort!.render(NEVER));+ });+});diff --git a/src/evaluator/subprocess.ts b/src/evaluator/subprocess.tsindex 504f45bc..4ab2850c 100644--- a/src/evaluator/subprocess.ts+++ b/src/evaluator/subprocess.ts@@ -21,6 +21,7 @@ import {type EvaluatorOutcomeCode,type EvaluatorOutputLimitDetails,type EvaluatorRequestV2,+ MAX_EVALUATOR_DEADLINE_MS,MAX_EVALUATOR_GLB_BYTES,MAX_EVALUATOR_REQUEST_BYTES,MAX_EVALUATOR_RESPONSE_BYTES,@@ -121,7 +122,11 @@ export async function renderGLBViaProcessLaunch(// decode reports an oversize request as a malformed one (#299).const oversizeSource = evaluatorSourceBudgetFailure(code);if (oversizeSource) throw new EvaluatorSubprocessError('INPUT_INVALID', oversizeSource);- const deadlineMs = boundedInteger(controls.deadlineMs, DEFAULT_DEADLINE_MS, 120_000);+ const deadlineMs = boundedInteger(+ controls.deadlineMs,+ DEFAULT_DEADLINE_MS,+ MAX_EVALUATOR_DEADLINE_MS,+ );const maxGlbBytes = boundedInteger(controls.maxGlbBytes,DEFAULT_MAX_GLB_BYTES,diff --git a/src/evaluator/worker.ts b/src/evaluator/worker.tsindex 45c47dae..44a3471c 100644--- a/src/evaluator/worker.ts+++ b/src/evaluator/worker.ts@@ -1,6 +1,10 @@import { writeFileSync } from 'node:fs';import { evaluateEvaluatorRequestV2 } from './handler';-import { MAX_EVALUATOR_REQUEST_BYTES, MAX_EVALUATOR_RESPONSE_BYTES } from './protocol';+import {+ MAX_EVALUATOR_DEADLINE_MS,+ MAX_EVALUATOR_REQUEST_BYTES,+ MAX_EVALUATOR_RESPONSE_BYTES,+} from './protocol';async function readBoundedInput(): Promise<string> {const chunks: Buffer[] = [];@@ -15,14 +19,15 @@ async function readBoundedInput(): Promise<string> {}try {- // The request carries the GLB limit but not the response budget. The host stops reading at its- // own budget, so the worker bounds this only by what the protocol can ever carry.+ // The request carries the GLB limit but neither the response budget nor the deadline. The host+ // stops reading at its own budget and kills this process at its own deadline, which a timer in+ // here could only follow, so the worker bounds both only by what the protocol can ever carry.writeFileSync(3,await evaluateEvaluatorRequestV2(await readBoundedInput(),{},- { maxResponseBytes: MAX_EVALUATOR_RESPONSE_BYTES },+ { deadlineMs: MAX_EVALUATOR_DEADLINE_MS, maxResponseBytes: MAX_EVALUATOR_RESPONSE_BYTES },),{ encoding: 'utf8' },);diff --git a/src/local-runtime.ts b/src/local-runtime.tsindex 3224a2fa..c1956f39 100644--- a/src/local-runtime.ts+++ b/src/local-runtime.ts@@ -2,6 +2,7 @@ import type { KilnToolContext } from './tools/registry';import {DEFAULT_EVALUATOR_MAX_GLB_BYTES,DEFAULT_EVALUATOR_MAX_RESPONSE_BYTES,+ MAX_EVALUATOR_DEADLINE_MS,MAX_EVALUATOR_GLB_BYTES,MAX_EVALUATOR_RESPONSE_BYTES,type EvaluatorPortV2,@@ -129,7 +130,7 @@ export function createLocalToolContext(if (!['warn', 'strict'].includes(geometryPolicy))throw new Error('KILN_GEOMETRY_POLICY must be warn or strict.');const mode = localEvaluatorMode(env);- const deadlineMs = integer(env, 'KILN_EVALUATOR_TIMEOUT_MS', 60000, 1, 120000);+ const deadlineMs = integer(env, 'KILN_EVALUATOR_TIMEOUT_MS', 60000, 1, MAX_EVALUATOR_DEADLINE_MS);const heapMb = integer(env, 'KILN_EVALUATOR_HEAP_MB', 512, 64, 4096);if (mode === 'subprocess' && process.versions.bun && env.KILN_EVALUATOR_HEAP_MB !== undefined) {throw new Error('KILN_EVALUATOR_HEAP_MB requires the packaged Node runtime.');