Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions commands/recover.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const fs = require('node:fs');
const path = require('node:path');
const { spawnSync } = require('node:child_process');
const { reasonClass, HUMAN_BLOCKING_REASONS } = require('../lib/self-drive');
const { reasonClass, isHumanBlockingReason } = require('../lib/self-drive');
const { missionLockRecords } = require('../lib/loop-doctor');
const {
loadMissionMap,
Expand Down Expand Up @@ -83,15 +83,15 @@ function classifyRecovery(value) {
reason,
happened: entry.happened,
apply: entry.apply,
human_blocking: HUMAN_BLOCKING_REASONS.has(reason),
human_blocking: isHumanBlockingReason(reason),
};
}
return {
catalog_entry: 'unknown',
reason,
happened: `the mission stopped for "${reason}"`,
apply: null,
human_blocking: HUMAN_BLOCKING_REASONS.has(reason),
human_blocking: isHumanBlockingReason(reason),
};
}

Expand Down
11 changes: 9 additions & 2 deletions lib/self-drive.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ const { openHumanAsks } = require('./mission-human-asks');
const HUMAN_BLOCKING_REASONS = new Set(['auth-required', 'model-unavailable', 'rate-limit-exceeded-wall']);
const OPEN_TASK_STATUSES = new Set(['open', 'claimed', 'review']);

// A mission held in a protected lane (security, money, deploys, a diff that
// needs review) waits for a person by design. Filing an agent task to "get it
// moving again" asks an agent to undo a hold only a human may lift.
function isHumanBlockingReason(reason) {
return HUMAN_BLOCKING_REASONS.has(reason) || /^protected-lane-/.test(String(reason || ''));
}

const SWARLO_HUB = process.env.SWARLO_HUB_URL || process.env.SWARLO_HUB || 'http://localhost:8090';
const SWARLO_HUB_ID = process.env.SWARLO_HUB_ID || 'atris';
const SWARLO_FLEET_TIMEOUT_MS = 3000;
Expand Down Expand Up @@ -210,7 +217,7 @@ function projectTasks(taskDb, db, workspaceRoot) {
function handleMissionBlocker({ mission, stopReason, workspaceRoot, appendEvent }, injected = {}) {
if (!mission || !mission.id) return { taskId: null, dispatched: false, engine: null, reason: 'missing mission' };
const blockerClass = reasonClass(stopReason || mission.stop_reason || mission.last_tick_reason);
if (HUMAN_BLOCKING_REASONS.has(blockerClass) || openHumanAsks(mission.human_asks).length) {
if (isHumanBlockingReason(blockerClass) || openHumanAsks(mission.human_asks).length) {
return { taskId: null, dispatched: false, engine: null, reason: 'human-blocking' };
}
if (['ready', 'complete', 'stopped'].includes(String(mission.status || '').toLowerCase())) {
Expand Down Expand Up @@ -371,4 +378,4 @@ function handleMissionBlocker({ mission, stopReason, workspaceRoot, appendEvent
}
}

module.exports = { handleMissionBlocker, reasonClass, HUMAN_BLOCKING_REASONS, loadSwarloApiKey };
module.exports = { handleMissionBlocker, reasonClass, HUMAN_BLOCKING_REASONS, isHumanBlockingReason, loadSwarloApiKey };
36 changes: 36 additions & 0 deletions test/self-drive--protected-lane-hold.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
'use strict';
require('./helpers/clean-temp');

const test = require('node:test');
const assert = require('node:assert/strict');

const { handleMissionBlocker, isHumanBlockingReason } = require('../lib/self-drive');
const { classifyRecovery } = require('../commands/recover');

// A mission paused in a protected lane waits for a person. Self-drive used to
// file "get X moving again: protected lane security" and hand it to an agent.
test('a protected-lane pause files no blocker task and dispatches nothing', () => {
for (const reason of ['protected-lane-security', 'protected-lane-billing', 'protected-lane-declared', 'protected-lane-review']) {
const result = handleMissionBlocker({
mission: { id: 'mission-replay', objective: 'As Replay Lead, find the saved earlier replay', status: 'paused' },
stopReason: reason,
workspaceRoot: process.cwd(),
}, {
taskDb: {
open: () => { throw new Error('task db must not be opened for a human hold'); },
},
resolveEngineForRole: () => { throw new Error('no engine may be picked'); },
});
assert.deepEqual(result, { taskId: null, dispatched: false, engine: null, reason: 'human-blocking' }, reason);
}
});

test('protected-lane reasons read as human-blocking everywhere, other reasons do not', () => {
assert.equal(isHumanBlockingReason('protected-lane-security'), true);
assert.equal(isHumanBlockingReason('auth-required'), true);
assert.equal(isHumanBlockingReason('repeated-error:runner-failed'), false);
assert.equal(isHumanBlockingReason('lane-security'), false);
assert.equal(isHumanBlockingReason(undefined), false);
assert.equal(classifyRecovery('protected-lane-security').human_blocking, true);
assert.equal(classifyRecovery('protected-lane-security').apply, null);
});