Skip to content

Autonomous development for real products. Governed agents build from specs you approve, follow the rules you set, and nothing merges until another agent proves it. Your decisions, judgement and taste are the bar that work must clear. Declare your vision and let agents build it.

test(pool): measure file inflation before dispatch [C7]

Corey Olson6d9caac5a932
diff --git a/test/gate-admission-p95-fixture.js b/test/gate-admission-p95-fixture.js
new file mode 100644
index 00000000..fefe6197
--- /dev/null
+++ b/test/gate-admission-p95-fixture.js
@@ -0,0 +1,110 @@
+/** Real Git/SQLite/CPU file workloads and a private machine pool for the #1091 process-lifetime measurement [C7]. */
+import assert from 'node:assert/strict';
+import { mkdirSync } from 'node:fs';
+import { mkdtempSync } from 'node:fs';
+import { readFileSync } from 'node:fs';
+import { rmSync } from 'node:fs';
+import { writeFileSync } from 'node:fs';
+import { tmpdir } from 'node:os';
+import { join } from 'node:path';
+import { fileURLToPath } from 'node:url';
+import { DatabaseSync } from 'node:sqlite';
+import { runFixtureChild } from './fixture-child.js';
+import { runFixtureChildAsync } from './fixture-child.js';
+import { awaitNestedRun } from '../src/test-file-pool.js';
+import { TEST_FILE_CORES_ENV } from '../src/test-file-pool.js';
+import { TEST_FILE_POOL_ENV } from '../src/test-file-pool.js';
+import { GATE_SLOT_HELD_ENV } from '../src/resources.js';
+import { GATE_SLOT_POOL_ENV } from '../src/resources.js';
+import { GATE_SLOT_TOKEN_ENV } from '../src/resources.js';
+import { BROWSER_SLOT_HELD_ENV } from '../src/resources.js';
+
+const runner = fileURLToPath(new URL('../bin/run-tests.js', import.meta.url));
+
+/** Make a real test file; its exit record includes startup and any post-spawn pool wait, never dispatcher queue time. */
+function workload(file) {
+ return `import assert from 'node:assert/strict';
+import { pbkdf2Sync } from 'node:crypto';
+import { execFileSync } from 'node:child_process';
+import { appendFileSync } from 'node:fs';
+import { join } from 'node:path';
+import { DatabaseSync } from 'node:sqlite';
+import { test } from 'node:test';
+process.once('exit', () => appendFileSync(process.env.FIXTURE_TIMES, JSON.stringify({
+ run: process.env.FIXTURE_RUN, file: ${JSON.stringify(file)}, pid: process.pid, lifetimeMs: process.uptime() * 1000
+}) + '\\n'));
+test('a real Git and SQLite workload [C7]', () => {
+ assert.equal(execFileSync('git', ['rev-parse', '--is-inside-work-tree'], { encoding: 'utf8' }).trim(), 'true');
+ const db = new DatabaseSync(join(process.env.FIXTURE_DATA, process.env.FIXTURE_RUN + '-' + ${JSON.stringify(file)} + '.sqlite'));
+ try {
+ db.exec('CREATE TABLE value(n INTEGER); BEGIN');
+ const put = db.prepare('INSERT INTO value VALUES (?)');
+ for (let n = 0; n < 100; n++) put.run(n);
+ db.exec('COMMIT');
+ assert.equal(db.prepare('SELECT sum(n) AS total FROM value').get().total, 4950);
+ } finally { db.close(); }
+ assert.equal(pbkdf2Sync('private-pool-workload', 'fixed-fixture-input', 200000, 32, 'sha256').length, 32);
+});
+`;
+}
+
+/** Read the complete append-only lifetime observations after their owning file processes have exited. */
+function observations(path) {
+ return readFileSync(path, 'utf8').trim().split('\n').filter(Boolean).map(line => JSON.parse(line));
+}
+
+/** Measure eight files alone and four concurrent runs of those files; fixture settings never change the user's machine. */
+export async function measureFileInflation(t, mode) {
+ const root = mkdtempSync(join(tmpdir(), 'pullboard-dispatch-p95-'));
+ t.after(() => rmSync(root, { recursive: true, force: true }));
+ const git = runFixtureChild('git', ['init', '-q'], { cwd: root });
+ assert.equal(git.status, 0, git.failure);
+ writeFileSync(join(root, 'package.json'), JSON.stringify({ type: 'module' }));
+ writeFileSync(join(root, 'pullboard.json'), JSON.stringify({ testConcurrency: { files: 8, browser: 1 } }));
+ const machine = join(root, '.machine');
+ mkdirSync(machine);
+ writeFileSync(join(machine, 'settings.json'), JSON.stringify({ gateSlots: 4, browserSlots: 1 }));
+ const times = join(root, 'lifetimes.jsonl');
+ writeFileSync(times, '');
+ const env = { ...process.env, PULLBOARD_MACHINE_HOME: machine, [TEST_FILE_CORES_ENV]: '2',
+ PULLBOARD_LANDING_RUN: mode === 'landing' ? '1' : '0', FIXTURE_TIMES: times, FIXTURE_DATA: root };
+ // These are independently admitted private fixture runs, with their own pool and no action reuse.
+ for (const key of [TEST_FILE_POOL_ENV, GATE_SLOT_HELD_ENV, GATE_SLOT_POOL_ENV, GATE_SLOT_TOKEN_ENV,
+ BROWSER_SLOT_HELD_ENV, 'PULLBOARD_TEST_ACTIONS']) delete env[key];
+ const files = Array.from({ length: 8 }, (_, n) => 'work-' + n + '.test.js');
+ for (const file of files) writeFileSync(join(root, file), workload(file));
+ const standalone = [];
+ for (const file of files) {
+ const result = await awaitNestedRun(runFixtureChildAsync(process.execPath, [runner, file], {
+ cwd: root, env: { ...env, FIXTURE_RUN: 'alone' },
+ }));
+ assert.equal(result.status, 0, result.failure ?? result.stdout);
+ standalone.push({ file, status: result.status, elapsedMs: result.elapsedMs, stdout: result.stdout, stderr: result.stderr });
+ }
+ const alone = new Map(observations(times).map(row => [row.file, row.lifetimeMs]));
+ assert.equal(alone.size, 8, 'all eight standalone file processes exited and recorded their real lifetimes');
+ const runs = Array.from({ length: 4 }, (_, n) => runFixtureChildAsync(process.execPath, [runner, ...files], {
+ cwd: root, env: { ...env, FIXTURE_RUN: 'concurrent-' + n },
+ }));
+ const parents = new Set(runs.map(run => run.child.pid));
+ let peakFileProcesses = 0;
+ const db = new DatabaseSync(join(machine, 'test-file-pool.sqlite'), { readOnly: true });
+ /** Observe already spawned files, including those blocked in preload; dispatcher PIDs are not file processes. */
+ const sample = () => {
+ const rows = db.prepare('SELECT pid FROM file_holder UNION SELECT pid FROM file_waiter').all();
+ peakFileProcesses = Math.max(peakFileProcesses, rows.filter(row => !parents.has(row.pid)).length);
+ };
+ const monitor = setInterval(sample, 20); // budget: one private read every 20 ms observes overspawn; this is not a speed threshold.
+ let results;
+ try { results = await Promise.all(runs.map(run => awaitNestedRun(run))); sample(); }
+ finally { clearInterval(monitor); db.close(); }
+ for (const result of results) assert.equal(result.status, 0, result.failure ?? result.stdout);
+ const concurrent = observations(times).filter(row => row.run.startsWith('concurrent-'));
+ assert.equal(concurrent.length, 32, 'four runs of all eight real files completed without action reuse');
+ const samples = concurrent.map(row => ({ ...row, standaloneMs: alone.get(row.file), ratio: row.lifetimeMs / alone.get(row.file) }));
+ const ordered = samples.map(row => row.ratio).sort((a, b) => a - b);
+ return { mode, cores: 2, peakFileProcesses, standalone, standaloneFileLifetimes: Object.fromEntries(alone), samples,
+ percentile: 'nearest rank: ceil(0.95 * 32)-1', p95: ordered[Math.ceil(0.95 * ordered.length) - 1],
+ runs: results.map(result => ({ status: result.status, signal: result.signal, elapsedMs: result.elapsedMs,
+ stdout: result.stdout, stderr: result.stderr })) };
+}
diff --git a/test/gate-admission.test.js b/test/gate-admission.test.js
index c7fb4d01..a649f2af 100644
--- a/test/gate-admission.test.js
+++ b/test/gate-admission.test.js
@@ -1,5 +1,6 @@
/** Test files on one machine never outnumber its cores, and the longest files start first [C7]. */
import { awaitNestedRun } from '../src/test-file-pool.js';
+import { measureFileInflation } from './gate-admission-p95-fixture.js';
import assert from 'node:assert/strict';
import { chmodSync, existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
import { tmpdir } from 'node:os';
@@ -516,3 +517,14 @@ test('c', () => { execSync(${JSON.stringify(startD)}, { cwd: ${JSON.stringify(ro
assert.ok(dEnd, 'D ran to its end after C died');
assert.ok(events.find(event => event.at === 'resume').t >= dEnd, 'on 1 core, P resumed only after D, the file under its call, ended');
});
+
+
+test('four concurrent runs start only token-owned file processes and keep p95 below twice standalone [C7]', async t => {
+ for (const mode of ['native', 'landing']) await t.test(mode, async scope => {
+ const measurement = await measureFileInflation(scope, mode);
+ scope.diagnostic('P95_MEASUREMENT=' + JSON.stringify(measurement));
+ assert.ok(measurement.peakFileProcesses <= measurement.cores,
+ `a two-token machine must not spawn files that wait for a token; saw ${measurement.peakFileProcesses}`);
+ assert.ok(measurement.p95 < 2, `p95 process-lifetime ratio ${measurement.p95} must be below2x standalone`); // budget: #1091 requires p95<2x under four concurrent runs.
+ });
+});