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): share runner retry status [C7]

Corey Olson42df48938488
diff --git a/src/resources.js b/src/resources.js
index e7687a1f..1c24f9e4 100644
--- a/src/resources.js
+++ b/src/resources.js
@@ -476,12 +476,7 @@ function gateAdmission(db, ticket, capacity, shortCapacity, runners, runnersFirs
browsers: remoteHolders.filter(holder => holder.browser === 1).length,
}];
}));
- // A runner whose transport dropped rejoins the pool after RUNNER_RETRY_MS, so one network blip cannot send every
- // later run to this machine; another drop quarantines it again. Unverified cleanup stays out until re-registered.
- const unavailable = new Set([
- ...db.prepare("SELECT host, since, detail FROM runner_unavailable").all()
- .filter(row => row.detail !== 'TRANSPORT_LOST' || !(now - Date.parse(row.since) >= RUNNER_RETRY_MS)).map(row => row.host),
- ...db.prepare('SELECT host FROM runner_draining').all().map(row => row.host)]);
+ const unavailable = unavailableRunnerHosts(db, now);
/** Keep an already holding process from taking another slot ahead of a different landing. */
const blockedByLanding = waiter => holders.some(holder => holder.pid === waiter.pid)
&& waiters.some(other => other.landing === 1 && other.pid !== waiter.pid);
@@ -559,6 +554,20 @@ function gateAdmission(db, ticket, capacity, shortCapacity, runners, runnersFirs
return null;
}
+/** A transport drop expires after the retry window; cleanup failures and unreadable timestamps stay blocked. */
+function runnerUnavailable(entry, now) {
+ return Boolean(entry && (entry.detail !== 'TRANSPORT_LOST' || !(now - Date.parse(entry.since) >= RUNNER_RETRY_MS)));
+}
+
+/** Use the same current transport and draining exclusions for admission and local-memory status. */
+function unavailableRunnerHosts(db, now) {
+ return new Set([
+ ...db.prepare('SELECT host, since, detail FROM runner_unavailable').all()
+ .filter(row => runnerUnavailable(row, now)).map(row => row.host),
+ ...db.prepare('SELECT host FROM runner_draining').all().map(row => row.host),
+ ]);
+}
+
/** Capability/availability permits a remote executor even when every compatible slot is currently busy. */
function runnerCompatible(db, runner, waiter, unavailable) {
const observed = db.prepare('SELECT gui FROM runner_gui WHERE host = ?').get(runner.host);
@@ -580,7 +589,8 @@ export function runnerResourceStatus(runners) {
const holders = db.prepare('SELECT agent, repo, since, browser, item, kind, runner, timing FROM holder WHERE name = ? ORDER BY since, token')
.all(runnerResourceName(runner.host));
if (runner.draining && !holders.length) return [];
- const unavailable = db.prepare('SELECT since, detail FROM runner_unavailable WHERE host = ?').get(runner.host);
+ const recorded = db.prepare('SELECT since, detail FROM runner_unavailable WHERE host = ?').get(runner.host);
+ const unavailable = runnerUnavailable(recorded, Date.now()) ? recorded : null;
const observed = db.prepare('SELECT gui, observed_at FROM runner_gui WHERE host = ?').get(runner.host);
return [{ ...runner, gui: runner.gui ?? null, ...(observed ? { gui: observed.gui === null ? null : observed.gui === 1, guiObservedAt: observed.observed_at } : {}), inUse: holders.length, browserInUse: holders.filter(holder => holder.browser === 1).length,
unavailable: Boolean(unavailable), ...(unavailable ? { unavailableSince: unavailable.since, unavailableReason: unavailable.detail } : {}), holders }];
@@ -926,7 +936,7 @@ export async function takeResource(options) {
}
// 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 unavailable = new Set(db.prepare('SELECT host FROM runner_unavailable UNION SELECT host FROM runner_draining').all().map(row => row.host));
+ const unavailable = unavailableRunnerHosts(db, now);
const memoryHeld = Boolean(memory?.held && (name !== 'gate' || waiter.remote !== 1
|| !runners.some(runner => runnerCompatible(db, runner, waiter, unavailable))));
db.prepare('UPDATE waiter SET memory_held = ? WHERE token = ?').run(Number(memoryHeld), token);
diff --git a/test/runner-memory-fixture.js b/test/runner-memory-fixture.js
index f6164c60..1c15a067 100644
--- a/test/runner-memory-fixture.js
+++ b/test/runner-memory-fixture.js
@@ -47,14 +47,15 @@ export async function assertRunnerMemoryAdmission() {
'const root=process.cwd(); const output={};',
'/** Keep the refusal path bounded: release only the private simulated pressure after observing it. */',
'async function exercise(remote, agent, releaseOccupied){',
- 'let recovered=false; const held=[]; let status=null; let waited=0;',
+ 'let recovered=false; const held=[]; let status=null; let runnerStatus=null; let waited=0;',
'const readMemory=async()=>({checked:true,platform:process.platform,pressure:recovered?"normal":"critical",',
'availableBytes:(recovered?8192:64)*1024**2,totalBytes:16*1024**3,processes:[]});',
'const result=await withGateSlot(root,lease=>runProfiledShellAsync(root,"node memory-probe.cjs",{gateLease:lease,waitMs:lease.waitMs}),',
'{remote,agent,kind:"focused",readMemory,onWait(state){waited+=1;',
`status=JSON.parse(execFileSync(process.execPath,[${JSON.stringify(cli)},"status","--json"],{cwd:root,encoding:"utf8"}));`,
+ `runnerStatus=JSON.parse(execFileSync(process.execPath,[${JSON.stringify(cli)},"resources","--json"],{cwd:root,encoding:"utf8"})).runners.find(row=>row.host===${JSON.stringify(HOST)});`,
'if(state.memory?.held){held.push(state.memory);recovered=true;} releaseOccupied?.();}});',
- 'return {green:result.isGreen,runner:result.executionRunner,output:result.output,held,status,waited};}',
+ 'return {green:result.isGreen,runner:result.executionRunner,output:result.output,held,status,runnerStatus,waited};}',
'let markOccupied,releaseOccupied;',
'const ready=new Promise(resolve=>{markOccupied=resolve;});',
'const release=new Promise(resolve=>{releaseOccupied=resolve;});',
@@ -76,6 +77,7 @@ export async function assertRunnerMemoryAdmission() {
assert.equal(result.remote.runner, HOST, 'the actual stand-in worker executed this run');
assert.match(result.remote.output, /REAL_RUNNER_MEMORY_PROBE/u);
assert.deepEqual(result.remote.held, [], 'a runner-bound run is never held for local memory');
+ assert.equal(result.remote.runnerStatus.unavailable, false, 'public resources agrees the expired transport hold is retry-eligible');
assert.ok(result.remote.waited > 0, 'the compatible runner was genuinely occupied before the real dispatch');
assert.ok(!result.remote.status.memoryHeld.some(entry => entry.agent === 'remote-memory-control'), 'a capacity-blocked remote run is not listed as memory-held');
assert.equal(result.local.green, true, result.local.output);