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.

fix(core): raise live resource capacity atomically [Q1,Q4]

Corey Olsoneae147a00e8d
diff --git a/docs/api.md b/docs/api.md
index 3640a60c..65b5ae7e 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 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.
+`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`. Raising gate or browser capacity takes effect immediately, even with holders and waiters: settings and the durable queue limit change under the same lock, and existing waiters observe the new limit. Lowering capacity is refused while that resource has holders or waiters; the refusal names its live holders and leaves their leases, settings and queue order intact. Retry the decrease after the resource becomes idle.
Browser-free check admission is opt-in per machine with `"gate": { "browserFreeChecks": true }` in `~/.pullboard/settings.json`; it defaults to `false`. When enabled, the reviewed test classifier can let checks use a CPU-only gate slot. An absent or false setting keeps every check browser-gated, and uncertain or unsupported test commands remain browser-gated even when enabled. The same setting controls the wider frozen-check classification introduced in 0.8.26.
diff --git a/src/resources.js b/src/resources.js
index af90f406..67ffbba2 100644
--- a/src/resources.js
+++ b/src/resources.js
@@ -798,7 +798,7 @@ export function inheritedGateSlot({ root = process.cwd(), browser = false } = {}
};
}
-/** Change a resource's capacity only while its queue is empty, persisting related settings under the same lock. */
+/** Raise live capacity atomically; a decrease waits for an empty queue without evicting holders. */
export function setResourceCapacity({ name, capacity, scope = 'machine', root = process.cwd(), persist = () => {} }) {
if (typeof name !== 'string' || !name.trim() || name.trim() !== name) throw new Refused('BAD_RESOURCE_NAME', 'resource name must be nonempty trimmed text');
if (name.startsWith('runner:')) throw new Refused('RESERVED_RUNNER_RESOURCE', 'runner resource rows are managed by the machine gate; use runner settings');
@@ -807,8 +807,10 @@ export function setResourceCapacity({ name, capacity, scope = 'machine', root =
try {
return update(db, () => {
const state = snapshot(db, name);
- if (state.holders.length || state.line.length) {
- throw new Refused('RESOURCE_BUSY', `resource "${name}" has ${state.holders.length} holder(s) and ${state.line.length} waiter(s); wait for it to become idle, then retry pullboard settings ${name === 'browser' ? 'browserSlots' : 'gateSlots'} ${capacity}`);
+ const current = db.prepare('SELECT capacity FROM resource WHERE name = ?').get(name)?.capacity;
+ if ((state.holders.length || state.line.length) && (current === undefined || capacity < current)) {
+ const holders = state.holders.map(holder => `${holder.agent} (${holder.repo})`).join(', ') || 'none';
+ throw new Refused('RESOURCE_BUSY', `resource "${name}" has ${state.holders.length} holder(s) and ${state.line.length} waiter(s); running: ${holders}; wait for it to become idle, then retry pullboard settings ${name === 'browser' ? 'browserSlots' : 'gateSlots'} ${capacity}`);
}
persist();
db.prepare('INSERT INTO resource(name, capacity) VALUES (?, ?) ON CONFLICT(name) DO UPDATE SET capacity = excluded.capacity').run(name, capacity);
diff --git a/src/settings.js b/src/settings.js
index b7e67c6e..57002d35 100644
--- a/src/settings.js
+++ b/src/settings.js
@@ -69,7 +69,7 @@ function writeMachineSettings(settings) {
} finally { rmSync(temporary, { force: true }); }
}
-/** Set machine gate capacity only when its durable holder and waiter lists are empty. */
+/** Raise machine gate capacity immediately; decreases require an empty durable queue. */
export function setGateSlots(capacity) {
if (!Number.isSafeInteger(capacity) || capacity < 1) throw new Refused('BAD_GATE_SLOTS', 'gateSlots must be a positive integer; run pullboard settings gateSlots <n>');
let next;
@@ -82,7 +82,7 @@ export function setGateSlots(capacity) {
return next;
}
-/** Set machine browser capacity only when its browser holders and waiters are empty. */
+/** Raise machine browser capacity immediately; decreases require an empty browser queue. */
export function setBrowserSlots(capacity) {
if (!Number.isSafeInteger(capacity) || capacity < 1) throw new Refused('BAD_BROWSER_SLOTS', 'browserSlots must be a positive integer; run pullboard settings browserSlots <n>');
let next;
diff --git a/test/resources-capacity-fixture.js b/test/resources-capacity-fixture.js
new file mode 100644
index 00000000..65b267e8
--- /dev/null
+++ b/test/resources-capacity-fixture.js
@@ -0,0 +1,114 @@
+/** Original public capacity regressions, kept outside the over-cap resource test module [Q1,Q2,Q4]. */
+import assert from 'node:assert/strict';
+import { resolve } from 'node:path';
+import { runFixtureChild } from './fixture-child.js';
+const BIN = resolve(import.meta.dirname, '../bin/pullboard.js');
+
+/** Change gate capacity through the public CLI in this fixture's private machine home. */
+function configureGateSlots(box, slots) {
+ return runFixtureChild(process.execPath, [BIN, 'settings', 'gateSlots', String(slots), '--json'], {
+ cwd: box.first, env: box.env, encoding: 'utf8',
+ });
+}
+
+/**
+ * Bind the existing resource fixture tools to the original regression callbacks.
+ * @param {any} tools - The unchanged resource-test helpers and worker source.
+ * @returns {{raising: Function, lowering: Function, browser: Function}}
+ */
+export function capacityChangeCases(tools) {
+ return { raising: raising.bind(null, tools), lowering: lowering.bind(null, tools), browser: browser.bind(null, tools) };
+}
+
+/** Exercise the original raising capacity case through the public CLI. */
+async function raising(tools) {
+ const { fixture, worker, event, acquired, release, privateList, poolWorker, POOL_MODULE_WORKER, configureBrowserSlots } = tools;
+ const box = fixture();
+ const children = [];
+ try {
+ for (const agent of ['raise-holder-one', 'raise-holder-two']) {
+ const child = worker(box, { capacity: 2, agent }); children.push(child);
+ assert.equal((await acquired(child)).acquired, agent);
+ }
+ for (const agent of ['raise-waiter-one', 'raise-waiter-two']) {
+ const child = worker(box, { capacity: 2, agent }); children.push(child);
+ assert.ok((await event(child)).waiting, 'the existing taker is queued before the setting changes');
+ }
+ const raised = configureGateSlots(box, 4);
+ assert.equal(raised.status, 0, raised.stderr);
+ assert.equal(JSON.parse(raised.stdout).settings.gateSlots, 4);
+ for (const child of children.slice(2)) await acquired(child);
+ const gate = privateList(box).find(row => row.name === 'gate');
+ assert.equal(gate.capacity, 4, 'resources reports the raised machine capacity');
+ assert.deepEqual(gate.holders.map(row => row.agent).sort(),
+ ['raise-holder-one', 'raise-holder-two', 'raise-waiter-one', 'raise-waiter-two'].sort());
+ assert.ok(children.every(child => child.exitResult === null), 'the original holders and newly admitted waiters remain running');
+ const next = worker(box, { capacity: 4, agent: 'after-raise-waiter' }); children.push(next);
+ assert.ok((await event(next)).waiting, 'the raised capacity is still a real limit');
+ await release(children[0]);
+ assert.equal((await acquired(next)).acquired, 'after-raise-waiter');
+ } finally { for (const child of children) if (!child.exitResult) await release(child); }
+}
+
+/** Exercise the original lowering capacity case through the public CLI. */
+async function lowering(tools) {
+ const { fixture, worker, event, acquired, release, privateList, poolWorker, POOL_MODULE_WORKER, configureBrowserSlots } = tools;
+ const box = fixture();
+ assert.equal(configureGateSlots(box, 4).status, 0);
+ const children = [];
+ try {
+ for (const agent of ['lower-one', 'lower-two', 'lower-three', 'lower-four']) {
+ const child = worker(box, { capacity: 4, agent }); children.push(child);
+ await acquired(child);
+ }
+ const before = privateList(box).find(row => row.name === 'gate');
+ const lowered = configureGateSlots(box, 1);
+ assert.equal(lowered.status, 1, 'a decrease below live holders is refused rather than evicting them');
+ const error = JSON.parse(lowered.stdout).error;
+ assert.equal(error.code, 'RESOURCE_BUSY');
+ for (const child of children) assert.ok(error.message.includes(child.spawnargs.at(-3)),
+ 'the refusal identifies each live holder');
+ const after = privateList(box).find(row => row.name === 'gate');
+ assert.deepEqual(after, before, 'a refused decrease leaves the resource and leases unchanged');
+ assert.ok(children.every(child => child.exitResult === null), 'no running holder was stopped');
+ const settings = runFixtureChild(process.execPath, [BIN, 'settings', '--json'], {
+ cwd: box.first, env: box.env, encoding: 'utf8',
+ });
+ assert.equal(JSON.parse(settings.stdout).settings.gateSlots, 4, 'the refused decrease did not change settings');
+ for (const child of children) await release(child);
+ const changed = configureGateSlots(box, 1);
+ assert.equal(changed.status, 0, changed.stderr);
+ assert.equal(privateList(box).find(row => row.name === 'gate').capacity, 1,
+ 'the same decrease works after the holders finish');
+ } finally { for (const child of children) if (!child.exitResult) await release(child); }
+}
+
+/** Exercise the original browser capacity case through the public CLI. */
+async function browser(tools) {
+ const { fixture, worker, event, acquired, release, privateList, poolWorker, POOL_MODULE_WORKER, configureBrowserSlots } = tools;
+ const box = fixture();
+ assert.equal(configureGateSlots(box, 4).status, 0);
+ const script = POOL_MODULE_WORKER.replace('capacity: 2,',
+ 'capacity: loadMachineSettings().gateSlots, capacityProvider: () => loadMachineSettings().gateSlots,');
+ const children = [];
+ try {
+ const first = poolWorker(box, { agent: 'browser-holder', browser: true, script }); children.push(first);
+ await acquired(first);
+ for (const agent of ['browser-waiter-one', 'browser-waiter-two', 'browser-waiter-three']) {
+ const child = poolWorker(box, { agent, browser: true, script }); children.push(child);
+ assert.ok((await event(child)).queued, 'the browser taker waits before browserSlots is raised');
+ }
+ const raised = configureBrowserSlots(box, 3);
+ assert.equal(raised.status, 0, raised.stderr);
+ for (const child of children.slice(1, 3)) await acquired(child);
+ const rows = privateList(box);
+ assert.equal(rows.find(row => row.name === 'browser').capacity, 3);
+ assert.equal(rows.find(row => row.name === 'browser').holders.length, 3);
+ assert.equal(rows.find(row => row.name === 'gate').holders.length, 3);
+ assert.equal(rows.find(row => row.name === 'browser').line.length, 1,
+ 'the fourth browser stays queued even though a gate slot is free');
+ await release(first);
+ await acquired(children[3]);
+ assert.equal(privateList(box).find(row => row.name === 'browser').holders.length, 3);
+ } finally { for (const child of children) if (!child.exitResult) await release(child); }
+}
diff --git a/test/resources.test.js b/test/resources.test.js
index 4c8ea851..c5211a0a 100644
--- a/test/resources.test.js
+++ b/test/resources.test.js
@@ -12,6 +12,7 @@ import { createInterface } from 'node:readline';
import { after, test } from 'node:test';
import { DatabaseSync } from 'node:sqlite';
import { listResources, setResourceCapacity, takeResource } from '../src/resources.js';
+import { capacityChangeCases } from './resources-capacity-fixture.js';
import { checkNeedsBrowser } from '../src/browser-admission.js';
import { releaseQueueProof } from './resources-release-fixture.js';
@@ -1649,23 +1650,23 @@ test('the memory hold is off until a floor is set, an unread machine warns once,
assert.match(JSON.parse(json.stdout).memory.line, /^memory: /u, 'the JSON result carries the same machine line');
});
-test('[Q4] machine capacity changes atomically refuse an occupied or queued resource', async () => {
+test('[Q4] machine capacity decreases 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' });
+ const holder = worker(box, { capacity: 2, agent: 'capacity-holder' });
try {
assert.equal((await event(holder)).acquired, 'capacity-holder');
- const waiter = worker(box, { agent: 'capacity-waiter' });
+ const waiter = worker(box, { capacity: 2, agent: 'capacity-waiter' });
assert.equal((await event(waiter)).waiting, 1);
let persisted = false;
- assert.throws(() => setResourceCapacity({ name: 'gate', capacity: 3, persist: () => { persisted = true; } }), (error) => error.code === 'RESOURCE_BUSY');
+ assert.throws(() => setResourceCapacity({ name: 'gate', capacity: 1, persist: () => { persisted = true; } }), (error) => error.code === 'RESOURCE_BUSY');
assert.equal(persisted, false, 'settings remain unchanged while a holder and waiter exist');
await release(holder);
assert.equal((await event(waiter)).acquired, 'capacity-waiter');
- assert.throws(() => setResourceCapacity({ name: 'gate', capacity: 3, persist: () => { persisted = true; } }), (error) => error.code === 'RESOURCE_BUSY');
+ assert.throws(() => setResourceCapacity({ name: 'gate', capacity: 1, persist: () => { persisted = true; } }), (error) => error.code === 'RESOURCE_BUSY');
await release(waiter);
const changed = setResourceCapacity({ name: 'gate', capacity: 3, persist: () => { persisted = true; } });
assert.deepEqual(changed, { name: 'gate', capacity: 3 });
@@ -1750,3 +1751,15 @@ test('[Q4] a red gate releases its lease before the same process starts another
if (child.exitCode === null && child.signalCode === null) await closed;
}
});
+
+
+const capacityCases = capacityChangeCases({ fixture, worker, event, acquired, release, privateList, poolWorker, POOL_MODULE_WORKER, configureBrowserSlots });
+
+/** Existing queued processes observe a raised limit without restarting their holders [Q1,Q2,Q4]. */
+test("raising a busy resource's capacity admits waiters at once [Q1,Q2,Q4]", capacityCases.raising);
+
+/** A refused decrease names the live holders and leaves their leases and settings intact [Q1,Q3,Q4]. */
+test("lowering capacity never stops a running holder [Q1,Q3,Q4]", capacityCases.lowering);
+
+/** Browser capacity can grow under the same live gate lease without exceeding either limit [Q1,Q2,Q4]. */
+test("raising busy browser capacity admits only the new browser slots [Q1,Q2,Q4]", capacityCases.browser);