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(core): retain CPU observation on native read failure [A6,H16]

Corey Olson9ded96606692
diff --git a/src/health-sentinel.js b/src/health-sentinel.js
index d8e39e7b..84748fa3 100644
--- a/src/health-sentinel.js
+++ b/src/health-sentinel.js
@@ -18,8 +18,9 @@ export function scanHealthSentinel(file, { root, config, now, cpu = agentCpuFind
db.exec('BEGIN');
const observedRevision = db.prepare('SELECT COALESCE(MAX(event_id), 0) AS revision FROM event').get().revision;
const report = healthReport({ db, root, config, now });
- report.stuck.push(...cpu(db));
const last = db.prepare("SELECT event_detail FROM event WHERE event_kind = 'health-scan' ORDER BY event_id DESC LIMIT 1").get();
+ const processes = cpu(db);
+ report.stuck.push(...(processes ?? (last ? JSON.parse(last.event_detail).active : []).filter(finding => finding.cause === 'AGENT_CPU')));
const before = (last ? JSON.parse(last.event_detail).active : []).map(healthFindingIdentity).sort();
const after = normalizedHealthFindings(report.stuck).map(healthFindingIdentity).sort();
db.exec('COMMIT');
diff --git a/src/sentinel-cpu.js b/src/sentinel-cpu.js
index d830d447..3d9a2d00 100644
--- a/src/sentinel-cpu.js
+++ b/src/sentinel-cpu.js
@@ -29,6 +29,10 @@ function canonical(path) {
/** Report only native cwd ownership revalidated against the same PID birth after the cwd observation. */
export function agentCpuFindings(db, { platform = process.platform, run = native, readLink = readlinkSync } = {}) {
if (!['darwin', 'linux'].includes(platform)) return [];
+ const agents = db.prepare('SELECT agent_id, agent_path FROM agent WHERE agent_id != ?').all('coordinator')
+ .map(agent => ({ ...agent, path: canonical(agent.agent_path) })).filter(agent => agent.path)
+ .sort((left, right) => right.path.length - left.path.length);
+ if (!agents.length) return [];
const format = ['pid=', 'time=', 'lstart=', 'comm='].flatMap(field => ['-o', field]);
let candidates, confirmed, directories = new Map();
try {
@@ -48,10 +52,7 @@ export function agentCpuFindings(db, { platform = process.platform, run = native
}
}
confirmed = new Set(rows(run('/bin/ps', ['-p', candidates.map(row => row.pid).join(','), ...format])).map(row => `${row.pid}:${row.since}`));
- } catch { return []; /* Unavailable native observations cannot prove process ownership or CPU use. */ }
- const agents = db.prepare('SELECT agent_id, agent_path FROM agent WHERE agent_id != ?').all('coordinator')
- .map(agent => ({ ...agent, path: canonical(agent.agent_path) })).filter(agent => agent.path)
- .sort((left, right) => right.path.length - left.path.length);
+ } catch { return null; /* Unavailable observations cannot establish that a previously seen process resolved. */ }
return candidates.flatMap(row => {
const cwd = directories.get(row.pid);
if (!cwd || !confirmed.has(`${row.pid}:${row.since}`)) return [];
diff --git a/test/sentinel-cpu.test.js b/test/sentinel-cpu.test.js
index d58c3b2d..d8a85069 100644
--- a/test/sentinel-cpu.test.js
+++ b/test/sentinel-cpu.test.js
@@ -19,10 +19,11 @@ test('the sentinel names an agent process past 20 CPU minutes once [A6,H16]', as
store.register(board, { lane: 'coordinator', path: root });
const seat = store.register(board, { lane: 'core', path: work });
t.after(() => { store.closeBoard(board); rmSync(directory, { recursive: true }); });
- let birth = 'Mon Oct 19 12:00:00 2026', cpu = '21:30.00', cwd = work, present = true;
+ let birth = 'Mon Oct 19 12:00:00 2026', cpu = '21:30.00', cwd = work, present = true, unavailable = false;
const calls = [];
const run = (command, args) => {
calls.push([command, args]);
+ if (unavailable) throw new Error('native observation unavailable');
if (command === '/bin/ps') return present ? ` 4321 ${cpu} ${birth} /usr/bin/git\n 4322 19:59.99 ${birth} /usr/bin/node\n` : '';
assert.equal(command, '/usr/sbin/lsof');
return `p4321\nn${cwd}\n`;
@@ -37,6 +38,8 @@ test('the sentinel names an agent process past 20 CPU minutes once [A6,H16]', as
assert.equal(notices().length, 1);
for (const value of ['4321', 'git', seat, '21.50 CPU minutes']) assert.ok(notices()[0].shout_text.includes(value), value);
assert.equal(notices()[0].shout_from, 'sentinel');
+ unavailable = true; scan(); unavailable = false;
+ assert.equal(store.allShouts(board).filter(row => row.shout_text.startsWith('Resolved:') && row.shout_text.includes('AGENT_CPU')).length, 0, 'an unavailable observation does not claim resolution');
cpu = '01:22:30'; scan(); scan();
assert.equal(notices().length, 1, 'increasing CPU time does not create another process episode');
present = false; scan(); present = true; scan();
@@ -49,6 +52,7 @@ test('the sentinel names an agent process past 20 CPU minutes once [A6,H16]', as
assert.equal(notices().length, 2, 'exactly twenty CPU minutes has not exceeded twenty minutes');
cpu = '1-00:00:01';
assert.equal(observe()[0].why.includes('1440.02 CPU minutes'), true, 'day-form CPU time is parsed');
+ assert.equal(agentCpuFindings(board.db, { platform: 'linux', run, readLink: path => { assert.equal(path, '/proc/4321/cwd'); return work; } })[0].cause, 'AGENT_CPU');
assert.ok(calls.some(([command, args]) => command === '/bin/ps' && args.includes('time=')));
assert.ok(calls.some(([command]) => command === '/usr/sbin/lsof'));
});