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.

feat: share gate slots across private board homes [Q4]

Corey Olsonfd4fb0f359cc
diff --git a/bin/run-tests.js b/bin/run-tests.js
index fabe51e7..8bdb1aac 100644
--- a/bin/run-tests.js
+++ b/bin/run-tests.js
@@ -32,6 +32,7 @@ function testEnvironment(sandbox) {
env.HOME = home;
env.USERPROFILE = home;
env.PULLBOARD_HOME = home;
+ env.PULLBOARD_MACHINE_HOME = join(sandbox, 'machine');
env.TMPDIR = sandbox;
env.TMP = sandbox;
env.TEMP = sandbox;
diff --git a/docs/api.md b/docs/api.md
index 0f46d078..1819b6c9 100644
--- a/docs/api.md
+++ b/docs/api.md
@@ -8,7 +8,7 @@ Decision shouts without a recipient go to the agent's coordinator, or to `person
A successful command returns the fields listed below. `version` is always the number `1`. The catalog lists required top-level fields; nested objects and arrays are command data, and optional top-level fields may be added.
-`pullboard settings` reads machine-wide settings from `~/.pullboard/settings.json`; `pullboard settings gateSlots <n>` changes the gate queue capacity, which defaults to `2`. Capacity changes are refused while a gate is running or waiting, so existing holders and FIFO order remain intact.
+`pullboard settings` reads machine-wide settings from the OS account's `~/.pullboard/settings.json`; the gate queue database is beside it. This location does not follow `HOME` or `PULLBOARD_HOME`, so agents with private board homes still share one machine gate limit. Set `PULLBOARD_MACHINE_HOME` to an explicit directory only when a separate private machine settings and gate pool is intended; tests use this override. `pullboard settings gateSlots <n>` changes the gate queue capacity, which defaults to `2`. Capacity changes are refused while a gate is running or waiting, so existing holders and FIFO order remain intact.
<!-- api-command-shapes:start -->
| Command | Required top-level fields |
diff --git a/src/machine-home.js b/src/machine-home.js
new file mode 100644
index 00000000..ff5efdba
--- /dev/null
+++ b/src/machine-home.js
@@ -0,0 +1,9 @@
+/** Resolve the per-account directory for machine-wide Pullboard state. */
+import { userInfo } from 'node:os';
+import { join, resolve } from 'node:path';
+
+/** Use the OS account home unless a caller explicitly selects a private machine pool. */
+export function machineHome() {
+ const override = process.env.PULLBOARD_MACHINE_HOME;
+ return override ? resolve(override) : join(userInfo().homedir, '.pullboard');
+}
diff --git a/src/resources.js b/src/resources.js
index 6a56da81..0059f533 100644
--- a/src/resources.js
+++ b/src/resources.js
@@ -1,11 +1,11 @@
/** Local machine and repository resource queues with SQLite-backed leases [Q1,Q2,Q3]. */
import { mkdirSync } from 'node:fs';
import { execFileSync } from 'node:child_process';
-import { homedir } from 'node:os';
import { dirname, join } from 'node:path';
import { randomUUID } from 'node:crypto';
import { DatabaseSync } from 'node:sqlite';
import { repoInfo } from './git.js';
+import { machineHome } from './machine-home.js';
import { Refused } from './refused.js';
const LEASE_MS = 20_000;
@@ -17,7 +17,7 @@ const processIdentities = new Map();
/** Resolve the local database for the requested scope. */
function databaseFile(scope, root) {
if (scope === 'board') throw new Refused('BOARD_SCOPE_UNAVAILABLE', 'board-scoped resources need the relay; run pullboard relay on');
- if (scope === 'machine') return join(process.env.PULLBOARD_HOME || join(homedir(), '.pullboard'), 'resources.sqlite');
+ if (scope === 'machine') return join(machineHome(), 'resources.sqlite');
if (scope === 'repo') return join(repoInfo(root).commonDir, 'pullboard', 'resources.sqlite');
throw new Refused('BAD_RESOURCE_SCOPE', `unknown resource scope "${scope}"; use machine or repo`);
}
diff --git a/src/settings.js b/src/settings.js
index bb693ea1..0c5f6c51 100644
--- a/src/settings.js
+++ b/src/settings.js
@@ -1,8 +1,8 @@
/** Machine-wide settings shared by every Pullboard checkout on this machine. */
import { existsSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from 'node:fs';
-import { homedir } from 'node:os';
import { dirname, join } from 'node:path';
import { randomUUID } from 'node:crypto';
+import { machineHome } from './machine-home.js';
import { setResourceCapacity } from './resources.js';
import { Refused } from './refused.js';
@@ -10,7 +10,7 @@ const DEFAULT_GATE_SLOTS = 2;
/** Resolve the separate machine settings file. */
export function machineSettingsFile() {
- return join(process.env.PULLBOARD_HOME || join(homedir(), '.pullboard'), 'settings.json');
+ return join(machineHome(), 'settings.json');
}
/** Read and validate machine settings, preserving any unrelated settings. */
diff --git a/test/api.test.js b/test/api.test.js
index 1457f6b2..de63cbd8 100644
--- a/test/api.test.js
+++ b/test/api.test.js
@@ -61,6 +61,7 @@ function sandbox() {
GIT_COMMITTER_NAME: 'API Test',
GIT_COMMITTER_EMAIL: '[email protected]',
PULLBOARD_HOME: join(dir, 'home'),
+ PULLBOARD_MACHINE_HOME: join(dir, 'home'),
};
const git = (cwd, ...args) => execFileSync('git', args, { cwd, env, encoding: 'utf8', stdio: 'pipe' }).trim();
const run = (cwd, ...args) => spawnSync(process.execPath, [BIN, ...args], { cwd, env, encoding: 'utf8' });
diff --git a/test/e2e.test.js b/test/e2e.test.js
index a6593677..f4410712 100644
--- a/test/e2e.test.js
+++ b/test/e2e.test.js
@@ -51,6 +51,7 @@ function sandbox() {
GIT_COMMITTER_NAME: 'Test Agent',
GIT_COMMITTER_EMAIL: '[email protected]',
PULLBOARD_HOME: join(dir, 'pullboard-home'),
+ PULLBOARD_MACHINE_HOME: join(dir, 'pullboard-home'),
};
const git = (cwd, ...args) => execFileSync('git', args, { cwd, env, encoding: 'utf8', stdio: 'pipe' }).trim();
const tryGit = (cwd, ...args) => spawnSync('git', args, { cwd, env, encoding: 'utf8' });
diff --git a/test/gate-resource.test.js b/test/gate-resource.test.js
index 51683055..c8b075b6 100644
--- a/test/gate-resource.test.js
+++ b/test/gate-resource.test.js
@@ -27,17 +27,19 @@ function fixture() {
GIT_COMMITTER_NAME: 'Queue Test',
GIT_COMMITTER_EMAIL: '[email protected]',
PULLBOARD_HOME: join(dir, 'home'),
+ PULLBOARD_MACHINE_HOME: join(dir, 'home'),
};
return { dir, events, env };
}
-/** Create a real clean repository whose gate records its start and end around a delay. */
-function gateRepo(box, name, delay = 0.25) {
+/** Create a real clean repository whose gate records its start and end around a delay or release file. */
+function gateRepo(box, name, delay = 0.25, releaseFile = '') {
const root = join(box.dir, name);
mkdirSync(root);
const git = (...args) => spawnSync('git', args, { cwd: root, env: box.env, encoding: 'utf8' });
assert.equal(git('init', '-q', '-b', 'main').status, 0);
- const command = `printf '${name} start\\n' >> ${quote(box.events)}; sleep ${delay}; printf '${name} end\\n' >> ${quote(box.events)}`;
+ const finish = releaseFile ? `while [ ! -f ${quote(releaseFile)} ]; do sleep 0.02; done` : `sleep ${delay}`;
+ const command = `printf '${name} start\\n' >> ${quote(box.events)}; ${finish}; printf '${name} end\\n' >> ${quote(box.events)}`;
writeFileSync(join(root, 'pullboard.json'), JSON.stringify({ gate: command }));
writeFileSync(join(root, 'SPEC.md'), '# Queue fixture\n');
assert.equal(git('add', '-A').status, 0);
@@ -115,6 +117,64 @@ test('[Q4,O5,O6] gate processes run one at a time in FIFO order when machine slo
assert.equal(maximum, 1);
});
+test('[Q4] gates with different PULLBOARD_HOME values share the machine pool unless explicitly separated', async () => {
+ const shared = fixture();
+ const releaseShared = join(shared.dir, 'release-shared');
+ const firstRoot = gateRepo(shared, 'shared-first', 0, releaseShared);
+ const otherBoardHome = { ...shared, env: { ...shared.env, PULLBOARD_HOME: join(shared.dir, 'other-board-home') } };
+ const secondRoot = gateRepo(otherBoardHome, 'shared-second', 0, releaseShared);
+ const setting = spawnSync(process.execPath, [BIN, 'settings', 'gateSlots', '1'], { cwd: firstRoot, env: shared.env, encoding: 'utf8' });
+ assert.equal(setting.status, 0, setting.stderr);
+ const first = launch(shared, firstRoot);
+ let second;
+ try {
+ await waitFor(() => events(shared).includes('shared-first start'), 'first shared-pool gate to start');
+ second = launch(otherBoardHome, secondRoot);
+ await waitFor(() => second.stdoutText.includes('place 1'), 'gate with another board home to queue on the same machine pool');
+ assert.deepEqual(events(shared), ['shared-first start']);
+ writeFileSync(releaseShared, 'release');
+ const results = await Promise.all([first.closed, second.closed]);
+ assert.deepEqual(results.map(({ code }) => code), [0, 0], `${first.stderrText}${second.stderrText}`);
+ assert.deepEqual(events(shared), ['shared-first start', 'shared-first end', 'shared-second start', 'shared-second end']);
+ } finally {
+ writeFileSync(releaseShared, 'release');
+ await Promise.all([first, second].filter(Boolean).map((child) => child.closed));
+ }
+
+ const separated = fixture();
+ const releaseSeparated = join(separated.dir, 'release-separated');
+ const firstPool = { ...separated, env: { ...separated.env, PULLBOARD_MACHINE_HOME: join(separated.dir, 'machine-first') } };
+ const secondPool = {
+ ...separated,
+ env: {
+ ...separated.env,
+ PULLBOARD_MACHINE_HOME: join(separated.dir, 'machine-second'),
+ },
+ };
+ const isolatedFirstRoot = gateRepo(firstPool, 'isolated-first', 0, releaseSeparated);
+ const isolatedSecondRoot = gateRepo(secondPool, 'isolated-second', 0, releaseSeparated);
+ for (const [box, root] of [[firstPool, isolatedFirstRoot], [secondPool, isolatedSecondRoot]]) {
+ const configured = spawnSync(process.execPath, [BIN, 'settings', 'gateSlots', '1'], { cwd: root, env: box.env, encoding: 'utf8' });
+ assert.equal(configured.status, 0, configured.stderr);
+ }
+ const isolatedFirst = launch(firstPool, isolatedFirstRoot);
+ let isolatedSecond;
+ try {
+ await waitFor(() => events(separated).includes('isolated-first start'), 'first isolated-pool gate to start');
+ isolatedSecond = launch(secondPool, isolatedSecondRoot);
+ await waitFor(() => events(separated).includes('isolated-second start'), 'explicit private pool to acquire while the first pool is occupied');
+ assert.deepEqual(events(separated), ['isolated-first start', 'isolated-second start']);
+ writeFileSync(releaseSeparated, 'release');
+ const results = await Promise.all([isolatedFirst.closed, isolatedSecond.closed]);
+ assert.deepEqual(results.map(({ code }) => code), [0, 0], `${isolatedFirst.stderrText}${isolatedSecond.stderrText}`);
+ assert.deepEqual(events(separated).slice(0, 2), ['isolated-first start', 'isolated-second start']);
+ assert.deepEqual(events(separated).slice(2).sort(), ['isolated-first end', 'isolated-second end']);
+ } finally {
+ writeFileSync(releaseSeparated, 'release');
+ await Promise.all([isolatedFirst, isolatedSecond].filter(Boolean).map((child) => child.closed));
+ }
+});
+
test('[Q4] an exact-tree cached gate starts while another machine gate holds the only slot', async () => {
const box = fixture();
const cachedRoot = gateRepo(box, 'cached', 0.1);
@@ -128,7 +188,7 @@ test('[Q4] an exact-tree cached gate starts while another machine gate holds the
const refusedChange = spawnSync(process.execPath, [BIN, 'settings', 'gateSlots', '2', '--json'], { cwd: cachedRoot, env: box.env, encoding: 'utf8' });
assert.equal(refusedChange.status, 1);
assert.equal(JSON.parse(refusedChange.stdout).error.code, 'RESOURCE_BUSY');
- assert.equal(JSON.parse(readFileSync(join(box.env.PULLBOARD_HOME, 'settings.json'), 'utf8')).gateSlots, 1);
+ assert.equal(JSON.parse(readFileSync(join(box.env.PULLBOARD_MACHINE_HOME, 'settings.json'), 'utf8')).gateSlots, 1);
const started = Date.now();
const cached = spawnSync(process.execPath, [BIN, 'gate'], { cwd: cachedRoot, env: box.env, encoding: 'utf8', timeout: 1_000 });
assert.equal(cached.status, 0, cached.stderr);
diff --git a/test/gate.test.js b/test/gate.test.js
index 0b6d76c8..0ee0e28f 100644
--- a/test/gate.test.js
+++ b/test/gate.test.js
@@ -36,6 +36,7 @@ function repoWithGate(gate) {
GIT_COMMITTER_NAME: 'Test Agent',
GIT_COMMITTER_EMAIL: '[email protected]',
PULLBOARD_HOME: join(dir, 'home'),
+ PULLBOARD_MACHINE_HOME: join(dir, 'home'),
};
const git = (...args) => execFileSync('git', args, { cwd: repo, env, encoding: 'utf8', stdio: 'pipe' }).trim();
const run = (...args) => spawnSync(process.execPath, [BIN, ...args], { cwd: repo, env, encoding: 'utf8', timeout: 60_000 });
diff --git a/test/machine.test.js b/test/machine.test.js
index 494ec5ff..3003902c 100644
--- a/test/machine.test.js
+++ b/test/machine.test.js
@@ -1002,6 +1002,7 @@ test('next --verify reserves the review for the reviewLease and says until when;
GIT_COMMITTER_NAME: 'Test Agent',
GIT_COMMITTER_EMAIL: '[email protected]',
PULLBOARD_HOME: join(dir, 'home'),
+ PULLBOARD_MACHINE_HOME: join(dir, 'home'),
};
const git = (cwd, ...args) => execFileSync('git', args, { cwd, env, encoding: 'utf8', stdio: 'pipe' }).trim();
// A command that never returns fails the test after a minute instead of holding the gate open.
diff --git a/test/release.test.js b/test/release.test.js
index 0f6dfc0f..96baadb4 100644
--- a/test/release.test.js
+++ b/test/release.test.js
@@ -44,6 +44,7 @@ test('a packed release installs with no network and runs the whole loop from a f
GIT_COMMITTER_NAME: 'Test Agent',
GIT_COMMITTER_EMAIL: '[email protected]',
PULLBOARD_HOME: join(dir, 'home'),
+ PULLBOARD_MACHINE_HOME: join(dir, 'home'),
};
const git = (cwd, ...args) => execFileSync('git', args, { cwd, env, encoding: 'utf8', stdio: 'pipe' }).trim();
/** Run the installed pullboard and require it to succeed. */
diff --git a/test/resources.test.js b/test/resources.test.js
index 61cb5f90..8ace3655 100644
--- a/test/resources.test.js
+++ b/test/resources.test.js
@@ -53,7 +53,7 @@ function fixture() {
const result = spawnSync('git', ['init', '-q', repo], { encoding: 'utf8' });
assert.equal(result.status, 0, result.stderr);
}
- return { dir, home, first, second, env: { ...process.env, PULLBOARD_HOME: home } };
+ return { dir, home, first, second, env: { ...process.env, PULLBOARD_HOME: home, PULLBOARD_MACHINE_HOME: home } };
}
/** Create the previous private queue schema so simultaneous openers exercise its migration. */
@@ -92,11 +92,15 @@ function expireHeartbeat(box, table, agent) {
/** Read a private machine database without changing the process environment for other fixtures. */
function privateList(box, scope = 'machine', root = process.cwd()) {
const previous = process.env.PULLBOARD_HOME;
+ const previousMachineHome = process.env.PULLBOARD_MACHINE_HOME;
process.env.PULLBOARD_HOME = box.home;
+ process.env.PULLBOARD_MACHINE_HOME = box.home;
try { return listResources({ scope, root }); }
finally {
if (previous === undefined) delete process.env.PULLBOARD_HOME;
else process.env.PULLBOARD_HOME = previous;
+ if (previousMachineHome === undefined) delete process.env.PULLBOARD_MACHINE_HOME;
+ else process.env.PULLBOARD_MACHINE_HOME = previousMachineHome;
}
}
@@ -443,7 +447,9 @@ test('[Q2,Q3] a SIGKILLed waiter is skipped while the next live waiter advances'
test('[Q4] machine capacity changes atomically refuse an occupied or queued resource', async () => {
const box = fixture();
const oldHome = process.env.PULLBOARD_HOME;
+ const oldMachineHome = process.env.PULLBOARD_MACHINE_HOME;
process.env.PULLBOARD_HOME = box.home;
+ process.env.PULLBOARD_MACHINE_HOME = box.home;
const holder = worker(box, { agent: 'capacity-holder' });
try {
assert.equal((await event(holder)).acquired, 'capacity-holder');
@@ -467,6 +473,8 @@ test('[Q4] machine capacity changes atomically refuse an occupied or queued reso
if (!holder.exitResult) await release(holder);
if (oldHome === undefined) delete process.env.PULLBOARD_HOME;
else process.env.PULLBOARD_HOME = oldHome;
+ if (oldMachineHome === undefined) delete process.env.PULLBOARD_MACHINE_HOME;
+ else process.env.PULLBOARD_MACHINE_HOME = oldMachineHome;
}
});
diff --git a/test/settings.test.js b/test/settings.test.js
index 2b1879f8..f769de37 100644
--- a/test/settings.test.js
+++ b/test/settings.test.js
@@ -1,17 +1,18 @@
/** Machine-wide gate capacity settings through the actual CLI [O5,O6]. */
import assert from 'node:assert/strict';
import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
-import { tmpdir } from 'node:os';
+import { tmpdir, userInfo } from 'node:os';
import { join, resolve } from 'node:path';
import { spawnSync } from 'node:child_process';
import { test } from 'node:test';
const BIN = resolve(import.meta.dirname, '../bin/pullboard.js');
+const MACHINE_HOME_MODULE = resolve(import.meta.dirname, '../src/machine-home.js');
/** Run settings in an isolated machine home, returning its structured CLI result. */
function settings(home, ...args) {
return spawnSync(process.execPath, [BIN, 'settings', ...args, '--json'], {
- encoding: 'utf8', env: { ...process.env, PULLBOARD_HOME: home },
+ encoding: 'utf8', env: { ...process.env, PULLBOARD_HOME: home, PULLBOARD_MACHINE_HOME: home },
});
}
@@ -42,3 +43,19 @@ test('[O5,O6] gateSlots defaults to two, reads and sets atomically, and refuses
assert.equal(JSON.parse(refused.stdout).error.code, 'BAD_GATE_SLOTS');
} finally { rmSync(home, { recursive: true, force: true }); }
});
+
+test('[Q4] the machine pool ignores board and HOME overrides unless explicitly selected', () => {
+ const script = `import { machineHome } from ${JSON.stringify(MACHINE_HOME_MODULE)}; process.stdout.write(machineHome());`;
+ const env = { ...process.env, HOME: '/private/home', PULLBOARD_HOME: '/private/board' };
+ delete env.PULLBOARD_MACHINE_HOME;
+ const defaultHome = spawnSync(process.execPath, ['--input-type=module', '-e', script], { encoding: 'utf8', env });
+ assert.equal(defaultHome.status, 0, defaultHome.stderr);
+ assert.equal(defaultHome.stdout, join(userInfo().homedir, '.pullboard'));
+
+ const override = join(tmpdir(), 'pullboard-private-machine-home');
+ const privateHome = spawnSync(process.execPath, ['--input-type=module', '-e', script], {
+ encoding: 'utf8', env: { ...env, PULLBOARD_MACHINE_HOME: override },
+ });
+ assert.equal(privateHome.status, 0, privateHome.stderr);
+ assert.equal(privateHome.stdout, resolve(override));
+});
diff --git a/test/spec.test.js b/test/spec.test.js
index ced7511a..e0cc9a4f 100644
--- a/test/spec.test.js
+++ b/test/spec.test.js
@@ -126,6 +126,7 @@ test('a grammar-1 repair can commit after grammar 2 was already recorded [A5,S8]
GIT_COMMITTER_NAME: 'Test Agent',
GIT_COMMITTER_EMAIL: '[email protected]',
PULLBOARD_HOME: join(root, '.home'),
+ PULLBOARD_MACHINE_HOME: join(root, '.home'),
};
const git = (...args) => execFileSync('git', args, { cwd: root, env, encoding: 'utf8', stdio: 'pipe' });
const command = (...args) => spawnSync(process.execPath, [resolve(import.meta.dirname, '../bin/pullboard.js'), ...args], { cwd: root, env, encoding: 'utf8' });
@@ -282,6 +283,7 @@ function specBox(t, { specName = 'SPEC.md', practiceName = 'PRACTICE.md', practi
GIT_AUTHOR_NAME: 'Test Agent', GIT_AUTHOR_EMAIL: '[email protected]',
GIT_COMMITTER_NAME: 'Test Agent', GIT_COMMITTER_EMAIL: '[email protected]',
PULLBOARD_HOME: join(root, '.home'),
+ PULLBOARD_MACHINE_HOME: join(root, '.home'),
};
const git = (...args) => execFileSync('git', args, { cwd: root, env, stdio: 'pipe', encoding: 'utf8' });
const command = (...args) => spawnSync(process.execPath, [resolve(import.meta.dirname, '../bin/pullboard.js'), ...args], { cwd: root, env, encoding: 'utf8' });
diff --git a/test/test-runner.test.js b/test/test-runner.test.js
index 465e65f4..1c60949b 100644
--- a/test/test-runner.test.js
+++ b/test/test-runner.test.js
@@ -18,6 +18,7 @@ test('tests run without inherited Git identity or config and refuse ambient pull
assert.equal(process.env.GIT_COMMITTER_NAME, undefined);
assert.equal(process.env.GIT_COMMITTER_EMAIL, undefined);
assert.equal(process.env.HOME, process.env.PULLBOARD_HOME);
+ assert.ok(process.env.PULLBOARD_MACHINE_HOME.startsWith(join(process.env.TMPDIR, 'machine')));
assert.ok(process.env.PULLBOARD_TEST_FILE.endsWith('test/test-runner.test.js'));
const root = mkdtempSync(join(tmpdir(), 'pullboard-runner-git-'));