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(gate): compose release priority with memory hold [C7,V4]

Corey Olson5435af90ca7c
diff --cc docs/api.md
index 0f8a927b,282435fa..25d7e58c
--- a/docs/api.md
+++ b/docs/api.md
@@@ -12,10 -12,10 +12,12 @@@ A successful command returns the field
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.
--The machine gate pool admits landings first and then everything else in arrival order. A machine opts in to reviews first with `"gate": { "queue": { "reviewsFirst": true } }` in `~/.pullboard/settings.json`: the pool then admits landing runs, then reviews, then submits and item checks, then focused and other runs, first come first served within each class. `gate.queue.agingMinutes` (a positive whole number, default `30`) is how long a waiting run waits before it moves up one class, so no class starves; it is used only while `reviewsFirst` is true. `pullboard settings` prints both values, and `pullboard resources` names the order in effect.
++The machine gate pool admits landings first and then everything else in arrival order. A machine opts in to reviews first with `"gate": { "queue": { "reviewsFirst": true } }` in `~/.pullboard/settings.json`: the pool then admits landing runs, then reviews, then submits and item checks, then focused and other runs, first come first served within each class. `gate.queue.agingMinutes` (a positive whole number, default `30`) is how long a waiting run waits before it moves up one class, so no class starves; it is used while `reviewsFirst` or the release priority below is enabled. `pullboard settings` prints both values, and `pullboard resources` names the order in effect.
+
+Release priority is separately opt-in with `"gate": { "queue": { "currentReleaseFirst": true } }`. Before queueing, a gate run captures its board identity and its item's roadmap rank. The first unfinished milestone is current, counting only this board's own items as verified out of total; `repo#id` references are left out and never opened. Later milestones follow in roadmap order, then already completed earlier milestones, then unplanned work. Within otherwise-tied positions belonging to one board, current-release work goes first: `A-later, B, A-current` becomes `A-current, B, A-later`. Different boards retain their opportunity positions. Global admission classes and landings retain their existing precedence, and a waiter older than `agingMinutes` keeps its position against release reordering. Queued ranks do not change if the roadmap changes. With the setting off, no board is read for release priority. Unknown board identities keep their positions; while any older client is waiting, all clients fall back together to landings then arrival. `pullboard settings` prints `gate.queue.currentReleaseFirst`, default `false`.
+ The memory hold is opt-in per machine with `"gate": { "memoryFloorMB": <n> }` in `~/.pullboard/settings.json`; absent, it is off and the pool admits by slots alone, as before. When set, before admitting a run the machine gate pool reads the machine's memory: on macOS the kernel's memory pressure level and free percentage, on Linux `MemAvailable` and the pressure stall averages in `/proc/pressure/memory`. The whole queue, landings included, waits in place while pressure is critical or free memory is under that many megabytes (`0` leaves only the pressure check). A held run prints one line naming why and the three biggest processes by memory, with pid, size and working directory, and starts once memory recovers. While the floor is set, `pullboard resources` prints the same line and returns it as `memory` in JSON; with no floor it reads no memory and `memory` is `null`. Where memory cannot be read, the pool admits by slots alone and prints one warning that memory is not checked there.
+
When `add` or `edit` supplies a new nonempty check, it records the item before measuring that check in a background temporary checkout of the captured `main` commit. Use `--wait` to wait for the measurement before returning, or `args.wait: true` for an HTTP add/edit move. The item returned by `add`, `edit`, `show`, and `next --verify` may include `item_check_baseline`: `{command, main, result, request?, seconds?, reason?, warning?}`. `main` is the commit id or `null`, and `result` is `pending`, `green`, `red`, or `unavailable`. A background request carries an opaque `request` identity; an older completion cannot overwrite a newly edited or cleared check.
An item's HTTP detail, and each item in the full board state, include `check` and, when recorded, `checkBaseline` with the same observation fields. A green result carries `warning: "CRITERION_PROVES_NOTHING"`; text output names that warning when showing or reserving the item for review, and when filing it with `--wait`. An exact match with the project gate configured at that main commit records green with `reason: "repo gate"` without running it again. A missing main records unavailable with `reason: "no main"` and still files the item. Changing the check replaces this observation; clearing it removes the observation. Captured observations and completions travel through ordered board moves, so replicas store results without executing commands. A completed result awaiting relay delivery stays on the measuring device and is retried by the next normal CLI command.
diff --cc src/cli.js
index 094d1a1a,8e575399..253c8bf0
--- a/src/cli.js
+++ b/src/cli.js
@@@ -3178,8 -3229,8 +3229,9 @@@ function settingsCommand(io, { first, s
io.say(`gateSlots: ${settings.gateSlots}`);
io.say(`browserSlots: ${settings.browserSlots}`);
io.say(`gate.queue.reviewsFirst: ${queue.reviewsFirst}${queue.reviewsFirst ? '' : ' (landings first, then arrival order)'}`);
- io.say(`gate.queue.agingMinutes: ${queue.agingMinutes}${queue.reviewsFirst ? '' : ' (used only while reviewsFirst is true)'}`);
+ io.say(`gate.queue.currentReleaseFirst: ${queue.currentReleaseFirst}${queue.currentReleaseFirst ? '' : ' (release priority is off)'}`);
- io.say(`gate.queue.agingMinutes: ${queue.agingMinutes}${queue.reviewsFirst ? '' : ' (used only while reviewsFirst is true)'}`);
++ io.say(`gate.queue.agingMinutes: ${queue.agingMinutes}${queue.reviewsFirst || queue.currentReleaseFirst ? '' : ' (used only while reviewsFirst or currentReleaseFirst is true)'}`);
+ io.say(`gate.memoryFloorMB: ${memoryFloorMB() ?? 'off (the gate queue does not wait for memory)'}`);
return 0;
}
if (!['gateSlots', 'browserSlots'].includes(first) || !second || rest.length) {
diff --cc src/gate.js
index eaf7a672,cf33501f..bb2e99c5
--- a/src/gate.js
+++ b/src/gate.js
@@@ -13,8 -13,8 +13,8 @@@ import { fileURLToPath } from 'node:url
import { gitChildEnv, gitPath, headTree, invalidateGitFacts, isClean, untracked } from './git.js';
import { secretsIn } from './hooks.js';
import { Refused } from './refused.js';
- import { GATE_SLOT_HELD_ENV, gateSlotEnvironment, inheritedGateSlot, takeResource } from './resources.js';
- import { browserFreeChecksEnabled, gateQueueSettings, loadMachineSettings } from './settings.js';
+ import { GATE_SLOT_HELD_ENV, gateSlotEnvironment, inheritedGateSlot, memoryAdmission, readMachineMemory, takeResource } from './resources.js';
-import { browserFreeChecksEnabled, loadMachineSettings, memoryFloorMB } from './settings.js';
++import { browserFreeChecksEnabled, gateQueueSettings, loadMachineSettings, memoryFloorMB } from './settings.js';
import { selectAffectedTests } from './affected-tests.js';
import { checkNeedsBrowser, testsNeedBrowser } from './browser-admission.js';
import { timingFromOutput, timingRunner } from './timing.js';
@@@ -509,11 -510,9 +510,12 @@@ export async function withGateSlot(root
finally { inherited.release(); }
}
const settingsProvider = () => loadMachineSettings();
+ const floorMB = memoryFloorMB();
const capacityProvider = () => settingsProvider().gateSlots;
const source = runnerSource(root);
+ // Read the board once before queueing, never inside the machine admission transaction.
+ const releaseContext = gateQueueSettings().currentReleaseFirst
+ ? (await import('./release-queue.js')).captureReleaseQueue(root, item) : undefined;
let lease = await takeResource({
name: 'gate',
capacity: capacityProvider(),
@@@ -532,7 -531,7 +534,8 @@@
allowIdleCapacityUpdate: true,
remote: remote && Boolean(source),
runnerProvider: () => loadMachineSettings().runners ?? [],
+ releaseContext,
+ memory: floorMB === null ? undefined : memoryAdmission({ floorBytes: () => (memoryFloorMB() ?? floorMB) * 1024 ** 2, read: readMemory }),
onWait,
});
try {
diff --cc src/help.js
index d6d3d936,ce71173b..98ec9cab
--- a/src/help.js
+++ b/src/help.js
@@@ -24,7 -25,7 +25,8 @@@ Set u
pullboard settings [gateSlots <n> | browserSlots <n>] view or set machine capacity (gate default 2; browser default 1)
browser-free check slots are opt-in: gate.browserFreeChecks in ~/.pullboard/settings.json (default false)
reviews-first queue order is opt-in: gate.queue.reviewsFirst (default false), gate.queue.agingMinutes (default 30)
+ release priority is opt-in: gate.queue.currentReleaseFirst (default false), within each board's otherwise-tied positions
+ memory hold is opt-in: gate.memoryFloorMB in ~/.pullboard/settings.json holds the queue under that many MB free or critical pressure (default off)
pullboard runner add <ssh-host> --slots <n> --browser <n> [--node <remote-path>] [--root <remote-path>]
register SSH test capacity; no runner sign-in; root defaults to ~/.pullboard-runner
pullboard view [--project] [--port N] [--no-open] every project on this machine in your browser; default http://127.0.0.1:${DEFAULT_VIEW_PORT}
diff --cc src/resources.js
index ca4792b6,3057ff88..af90f406
--- a/src/resources.js
+++ b/src/resources.js
@@@ -496,10 -678,15 +632,16 @@@ export async function takeResource(opti
initialTicket = Number(inserted.lastInsertRowid);
}
});
+ let memoryWarned = false;
while (true) {
+ const memory = options.memory ? await options.memory() : null;
+ if (memory && !memory.checked && !memoryWarned) {
+ memoryWarned = true;
+ options.onWait?.({ holders: [], line: [], position: 0, memory });
+ }
const order = queueOrder(scope);
const acquired = update(db, () => {
+ const now = Date.now();
// The machine-settings provider performs a bounded local JSON read. Read it
// after taking the same SQLite write lock used by updateRunnerSettings so an
// older pre-lock snapshot cannot overwrite a newer configured capacity.
@@@ -517,14 -704,15 +659,16 @@@
}
// The marker follows this poll's setting, so a change mid-wait reaches every process's ranking.
db.prepare('UPDATE waiter SET heartbeat = ?, classed = ? WHERE token = ?').run(Date.now(), classedMarker(order), token);
- const spot = snapshot(db, name, order);
- const reportPosition = waiterPosition(db, name, waiter.ticket, { order });
+ const spot = snapshot(db, name, order, now);
+ const reportPosition = waiterPosition(db, name, waiter.ticket, { order, now });
const limit = db.prepare('SELECT capacity FROM resource WHERE name = ?').get(name).capacity;
+ // A machine short of memory holds the whole line in place; recovery admits it in order.
+ if (memory?.held) return { acquired: false, state: { ...spot, position: reportPosition, memory } };
const executor = name === 'gate'
- ? gateAdmission(db, waiter.ticket, limit, runners, order)
- : (waiterPosition(db, name, waiter.ticket, { eligibleOnly: true, order }) === 1 && spot.holders.length < limit ? { host: '' } : null);
+ ? gateAdmission(db, waiter.ticket, limit, runners, order, now)
+ : (waiterPosition(db, name, waiter.ticket, { eligibleOnly: true, order, now }) === 1 && spot.holders.length < limit ? { host: '' } : null);
if (executor) {
+ const queueTicket = consumeOpportunity(db, name, waiter.ticket, order, now);
db.prepare('DELETE FROM waiter WHERE token = ?').run(token);
const acquiredAt = new Date().toISOString();
const holderName = executor.host ? runnerResourceName(executor.host) : name;