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(land): drain timed commands after a spool write fails [E27]

Corey Olson0022d908353c
diff --git a/src/gate.js b/src/gate.js
index cf6497e0..83c179ac 100644
--- a/src/gate.js
+++ b/src/gate.js
@@ -286,6 +286,7 @@ export function runShell(root, command, { pipefail = false, env = {}, stages = f
const timed = timeoutMs ? spawnSync(process.execPath, [fileURLToPath(new URL('./timed-shell-worker.js', import.meta.url))], { ...options, shell: false, stdio: ['pipe', 'pipe', 'pipe'], input: JSON.stringify({ command: script, timeoutMs, outputFile }) }) : null;
if (timed && (timed.status !== 0 || timed.error)) throw new Refused('LAND_TIMEOUT_CUSTODY', 'the timed gate worker did not prove cleanup; inspect its owned processes before landing again');
const result = timed ? { ...JSON.parse(timed.stdout || '{}'), stdout: '', stderr: timed.stderr } : spawnSync(script, options);
+ if (timed && result.error) throw new Refused('LAND_GATE_OUTPUT', `the timed gate stopped and drained after its output failed (${result.error}); inspect free disk space and ${timedDirectory} before landing again`);
if (timed) result.stdout = readFileSync(outputFile, 'utf8') + (result.timedOut ? `\n[LAND_GATE_TIMEOUT] landing gate exceeded ${timeoutMs}ms; its owned processes are stopped\n` : '');
if (timedDirectory) rmSync(timedDirectory, { recursive: true, force: true });
if (result.timedOut || result.overflow || result.error) result.status = 1;
diff --git a/src/timed-shell-worker.js b/src/timed-shell-worker.js
index 2b404d73..697c0065 100644
--- a/src/timed-shell-worker.js
+++ b/src/timed-shell-worker.js
@@ -1,12 +1,20 @@
/** Run a bounded shell under identity-checked process custody before returning its result [E27]. */
import { spawn } from 'node:child_process';
-import { appendFileSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
+import {
+ appendFileSync,
+ mkdtempSync,
+ readFileSync,
+ rmSync,
+ writeFileSync,
+} from 'node:fs';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
import { createDescendantTracker } from './runner-custody.js';
const request = JSON.parse(readFileSync(0, 'utf8'));
if (!Number.isSafeInteger(request.timeoutMs) || request.timeoutMs < 1 || request.timeoutMs > 2_147_483_647) throw new Error('invalid shell timeout');
+// A spool that cannot be created must refuse before there is any command to stop.
+writeFileSync(request.outputFile, '', { mode: 0o600, flag: 'wx' });
const directory = mkdtempSync(join(tmpdir(), 'pullboard-timed-shell-'));
const tracker = createDescendantTracker(directory);
const env = { ...process.env, NODE_OPTIONS: [process.env.NODE_OPTIONS, tracker.nodeOptions].filter(Boolean).join(' '), PULLBOARD_RUNNER_PRELOAD: tracker.nodeOptions };
@@ -18,7 +26,6 @@ let overflow = false;
let error = null;
let bytes = 0;
let stopping;
-writeFileSync(request.outputFile, '', { mode: 0o600, flag: 'wx' });
const closed = new Promise(resolveClose => {
child.once('error', cause => { error = cause.message; resolveClose({ status: null, signal: null }); });
child.once('close', (status, signal) => resolveClose({ status, signal }));
@@ -47,7 +54,10 @@ function stop() {
function capture(chunk) {
bytes += chunk.length;
if (bytes > 2 ** 30) { overflow = true; void stop(); }
- else appendFileSync(request.outputFile, chunk);
+ else if (!error) {
+ try { appendFileSync(request.outputFile, chunk); }
+ catch (cause) { error = cause.code ?? 'TIMED_OUTPUT_WRITE'; void stop(); }
+ }
}
child.stdout.on('data', capture);
child.stderr.on('data', capture);