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(gate): every gate receipt splits waiting from running [C7,V10]

Corey Olsond45b22c5e047
diff --git a/docs/api.md b/docs/api.md
index 92ecace8..c4ea7a44 100644
--- a/docs/api.md
+++ b/docs/api.md
@@ -36,6 +36,8 @@ For a stale acceptance, merge current main into the submitted work and commit a
`pullboard stats [--since <date>] --json` returns `{version: 1, stats: {...}}` from the append-only event log. `submissions` and `rejections` count moves, including repeated attempts; `rejectionShare` is rejections divided by submissions (zero when the window has no submissions). `merged` counts distinct items with a merge move; `mergedWithoutAccept` counts those whose merge lacks an earlier acceptance of the latest submitted commit. That audit uses earlier history even when the acceptance falls before the selected window. Current item and verdict rows do not replace event evidence.
+`stats.gateWaits` lists, for each kind of gated run in the last day (`check`, `review`, `doctrine`, `gate`, `landing`), its `runs`, `medianWaitMs`, `slowestWaitMs` and `medianRunMs`, read from the board's gate receipts; text `stats` prints them under `gate waits, last day:`. A gate receipt is written for every run that takes a gate slot. Its fields are `waitMs` (queued for a slot), `admissionMs` (deciding and queueing, then handing over), `setupMs`, `runMs` and `evidenceMs` (reading the result and writing its record), and `slot: {kind, reason}`, where `kind` is `ordinary`, `browser`, `short`, `runner` or `inherited`. A timing profile carries it as `receipt`, `check --json` returns it as `receipt`, and the timing lines print it as `phases: ...; slot: <kind> (<reason>)`. A doctrine hold at submit prints its own `doctrine hold phases:` line.
+
`stats.bars` counts bar corrections, keyed by agent: `{corrections, barRejects, buildRejects}`. A correction is an `edit --criterion` or `--check` on an item that was ever claimed. It must carry `--reason "what the old bar got wrong"` (HTTP `args.reason`); without one it is refused with `BAR_REASON`. A correction that follows the item's newest, unexplained reject marks that reject as caused by the bar, counted to the correcting agent; every other reject counts to the build, under the agent who added the item. Text `stats` prints one `bars:` line per agent, and text `show` prints each correction with its reason.
`stats.flow` adds the flow through the board:
@@ -96,7 +98,7 @@ For example: `flow: review wait average 61 min (1 measured; > 60 min); bottlenec
| `milestone remove` | `version:number`, `milestone:object` |
| `milestone ship` | `version:number`, `milestone:object`, `into:string|null`, `moved:array`, `notMoved:array` |
| `show` | `version:number`, `item_id:number`, `item_title:string`, `item_lane:string`, `item_status:string`, `verdicts:array`, `thread:array` |
-| `stats` | `version:number`, `stats:object` |
+| `stats` | `version:number`, `stats:object`, `gateWaits:array` |
| `status` | `version:number`, `me:object`, `mine:array`, `stats:object`, `reviewQueue:object`, `unread:number`, `relay:object` |
| `doctor` | `version:number`, `problems:array` |
| `health` | `version:number`, `asOf:string`, `thresholds:object`, `stuck:array`, `waiting:array` |
@@ -115,7 +117,7 @@ For example: `flow: review wait average 61 min (1 measured; > 60 min); bottlenec
| `run` | `version:number`, `messages:array` |
| `sweep` | `version:number`, `messages:array` |
| `next` | `version:number`, `item:object`, `review:boolean`, `held:boolean`, `shared:array` |
-| `check` | `version:number`, `id:number`, `green:boolean`, `seconds:number`, `check:string`, `report:string` |
+| `check` | `version:number`, `id:number`, `green:boolean`, `seconds:number`, `check:string`, `receipt:object`, `report:string` |
| `check accept` | `version:number`, `id:number`, `digest:string`, `check:string` |
| `claim` | `version:number`, `id:number`, `renewed:boolean`, `leaseUntil:string`, `digest:string` |
| `hold` | `version:number`, `lane:string`, `held:boolean` |
diff --git a/src/cli.js b/src/cli.js
index 206690eb..d3d1a809 100644
--- a/src/cli.js
+++ b/src/cli.js
@@ -41,6 +41,8 @@ import {
refuseNextIdle,
} from './next-steps.js';
import { reviewerStartup } from './next-steps.js';
+import { gateWaitStats } from './gate-receipt.js';
+import { receiptLine } from './gate-receipt.js';
import * as store from './board.js';
import {
CONFIG_FILE,
@@ -2614,7 +2616,8 @@ function readCommands(io, { first, second, rest, values }) {
stats: () => {
const ctx = context(io);
const { stats, agents } = withBoard(ctx, (board) => ({ stats: proofStats(board, { since: values.since }), agents: store.listAgents(board) }));
- io.result?.({ stats });
+ const waits = gateWaitStats(ctx.info.root);
+ io.result?.({ stats, gateWaits: waits.stats });
io.say(`${stats.submissions} submissions · ${stats.rejections} rejections · ${(stats.rejectionShare * 100).toFixed(1)}% sent back`);
io.say(`${stats.merged} items merged · ${stats.mergedWithoutAccept} merged without an accept`);
io.say(`${stats.agentCount} agents · ${stats.familyCount} family buckets: ${stats.families.map((family) => `${family.name} (${family.agents} agents, ${family.moves} moves)`).join('; ') || 'none'}`);
@@ -2622,6 +2625,7 @@ function readCommands(io, { first, second, rest, values }) {
io.say(`events: ${stats.firstEventAt ?? 'none'} to ${stats.lastEventAt ?? 'none'}${stats.since ? ` (since ${stats.since})` : ''}`);
for (const line of barStatsLines(stats.bars)) io.say(line);
for (const line of flowLines(stats.flow)) io.say(line);
+ for (const line of waits.lines) io.say(line);
return 0;
},
ledger: () => {
@@ -2744,7 +2748,7 @@ async function submitHere(ctx, id) {
// Doctrine counts only fall: accepted main's rules, at this exact commit (D1). No rule, no change.
const doctrine = hasSubmitRules(root, acceptedMain.commit, acceptedMain.config.practice)
? await withGateSlot(root, () => holdDoctrine(root, { mainCommit: acceptedMain.commit, commit, practice: acceptedMain.config.practice, timeoutMs: acceptedMain.config.check?.timeoutMs }),
- { itemCheck: true, agent: me.id, item: String(id), kind: 'doctrine', onWait: queuedItemLease(ctx, held, me.id, 'build') })
+ { itemCheck: true, agent: me.id, item: String(id), kind: 'doctrine', onWait: queuedItemLease(ctx, held, me.id, 'build'), onReceipt: (receipt) => ctx.io.say(`doctrine hold ${receiptLine(receipt)}`) })
: [];
for (const rule of doctrine) ctx.io.say(`doctrine: ${ruleLine(rule)}`);
// Every submit proves its frozen check and reachable tests anew on this exact commit (V4,V16).
@@ -3584,7 +3588,7 @@ function workCommands(io, args) {
const shortEligible = Boolean(await explicitCheckFiles(ctx.info.root, check));
const run = await withGateSlot(ctx.info.root, (lease) => runProfiledShell(ctx.info.root, check, { waitMs: lease.waitMs, artifactPrefix: `pullboard-check-${item.item_id}`, persistLog: true, gateLease: lease }), { browser, agent: caller, item: String(item.item_id), kind: 'check', itemCheck: true, shortEligible, onWait: queuedItemLease(ctx, item, caller, 'build') });
refuseSandboxBlocked(run);
- io.result?.({ id: item.item_id, green: run.isGreen, seconds: run.seconds, check, by, report: run.isGreen ? '' : digestOf(run.output) });
+ io.result?.({ id: item.item_id, green: run.isGreen, seconds: run.seconds, check, by, receipt: run.profile?.receipt, report: run.isGreen ? '' : digestOf(run.output) });
const timings = timingDigest(run.profile);
const compact = timings && !run.profile.files.length
? `; ${timings.replaceAll('\n', '; ')}; timing profile: ${run.profilePath}` : '';
diff --git a/src/gate-receipt.js b/src/gate-receipt.js
new file mode 100644
index 00000000..9a85fa64
--- /dev/null
+++ b/src/gate-receipt.js
@@ -0,0 +1,134 @@
+/**
+ * Gate receipts (#836): where a gated run's time went. Every run that takes a gate slot (submit, a named check, a
+ * doctrine hold) reports separate phases and the kind of slot it got, and appends one line to the board's receipt log
+ * so `pullboard stats` can show a day of waits beside run times. Measuring only; no slot behaviour lives here.
+ */
+import { appendFileSync } from 'node:fs';
+import { existsSync } from 'node:fs';
+import { mkdirSync } from 'node:fs';
+import { readFileSync } from 'node:fs';
+import { dirname } from 'node:path';
+import { join } from 'node:path';
+import { repoInfo } from './git.js';
+
+const DAY_MS = 24 * 60 * 60 * 1000;
+
+/** The board's receipt log, shared by every worktree of the repo. */
+export function receiptLog(root) {
+ return join(repoInfo(root).commonDir, 'pullboard', 'gate-receipts.jsonl');
+}
+
+/**
+ * Start timing one gated run when it asks for a slot. The run marks its own phases on the returned tracker; a run
+ * that never marks them (a doctrine hold) counts its whole action as running.
+ */
+export function startReceipt() {
+ const marks = { requestedAt: Date.now() };
+ return { marks, mark(name) { marks[name] ??= Date.now(); } };
+}
+
+/**
+ * Which kind of slot a lease is, and why the run got it.
+ *
+ * @param {{ runner?: { host: string }, slotClass?: string, browser?: boolean, inherited?: boolean }} lease
+ * @param {{ browserFree: boolean }} admission - Whether browser-free checks are on for this machine.
+ * @returns {{ kind: string, reason: string }}
+ */
+export function slotOf(lease, { browserFree }) {
+ if (lease.inherited) return { kind: 'inherited', reason: 'it ran inside a slot its caller already held' };
+ if (lease.runner) return { kind: 'runner', reason: `registered runner ${lease.runner.host} had a free slot` };
+ if (lease.slotClass === 'short') return { kind: 'short', reason: 'every ordinary slot was held and the run names its test files' };
+ if (lease.browser) {
+ return { kind: 'browser', reason: browserFree ? 'its files may launch a browser' : 'browser-free checks are off, so every run takes a browser-capable slot' };
+ }
+ return { kind: 'ordinary', reason: 'it launches no browser' };
+}
+
+/**
+ * Split a run's time at its marks: waiting for a slot, admission (deciding and queueing, then handing over), setup,
+ * running and evidence (reading the result and writing its record).
+ *
+ * @param {{ requestedAt: number, queuedAt?: number, admittedAt?: number, actionAt?: number, runAt?: number, ranAt?: number }} marks
+ * @param {number} endAt
+ */
+export function phasesOf(marks, endAt) {
+ const queuedAt = marks.queuedAt ?? marks.requestedAt;
+ const admittedAt = marks.admittedAt ?? queuedAt;
+ const actionAt = marks.actionAt ?? admittedAt;
+ const runAt = marks.runAt ?? actionAt;
+ const ranAt = marks.ranAt ?? endAt;
+ const span = (from, to) => Math.max(0, Math.round(to - from));
+ return {
+ waitMs: span(queuedAt, admittedAt),
+ admissionMs: span(marks.requestedAt, queuedAt) + span(admittedAt, actionAt),
+ setupMs: span(actionAt, runAt),
+ runMs: span(runAt, ranAt),
+ evidenceMs: span(ranAt, endAt),
+ };
+}
+
+/** One receipt: the run's kind, its phases and its slot. */
+export function receiptOf(tracker, { kind, slot, endAt = Date.now() }) {
+ return { at: new Date(endAt).toISOString(), kind: kind || 'gate', ...phasesOf(tracker.marks, endAt), slot };
+}
+
+/** Append a receipt to the board's log. A log that cannot be written never fails the run it describes. */
+export function recordReceipt(root, receipt) {
+ try {
+ const file = receiptLog(root);
+ mkdirSync(dirname(file), { recursive: true, mode: 0o700 });
+ appendFileSync(file, JSON.stringify(receipt) + '\n', { mode: 0o600 });
+ } catch { /* The receipt is diagnostic; the run's own verdict stands without it. */ }
+}
+
+/** The receipts of the last day, skipping any line that is not a whole receipt. */
+export function recentReceipts(root, now = Date.now()) {
+ const file = receiptLog(root);
+ if (!existsSync(file)) return [];
+ return readFileSync(file, 'utf8').split('\n').flatMap((line) => {
+ try {
+ const receipt = JSON.parse(line);
+ return now - Date.parse(receipt.at) <= DAY_MS && Number.isFinite(receipt.waitMs) && Number.isFinite(receipt.runMs) ? [receipt] : [];
+ } catch { return []; }
+ });
+}
+
+/** The middle value of a list of durations. */
+function median(values) {
+ const sorted = [...values].sort((left, right) => left - right);
+ const middle = Math.floor(sorted.length / 2);
+ return sorted.length % 2 ? sorted[middle] : Math.round((sorted[middle - 1] + sorted[middle]) / 2);
+}
+
+/** Each check kind's runs, median and slowest wait, and median run time. */
+export function receiptStats(receipts) {
+ const kinds = new Map();
+ for (const receipt of receipts) kinds.set(receipt.kind, [...(kinds.get(receipt.kind) ?? []), receipt]);
+ return [...kinds].sort(([left], [right]) => left.localeCompare(right)).map(([kind, rows]) => ({
+ kind, runs: rows.length,
+ medianWaitMs: median(rows.map((row) => row.waitMs)),
+ slowestWaitMs: Math.max(...rows.map((row) => row.waitMs)),
+ medianRunMs: median(rows.map((row) => row.runMs)),
+ }));
+}
+
+/** Seconds with two decimals, as the timing lines print them. */
+function seconds(ms) { return `${(ms / 1000).toFixed(2)}s`; }
+
+/** The stats lines for a day of receipts. */
+export function receiptStatsLines(stats) {
+ if (!stats.length) return ['gate waits, last day: no gated runs recorded'];
+ return ['gate waits, last day:', ...stats.map((row) => ` ${row.kind}: ${row.runs} run${row.runs === 1 ? '' : 's'}; wait median ${seconds(row.medianWaitMs)}, slowest ${seconds(row.slowestWaitMs)}; run median ${seconds(row.medianRunMs)}`)];
+}
+
+/** One line of a receipt's phases and slot, for a timing digest. */
+export function receiptLine(receipt) {
+ if (!receipt) return '';
+ return `phases: wait ${seconds(receipt.waitMs)}, admission ${seconds(receipt.admissionMs)}, setup ${seconds(receipt.setupMs)}, run ${seconds(receipt.runMs)}, evidence ${seconds(receipt.evidenceMs)}; slot: ${receipt.slot.kind} (${receipt.slot.reason})`;
+}
+
+/** The last day's gate waits for `pullboard stats`: the numbers for --json and the lines to print. */
+export function gateWaitStats(root, now = Date.now()) {
+ const stats = receiptStats(recentReceipts(root, now));
+ return { stats, lines: receiptStatsLines(stats) };
+}
diff --git a/src/gate.js b/src/gate.js
index e44d7670..eb458172 100644
--- a/src/gate.js
+++ b/src/gate.js
@@ -68,6 +68,11 @@ import {
timingRunner,
} from './timing.js';
import { landingShardProfile } from './landing-shards.js';
+import { receiptLine } from './gate-receipt.js';
+import { receiptOf } from './gate-receipt.js';
+import { recordReceipt } from './gate-receipt.js';
+import { slotOf } from './gate-receipt.js';
+import { startReceipt } from './gate-receipt.js';
import {
gateStages,
stagedScript,
@@ -306,19 +311,21 @@ export function runProfiledShell(root, command, { waitMs = 0, artifactDirectory,
[LANDING_WAIVERS_ENV]: landing ? JSON.stringify(waivers) : '[]',
};
// The registered worker returns the same complete stage/component accounting as a local run.
+ gateLease?.tracker?.mark('runAt');
const run = gateLease?.runner ? { ...runOnRunner(root, command, { runner: gateLease.runner, source: gateLease.source,
browser: gateLease.browser, pipefail, stages, waivers: landing ? waivers : [], metadata: { ...(gateLease.runMetadata ?? {}), landing } }) }
: runShell(root, command, { pipefail, env: inherited, stages });
+ gateLease?.tracker?.mark('ranAt');
const sandboxBlocked = run.isGreen ? null : run.sandboxBlocked ?? (run.executionRunner
// The controller cannot realpath remote files; retain the network denial signal without treating remote paths as local paths.
? sandboxBlockedOperation(root, run.output, { includeFilePaths: false })
: sandboxBlockedOperation(root, run.output));
const profiledRun = { ...run, sandboxBlocked };
+ if (logPath) writeFileSync(logPath, safeLog(run.output), { mode: 0o600 });
const profile = writeTimingProfile(profilePath, {
...runTiming(profiledRun, command),
- waitMs: Math.max(0, Math.round(waitMs)), wallMs: Math.max(0, Date.now() - started),
+ waitMs: Math.max(0, Math.round(waitMs)), wallMs: Math.max(0, Date.now() - started), receipt: settleReceipt(gateLease),
});
- if (logPath) writeFileSync(logPath, safeLog(run.output), { mode: 0o600 });
return { ...profiledRun, profile, profilePath, logPath };
}
@@ -330,14 +337,16 @@ export function runProfiledShell(root, command, { waitMs = 0, artifactDirectory,
*/
export async function runProfiledShellAsync(root, command, { waitMs = 0, gateSlotHeld = false, gateLease, landing = false } = {}) {
const started = Date.now();
+ gateLease?.tracker?.mark('runAt');
if (gateLease?.runner) {
const run = await runOnRunnerAsync(root, command, { runner: gateLease.runner, source: gateLease.source,
browser: gateLease.browser, metadata: { ...(gateLease.runMetadata ?? {}), landing } });
+ gateLease.tracker?.mark('ranAt');
const wallMs = Math.max(0, Date.now() - started);
const profilePath = join(dirname(gitPath(root, LOG)), `pullboard-gate-${randomUUID()}.profile.json`);
const sandboxBlocked = run.isGreen ? null : run.sandboxBlocked
?? sandboxBlockedOperation(root, run.output, { includeFilePaths: false });
- const profile = writeTimingProfile(profilePath, { ...runTiming(run, command), waitMs, wallMs });
+ const profile = writeTimingProfile(profilePath, { ...runTiming(run, command), waitMs, wallMs, receipt: settleReceipt(gateLease) });
return { ...run, sandboxBlocked, seconds: Math.round(wallMs / 1000), profile, profilePath, logPath: null };
}
const inherited = {
@@ -360,16 +369,24 @@ export async function runProfiledShellAsync(root, command, { waitMs = 0, gateSlo
child.stderr.setEncoding('utf8').on('data', capture);
child.once('error', error => { failure = error; });
const status = await new Promise(resolveClose => child.once('close', resolveClose));
+ gateLease?.tracker?.mark('ranAt');
invalidateGitFacts();
const output = chunks.join('') + (overflow ? '\nFocused comparison output exceeded one GiB.\n' : '')
+ (failure ? `\n${failure.message}\n` : '');
const wallMs = Math.max(0, Date.now() - started);
const profilePath = join(dirname(gitPath(root, LOG)), `pullboard-gate-${randomUUID()}.profile.json`);
const profile = writeTimingProfile(profilePath, { ...timingFromOutput(output, timingRunner(command)),
- waitMs: Math.max(0, Math.round(waitMs)), wallMs });
+ waitMs: Math.max(0, Math.round(waitMs)), wallMs, receipt: settleReceipt(gateLease) });
return { isGreen: status === 0 && !overflow && !failure, sandboxBlocked: status === 0 ? null : sandboxBlockedOperation(root, output), output, seconds: Math.round(wallMs / 1000), profile, profilePath, logPath: null };
}
+/** Close a gated run's receipt (#836) as its evidence is written; the slot's release records this same receipt. */
+function settleReceipt(lease) {
+ if (!lease?.tracker) return undefined;
+ lease.receipt = receiptOf(lease.tracker, { kind: lease.receiptKind, slot: lease.slot });
+ return lease.receipt;
+}
+
/** Keep raw remote TAP intact while resolving its measured filenames against the local source. */
function runTiming(run, command) {
const shards = landingShardProfile(run.output);
@@ -424,6 +441,7 @@ export function writeTimingProfile(path, profile) {
format: sanitize(profile.format ?? 'none', 'format'),
unavailable: sanitize(profile.unavailable ?? null, 'availability'),
...(profile.executionRunner ? { executionRunner: sanitize(profile.executionRunner, 'execution runner') } : {}),
+ ...(profile.receipt ? { receipt: { ...profile.receipt, slot: { kind: sanitize(profile.receipt.slot?.kind, 'slot kind'), reason: sanitize(profile.receipt.slot?.reason, 'slot reason') } } } : {}),
...(profile.landingShards ? { landingShards: {
balance: sanitize(String(profile.landingShards.balance ?? 'unknown'), 'landing balance'),
unverified: (profile.landingShards.unverified ?? []).map(entry => ({ shard: sanitize(String(entry.shard), 'landing unverified shard'),
@@ -472,14 +490,24 @@ function hasPipeline(command) {
* hold (gate.memoryFloorMB) holds short slots too, since a short run uses the same machine memory.
*
* @param {(lease: { waitMs: number, token?: string, pool?: string, browser?: boolean, slotClass?: 'gate'|'short', release: () => void }) => any | Promise<any>} action - Work to perform while holding a slot.
- * @param {{ landing?: boolean, itemCheck?: boolean, shortEligible?: boolean, diagnostic?: boolean, browser?: boolean, remote?: boolean, agent?: string, item?: string|number, kind?: string, onWait?: (state: object) => void, readMemory?: typeof readMachineMemory }} [options] - Queue class, short-slot eligibility, remote eligibility, progress reporter and, for tests, the machine memory reader.
+ * @param {{ landing?: boolean, itemCheck?: boolean, shortEligible?: boolean, diagnostic?: boolean, browser?: boolean, remote?: boolean, agent?: string, item?: string|number, kind?: string, onWait?: (state: object) => void, onReceipt?: (receipt: object) => void, readMemory?: typeof readMachineMemory }} [options] - Queue class, short-slot eligibility, remote eligibility, progress reporter, the run's receipt once its slot is released (#836) and, for tests, the machine memory reader.
* @returns {Promise<any>} The action's result after releasing its lease.
*/
-export async function withGateSlot(root, action, { landing = false, itemCheck = false, shortEligible = false, diagnostic = false, browser = false, remote = true, agent, item = '', kind = '', onWait, readMemory = readMachineMemory } = {}) {
+export async function withGateSlot(root, action, { landing = false, itemCheck = false, shortEligible = false, diagnostic = false, browser = false, remote = true, agent, item = '', kind = '', onWait, onReceipt, readMemory = readMachineMemory } = {}) {
+ const tracker = startReceipt();
+ const receiptKind = kind || (landing ? 'landing' : 'gate');
+ /** Hand the run its receipt tracker and slot, then record its receipt once the slot is released (#836). */
+ const timed = lease => Object.assign(lease, { tracker, receiptKind, slot: slotOf(lease, { browserFree: browserFreeChecksEnabled() }) });
+ const record = lease => {
+ const receipt = lease.receipt ?? receiptOf(tracker, { kind: receiptKind, slot: lease.slot });
+ recordReceipt(root, receipt);
+ onReceipt?.(receipt);
+ };
const inherited = inheritedGateSlot({ root, browser, namedFiles: shortEligible });
if (inherited) {
+ timed(Object.assign(inherited, { inherited: true })).tracker.mark('actionAt');
try { return await action(inherited); }
- finally { inherited.release(); }
+ finally { inherited.release(); record(inherited); }
}
const settingsProvider = () => loadMachineSettings();
const floorMB = memoryFloorMB();
@@ -488,6 +516,7 @@ export async function withGateSlot(root, action, { landing = false, itemCheck =
// 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;
+ tracker.mark('queuedAt');
let lease = await takeResource({
name: 'gate',
capacity: capacityProvider(),
@@ -512,10 +541,12 @@ export async function withGateSlot(root, action, { landing = false, itemCheck =
memory: floorMB === null ? undefined : memoryAdmission({ floorBytes: () => (memoryFloorMB() ?? floorMB) * 1024 ** 2, read: readMemory }),
onWait,
});
+ tracker.mark('admittedAt');
try {
while (true) {
lease.source = source;
lease.runMetadata = { landing, itemCheck, diagnostic, item: String(item), kind };
+ timed(lease).tracker.mark('actionAt');
try { return await action(lease); }
catch (error) {
if (!(error instanceof RunnerDropped) || !lease.runner || !lease.requeueRunner) throw error;
@@ -527,6 +558,7 @@ export async function withGateSlot(root, action, { landing = false, itemCheck =
}
} finally {
lease.release();
+ record(lease);
}
}
@@ -692,7 +724,8 @@ export function timingDigest(profile) {
const summary = `timing (${profile.runner ?? 'shell'}${profile.executionRunner ? ` on runner ${profile.executionRunner}` : ''}): wall ${measured(profile.wallMs)}, slot wait ${measured(profile.waitMs)}`;
const rows = [...(profile.files ?? [])].filter(file => typeof file.path === 'string' && Number.isFinite(file.durationMs) && file.durationMs >= 0).sort((left, right) => right.durationMs - left.durationMs).slice(0, 10);
const files = rows.length ? `\nslowest test files:\n${rows.map(file => ` ${file.path}: ${(file.durationMs / 1000).toFixed(2)}s`).join('\n')}` : '';
- return `${summary}${profile.unavailable ? `\n${profile.unavailable}` : ''}${files}`;
+ const receipt = profile.receipt ? `\n${receiptLine(profile.receipt)}` : '';
+ return `${summary}${receipt}${profile.unavailable ? `\n${profile.unavailable}` : ''}${files}`;
}
/**
diff --git a/test/gate-timing-output.test.js b/test/gate-timing-output.test.js
index 9f6ea3b1..a8e63480 100644
--- a/test/gate-timing-output.test.js
+++ b/test/gate-timing-output.test.js
@@ -1,7 +1,9 @@
+/** @pullboard-test-input source-tree */
/** Timing profiles parse the caller's unchanged TAP or JUnit output [C7,V10]. */
import assert from 'node:assert/strict';
import { execFileSync } from 'node:child_process';
-import { mkdtempSync, mkdirSync, readFileSync, realpathSync, rmSync, writeFileSync } from 'node:fs';
+import { spawn } from 'node:child_process';
+import { cpSync, mkdtempSync, mkdirSync, readFileSync, realpathSync, rmSync, writeFileSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { join, resolve } from 'node:path';
import { test } from 'node:test';
@@ -134,3 +136,39 @@ function shellWord(value) {
}
test.after(() => { for (const path of TEMP) rmSync(path, { recursive: true, force: true }); });
+
+test('a gate receipt splits waiting from running [C7,V10]', async t => {
+ const { createE2eHelpers } = await import('./e2e-helpers.js');
+ const helpers = createE2eHelpers();
+ t.after(helpers.cleanup);
+ const box = helpers.project('true');
+ // A check the runner can classify: this repo's own runner and one named file that never launches a browser.
+ cpSync(resolve(import.meta.dirname, '../bin'), join(box.repo, 'bin'), { recursive: true });
+ cpSync(resolve(import.meta.dirname, '../src'), join(box.repo, 'src'), { recursive: true });
+ mkdirSync(join(box.repo, 'test'));
+ writeFileSync(join(box.repo, 'test/quick.test.js'), "import { test } from 'node:test'; test('quick', () => new Promise(done => setTimeout(done, 200)));\n");
+ box.git(box.repo, 'add', 'bin', 'src', 'test');
+ box.git(box.repo, 'commit', '-q', '-m', 'test: add a browser-free named check');
+ box.git(box.web, 'merge', '-q', '--ff-only', 'main');
+ mkdirSync(box.env.PULLBOARD_MACHINE_HOME, { recursive: true });
+ writeFileSync(join(box.env.PULLBOARD_MACHINE_HOME, 'settings.json'), JSON.stringify({ gateSlots: 1, gate: { browserFreeChecks: true } }));
+ assert.equal(box.run(box.repo, 'add', 'web', 'Timed check', '--criterion', 'the check runs', '--check', 'node bin/run-tests.js test/quick.test.js').code, 0);
+ assert.equal(box.run(box.web, 'claim', '1').code, 0);
+ // A stand-in holds the only slot for HOLD_MS, then lets the check in.
+ const HOLD_MS = 3000; // budget: long enough that the wait cannot be confused with the 200 ms test.
+ const holder = spawn(process.execPath, ['--input-type=module', '-e', `import { takeResource } from ${JSON.stringify(resolve(import.meta.dirname, '../src/resources.js'))};
+const lease = await takeResource({ name: 'gate', capacity: 1, scope: 'machine', root: ${JSON.stringify(box.repo)}, agent: 'receipt-stand-in' });
+console.log('ready'); setTimeout(() => { lease.release(); process.exit(0); }, ${HOLD_MS});`], { cwd: box.repo, env: box.env, stdio: ['ignore', 'pipe', 'inherit'] });
+ t.after(() => holder.kill());
+ await new Promise(ready => holder.stdout.once('data', ready));
+ const checked = box.run(box.web, 'check', '1', '--yes', '--json');
+ assert.equal(checked.code, 0, checked.out + checked.err);
+ const receipt = JSON.parse(checked.out).result?.receipt ?? JSON.parse(checked.out).receipt;
+ assert.ok(receipt, checked.out);
+ assert.ok(receipt.waitMs >= HOLD_MS - 1000, `the wait covers the stand-in's hold: ${JSON.stringify(receipt)}`);
+ assert.ok(receipt.runMs >= 150 && receipt.runMs < HOLD_MS - 1000, `the run time covers only the test: ${JSON.stringify(receipt)}`);
+ for (const field of ['admissionMs', 'setupMs', 'evidenceMs']) assert.ok(Number.isFinite(receipt[field]) && receipt[field] >= 0, field);
+ assert.deepEqual(receipt.slot, { kind: 'ordinary', reason: 'it launches no browser' }, 'the slot kind and why');
+ const stats = box.run(box.repo, 'stats');
+ assert.match(stats.out, /gate waits, last day:\n {2}check: 1 run; wait median \d+\.\d{2}s, slowest \d+\.\d{2}s; run median \d+\.\d{2}s/u, stats.out);
+});