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(runner): output after a lost transport never strands the lease [C7]
Corey Olson39ce75c0df7c
diff --git a/src/runner-worker.js b/src/runner-worker.jsindex 3403b74f..4d0786ee 100644--- a/src/runner-worker.js+++ b/src/runner-worker.js@@ -50,6 +50,9 @@ let transportLost = false;let transportDrain = null;let signalCustodyInstalled = false;let transportDrop = () => {};+let markTransportGone;+// Settles when the transport is lost, so a write waiting on a dead stdout stops waiting (#888).+const transportGone = new Promise(resolveGone => { markTransportGone = resolveGone; });let heartbeatTimer = null;let workerId = 'starting';let rejectPendingFrame = null;@@ -766,6 +769,7 @@ function installSignalCustody() {const disconnected = () => {if (transportLost) return;transportLost = true;+ markTransportGone();beginCleanup();rejectPendingFrame?.(new Error('runner transport was lost'));clearInterval(heartbeatTimer);@@ -1070,7 +1074,10 @@ function outputSink() {const write = part => {const bytes = Buffer.isBuffer(part) ? part : Buffer.from(part);hash.update(bytes);- if (!process.stdout.write(bytes)) return once(process.stdout, 'drain');+ // A lost transport never drains. Discard instead of waiting: a paused command pipe never closes, its group never+ // finishes draining, and with only unref'd timers left the worker exits before releasing its lease (#888).+ if (transportLost || process.stdout.destroyed) return Promise.resolve();+ if (!process.stdout.write(bytes)) return Promise.race([once(process.stdout, 'drain'), transportGone]);return Promise.resolve();};return { hash, write, get pipeFailed() { return pipeFailed; }, set pipeFailed(value) { pipeFailed = value; }, wallStart };diff --git a/test/runner-parent-death-fixture.js b/test/runner-parent-death-fixture.jsindex 6133bf81..c58f1fe2 100644--- a/test/runner-parent-death-fixture.js+++ b/test/runner-parent-death-fixture.js@@ -8,8 +8,12 @@ import { takeResource } from '../src/resources.js';import { runFixtureChild } from './fixture-child.js';import { readRemoteGateHolders, waitForCondition } from './runner-fixture-state.js';-/** Keep the original custody assertions identical in ordinary and forced database ordering cases. */-export async function parentDeathDrainFixture(t, tools, { holdRelease = false } = {}) {+/**+ * Keep the original custody assertions identical in ordinary and forced ordering cases: `holdRelease` forces a real+ * release write conflict, and `chatty` makes the command keep writing output, so some always arrives after the+ * transport drops (#888: a forwarded write then waited forever for a drain from a destroyed stdout).+ */+export async function parentDeathDrainFixture(t, tools, { holdRelease = false, chatty = false } = {}) {const { cli, git, installSshStandIn, observe, startQueueController, waitForMarker, processIsAlive, shellQuote, HOST } = tools;const dir = realpathSync(mkdtempSync(join(tmpdir(), 'pullboard-runner-parent-death-')));t.after(() => rmSync(dir, { recursive: true, force: true }));@@ -29,6 +33,20 @@ export async function parentDeathDrainFixture(t, tools, { holdRelease = false }const childGone = join(dir, 'detached-child-gone');const workerLog = join(dir, 'worker-stderr.log');let releaseLock;+ /** The worker's own account of a stalled release: its runner status lines and any cleanup files in its private job (#888). */+ function workerCleanupReport() {+ const lines = existsSync(workerLog) ? readFileSync(workerLog, 'utf8').split('\n')+ .filter(line => /^PULLBOARD_RUNNER_(?!HEARTBEAT)[A-Z_]+ /u.test(line)).slice(-20) : [];+ const jobs = join(remoteHome, '.pullboard-runner', 'jobs');+ const files = {};+ for (const job of existsSync(jobs) ? readdirSync(jobs) : []) {+ for (const name of ['cleanup-timeout.json', 'release-pending.json']) {+ const file = join(jobs, job, name);+ if (existsSync(file)) files[job + '/' + name] = readFileSync(file, 'utf8').slice(0, 2_000);+ }+ }+ return { lines, files };+ }/** Release only this fixture's explicit write reservation. */function unlockRelease() {if (!releaseLock) return;@@ -55,7 +73,7 @@ const child = spawn(process.execPath, [require.resolve('./remote-detached-child.detached: true, stdio: 'ignore', env: process.env,});child.unref();-setInterval(() => {}, 1_000);+${chatty ? "setInterval(() => process.stdout.write('launcher output\\n'), 20);" : 'setInterval(() => {}, 1_000);'}`);writeFileSync(join(repo, 'remote-detached-child.js'), `const { existsSync, writeFileSync } = require('node:fs');const [ready, pidFile, term, release, gone] = process.argv.slice(2);@@ -153,7 +171,10 @@ setInterval(() => {}, 1_000);({ pid, agent, browser, item, kind, alive: processIsAlive(pid) })) };return holders.length === 0;}, 'the remote physical gate holder is released after child exit',- { signal: t.signal, state: () => lastReleaseState, onTimeout: message => t.diagnostic(message) });+ { signal: t.signal, state: () => lastReleaseState, onTimeout: message => {+ t.diagnostic(message);+ t.diagnostic('worker cleanup report ' + JSON.stringify(workerCleanupReport()));+ } });const controller = await remoteRun.closed;remoteRun = null;assert.equal(controller.signal, 'SIGTERM', 'the owned API controller alone received SIGTERM');diff --git a/test/runners.test.js b/test/runners.test.jsindex adc1b831..5ff99806 100644--- a/test/runners.test.js+++ b/test/runners.test.js@@ -1667,11 +1667,13 @@ syncBuiltinESMExports();\n`);const parentDeathTools = { cli, git, installSshStandIn, observe, startQueueController, waitForMarker, processIsAlive, shellQuote, HOST };test('a queued run executes on a registered runner and its result comes back [C7] (parent death drains a detached worker descendant before releasing its lease)',- { timeout: 90_000, skip: '#888: skipped for the 0.9.1 release (the person, 19 Oct); #888 fixes the remote drain and removes this skip' }, t => parentDeathDrainFixture(t, parentDeathTools)); // budget: fixture ceiling covers declared30-second remote cleanup plus startup, transport and final cleanup.+ { timeout: 90_000 }, t => parentDeathDrainFixture(t, parentDeathTools)); // budget: fixture ceiling covers declared30-second remote cleanup plus startup, transport and final cleanup.test('parent death retries a failed remote holder deletion after the real database writer releases [C7]',{ timeout: 90_000 }, t => parentDeathDrainFixture(t, parentDeathTools, { holdRelease: true })); // budget: same fixture deadline includes the real10-second SQLite busy attempt and release retry.+test('a queued run executes on a registered runner and its result comes back [C7] (parent death drains its worker while the command keeps writing output)',+ { timeout: 90_000 }, t => parentDeathDrainFixture(t, parentDeathTools, { chatty: true })); // budget: same fixture ceiling as the ordinary parent-death case.test('a queued run executes on a registered runner and its result comes back [C7] (unverified cleanup times out as a named red result)', { timeout: 90_000 }, async (t) => { // budget: bounded 30-second remote cleanup timeout plus startup, transport and fixture cleanup ceiling.const dir = realpathSync(mkdtempSync(join(tmpdir(), 'pullboard-runner-cleanup-timeout-')));