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.
JavaScript agentic-codingai-agentsai-governanceautonomous-agentsclaude-codeclicode-reviewcodexcoding-agentsdeveloper-toolsgit-hooksllmlocal-firstmulti-agentsoftware-factoryspec-driven-developmentverificationvibe-coding
fix(check): cap captured output without limiting files [V18,V2]
Corey Olsone1c2618c1522
diff --git a/docs/lifecycle.md b/docs/lifecycle.mdindex 0e9d527c..73b95609 100644--- a/docs/lifecycle.md+++ b/docs/lifecycle.md@@ -8,6 +8,8 @@ An item starts open. Its final states, verified and withdrawn, cannot be left, aThe coordinator may set `check.install` and `check.timeout` in committed `pullboard.json`; the defaults are no install command and `5m`. Accept runs the configured install and the frozen item check in a private clone, under one timeout budget. It reuses the verifier’s npm cache when available. Install commands that need network downloads conflict with P2 (offline); configure an offline install or make its needed packages available in the cache.+Private commands drain their output through pipes, retaining a bounded 8 MiB capture of its beginning and end. Output beyond that cap does not fail a successful command, and dependency files and build artifacts have no capture-size limit. A timeout kills the command's process group. An unverified check names how to restore the environment and retry; a failing check names rejection or builder rework as the next step.+```mermaidstateDiagram-v2[*] --> opendiff --git a/src/cli.js b/src/cli.jsindex 3cd178db..d4bfdf44 100644--- a/src/cli.js+++ b/src/cli.js@@ -1477,8 +1477,8 @@ async function verifyHere(ctx, id, { second, values }) {if (decision === 'ACCEPT') {if (digest !== item.item_frozen_digest) throw new Refused('CRITERIA_CHANGED', 'the criterion changed; ask the coordinator to refreeze this item before checking it');const check = checkAtCommit(root, item);- if (check.state === 'unverified') throw new Refused('CHECK_UNVERIFIED', `the frozen ${check.stage} could not be verified at the submitted commit; output digest:\n${check.report.replace(/^/gm, ' ')}`);- if (check.state === 'red') throw new Refused('CHECK_RED', `the frozen item check is red at the submitted commit; check.install may be needed for dependencies; output digest:\n${check.report.replace(/^/gm, ' ')}`);+ if (check.state === 'unverified') throw new Refused('CHECK_UNVERIFIED', `the frozen ${check.stage} could not be verified at the submitted commit; restore the install or check environment, then retry verification; output digest:\n${check.report.replace(/^/gm, ' ')}`);+ if (check.state === 'red') throw new Refused('CHECK_RED', `the frozen item check is red at the submitted commit; check.install may be needed for dependencies; reject with the failing behavior or ask the builder to fix and resubmit; output digest:\n${check.report.replace(/^/gm, ' ')}`);const receipt = store.events(board, { itemId: id }).filter(event => event.event_kind === 'submit').map(event => JSON.parse(event.event_detail)).find(event => event.commit === commit);submissionPaths(root, item, commit, { mainCommit: receipt?.policyCommit, dependencies: dependencySnapshots(board.db, item) });}diff --git a/src/json.js b/src/json.jsindex a61589e7..04e9fd60 100644--- a/src/json.js+++ b/src/json.js@@ -92,7 +92,7 @@ export const JSON_SHAPES = {/** Extract a concrete repair from existing refusals, retaining their original guidance. */function nextStep(message) {- const match = /(?:; |\. |: )((?:run|install|upgrade|fix|restore|commit|check out|set|give|use|ask your coordinator|answer from the main checkout|the coordinator|to keep looking|never work around)\b[\s\S]*)/i.exec(message);+ const match = /(?:; |\. |: )((?:run|install|upgrade|fix|restore|commit|check out|set|give|use|reject|ask your coordinator|answer from the main checkout|the coordinator|to keep looking|never work around)\b[\s\S]*)/i.exec(message);return match?.[1] ?? 'Run pullboard help, correct the reported problem, and retry the command.';}diff --git a/src/private-check-worker.js b/src/private-check-worker.jsnew file mode 100644index 00000000..990826cd--- /dev/null+++ b/src/private-check-worker.js@@ -0,0 +1,44 @@+/** Collect private command output through pipes; dependency files are never size-limited [V18,V2]. */+import { spawn } from 'node:child_process';+import { readFileSync, writeFileSync } from 'node:fs';++const { command, timeout, pidFile } = JSON.parse(readFileSync(0, 'utf8'));+const LIMIT = 8 * 1024 * 1024;+const HALF = LIMIT / 2;+let head = Buffer.alloc(0);+let tail = Buffer.alloc(0);+let bytes = 0;+let timedOut = false;+let error = null;++/** Drain every byte while retaining only the beginning and end of the combined output. */+function capture(chunk) {+ bytes += chunk.length;+ const take = Math.min(chunk.length, HALF - head.length);+ if (take) head = Buffer.concat([head, chunk.subarray(0, take)]);+ const rest = chunk.subarray(take);+ if (rest.length) tail = Buffer.concat([tail, rest]).subarray(-HALF);+}++const child = spawn('sh', ['-c', `(\n${command}\n) 2>&1`], { detached: true, stdio: ['ignore', 'pipe', 'pipe'] });+if (child.pid) writeFileSync(pidFile, String(child.pid), { mode: 0o600 });++/** Stop the command's entire process group, including background descendants that retain pipes. */+function stop() {+ if (child.pid) {+ try { process.kill(-child.pid, 'SIGKILL'); } catch { /* The group has already exited. */ }+ }+}++const timer = setTimeout(() => { timedOut = true; stop(); }, timeout);+child.stdout.on('data', capture);+child.stderr.on('data', capture);+child.once('error', cause => { error = { code: cause.code ?? 'CHECK_RUNNER' }; });+child.once('exit', stop);+child.once('close', (status, signal) => {+ clearTimeout(timer);+ stop();+ const marker = bytes > LIMIT ? '\n[output capped at 8 MiB; middle omitted]\n' : '';+ const output = head.toString('utf8') + marker + tail.toString('utf8');+ process.stdout.write(JSON.stringify({ status, signal, error: timedOut ? { code: 'ETIMEDOUT' } : error, output }));+});diff --git a/src/trusted-policy.js b/src/trusted-policy.jsindex 0e1a1f5d..043f1aa9 100644--- a/src/trusted-policy.js+++ b/src/trusted-policy.js@@ -1,9 +1,10 @@/** Coordinator policy and immutable submission checks cannot come from a builder's candidate [V4,V16,L3,M3]. */import { spawnSync } from 'node:child_process';import { digestOf } from './gate.js';-import { closeSync, mkdtempSync, mkdirSync, openSync, readFileSync, rmSync, statSync } from 'node:fs';+import { existsSync, mkdtempSync, mkdirSync, readFileSync, rmSync } from 'node:fs';import { tmpdir } from 'node:os';import { join } from 'node:path';+import { fileURLToPath } from 'node:url';import { configFromSource } from './config.js';import { outOfLane } from './lanes.js';import { Refused } from './refused.js';@@ -141,18 +142,25 @@ export function checkAtCommit(root, item) {/** Run one shell command in a bounded private process group and capture its combined output. */function runPrivateCommand(root, env, command, timeout, logPath) {- const descriptor = openSync(logPath, 'w', 0o600);+ const pidFile = logPath + '.pid';try {- const run = spawnSync('sh', ['-c', `ulimit -f 16384\n(\n${command}\n)`], {- cwd: root, env, detached: true, stdio: ['ignore', descriptor, descriptor], timeout, killSignal: 'SIGKILL',+ // The worker drains pipes even after its capture cap, so noisy successful commands still pass.+ const run = spawnSync(process.execPath, [fileURLToPath(new URL('./private-check-worker.js', import.meta.url))], {+ cwd: root, env, input: JSON.stringify({ command, timeout, pidFile }), encoding: 'utf8',+ timeout: timeout + 1000, killSignal: 'SIGKILL', maxBuffer: 64 * 1024 * 1024,});- if (run.pid) {- try { process.kill(-run.pid, 'SIGKILL'); } catch { /* The process group has already exited. */ }+ if (run.error) return { status: null, error: { code: run.error.code }, output: '' };+ try { return JSON.parse(run.stdout); }+ catch { return { status: null, error: { code: 'CHECK_RUNNER' }, output: '' }; }+ } finally {+ if (existsSync(pidFile)) {+ const pid = Number(readFileSync(pidFile, 'utf8'));+ if (Number.isSafeInteger(pid) && pid > 0 && pid !== process.pid) {+ try { process.kill(-pid, 'SIGKILL'); } catch { /* The private command group has already exited. */ }+ }+ rmSync(pidFile, { force: true });}- const output = readFileSync(logPath, 'utf8');- const capped = statSync(logPath).size >= 8 * 1024 * 1024 ? `${output}\n[output capped at 8 MiB]` : output;- return { ...run, output: capped };- } finally { closeSync(descriptor); }+ }}/** Summarize both private command outputs for verifier and doctor diagnostics. */diff --git a/test/e2e.test.js b/test/e2e.test.jsindex bcd6958d..f304b2ec 100644--- a/test/e2e.test.js+++ b/test/e2e.test.js@@ -1817,6 +1817,7 @@ test('accept without check.install keeps CHECK_RED and names the missing settingassert.match(error.message, /check\.install/);assert.match(error.message, /output digest/);assert.match(error.message, /check-failed/);+ assert.match(error.next, /^reject with the failing behavior or ask the builder to fix and resubmit/);});test('accept reports failed install as CHECK_UNVERIFIED with an output digest [V18,V2]', () => {@@ -1828,6 +1829,7 @@ test('accept reports failed install as CHECK_UNVERIFIED with an output digest [Vassert.match(error.message, /install failed/);assert.match(error.message, /output digest/);assert.match(error.message, /install-failed/);+ assert.match(error.next, /^restore the install or check environment, then retry verification/);});test('private check digest keeps install and noisy check output in separate sections [V18,V2]', () => {@@ -1845,6 +1847,40 @@ test('private check digest keeps install and noisy check output in separate sectassert.match(proof.report, /check output:[\s\S]*check-failed/);});+test('accept runs a successful frozen check that writes a file larger than the log cap [V18,V2]', () => {+ const box = privateCheckSubmission({ check: 'mkdir -p web/.deps; node -e \'require("node:fs").writeFileSync("web/.deps/check.bin", Buffer.alloc(20 * 1024 * 1024)); console.log("large-check-file-written")\'' });+ const accepted = box.run(box.review, 'verify', '1', 'accept', '--note', 'the check wrote its real 20 MiB artifact', '--json');+ assert.equal(accepted.code, 0, accepted.out);+ assert.equal(JSON.parse(accepted.out).decision, 'ACCEPT');+});++test('accept installs a real dependency file larger than the log cap before checking [V18,V2]', () => {+ const box = privateCheckSubmission({+ install: 'mkdir -p web/.deps; node -e \'require("node:fs").writeFileSync("web/.deps/dependency.bin", Buffer.alloc(20 * 1024 * 1024)); console.log("large-install-file-written")\'',+ check: 'node -e \'if (require("node:fs").statSync("web/.deps/dependency.bin").size !== 20 * 1024 * 1024) process.exit(1)\'',+ });+ const accepted = box.run(box.review, 'verify', '1', 'accept', '--note', 'the private install produced the complete 20 MiB dependency', '--json');+ assert.equal(accepted.code, 0, accepted.out);+ assert.equal(JSON.parse(accepted.out).decision, 'ACCEPT');+ const doctor = box.run(box.repo, 'doctor', '--json');+ assert.equal(doctor.code, 0, doctor.out);+});++test('a successful noisy check drains beyond the log cap and keeps bounded head and tail output [V18,V2]', () => {+ const box = privateCheckSubmission({ check: 'node -e \'process.stdout.write("BEGIN-MARKER\\n"); process.stdout.write(Buffer.alloc(20 * 1024 * 1024, 120)); process.stdout.write("\\nEND-MARKER\\n")\'' });+ const board = store.openBoard(join(box.repo, '.git/pullboard/board.sqlite'));+ let item;+ try { item = store.getItem(board, 1); } finally { store.closeBoard(board); }+ const proof = checkAtCommit(box.repo, item);+ assert.equal(proof.state, 'pass', proof.report);+ assert.ok(proof.output.length < 8 * 1024 * 1024 + 256, 'only a bounded capture reaches the caller');+ assert.match(proof.output, /BEGIN-MARKER/);+ assert.match(proof.output, /END-MARKER/);+ assert.match(proof.output, /output capped at 8 MiB; middle omitted/);+ const accepted = box.run(box.review, 'verify', '1', 'accept', '--note', 'a noisy successful check passes with bounded output', '--json');+ assert.equal(accepted.code, 0, accepted.out);+});+test('accept reports a frozen check timeout as CHECK_UNVERIFIED [V18,V2]', () => {const box = privateCheckSubmission({ timeout: '100ms', check: 'case "$PULLBOARD_HOME" in */pullboard-criterion-*/home/.pullboard) while :; do :; done;; *) exit 1;; esac' });const refused = box.run(box.review, 'verify', '1', 'accept', '--note', 'the frozen check exceeded its configured timeout', '--json');@@ -1853,6 +1889,19 @@ test('accept reports a frozen check timeout as CHECK_UNVERIFIED [V18,V2]', () =>assert.equal(error.code, 'CHECK_UNVERIFIED');assert.match(error.message, /check timed out/);assert.match(error.message, /output digest/);+ assert.match(error.next, /^restore the install or check environment, then retry verification/);+});++test('accept reports a frozen install timeout before running the check [V18,V2]', () => {+ const box = privateCheckSubmission({ timeout: '100ms', install: 'echo install-started; while :; do :; done', check: 'echo forbidden-check-ran' });+ const refused = box.run(box.review, 'verify', '1', 'accept', '--note', 'the install must finish within its frozen deadline', '--json');+ assert.equal(refused.code, 1);+ const error = JSON.parse(refused.out).error;+ assert.equal(error.code, 'CHECK_UNVERIFIED');+ assert.match(error.message, /install timed out/);+ assert.match(error.message, /install-started/);+ assert.doesNotMatch(error.message, /forbidden-check-ran/);+ assert.match(error.next, /^restore the install or check environment, then retry verification/);});test('private check timeout kills a TERM-resistant shell and its tracked child [V18,V2]', () => {