Files
strata/apps/host/tests/engine-progress.test.mjs
T
Niko1221 425bca7199 Agent watchdog: the engine's prompt-read progress counts as activity; local routes get a 60 min stream-idle timeout (#3623)
A local engine reading a long prompt sends the Harness nothing for minutes, so the 4 minute stall limit ended the turn mid-read. The host now hands the bridge the engine's /metrics progress (live.prompt_read, generated, slots); a moving mark keeps the turn alive for at most 30 minutes after the Harness last spoke. An engine that stops reporting still ends at the usual limit. API routes are unchanged.
2026-10-22 12:54:48 +02:00

24 lines
1.5 KiB
JavaScript

import test from 'node:test';
import assert from 'node:assert/strict';
import { engineProgressMark } from '../server/agent/engine-progress.mjs';
import { readFileSync } from 'node:fs';
test('the mark moves with the prompt read and with generation, and is null when the engine is idle or silent', () => {
const at = live => engineProgressMark({ metrics: { live } });
assert.equal(engineProgressMark(null), null);
assert.equal(engineProgressMark({ metrics: null }), null);
assert.equal(at({ state: 'idle' }), null);
assert.equal(at({ state: 'unloaded' }), null);
const a = at({ state: 'reading', prompt_read: 4096, prompt_total: 90000 });
const b = at({ state: 'reading', prompt_read: 8192, prompt_total: 90000 });
assert.notEqual(a, b);
assert.equal(a, at({ state: 'reading', prompt_read: 4096, prompt_total: 90000 }), 'no progress, same mark');
assert.notEqual(at({ state: 'generating', generated: 1 }), at({ state: 'generating', generated: 2 }));
assert.notEqual(at({ state: 'reading', slots: [{ state: 'reading', prompt_read: 1 }] }), at({ state: 'reading', slots: [{ state: 'reading', prompt_read: 2 }] }));
});
test('the host wires it in and the local profile lifts the 300 s stream-idle timer', () => {
assert.match(readFileSync(new URL('../server/index.mjs', import.meta.url), 'utf8'), /engineProgress: instanceId => engineProgressMark\(/);
assert.match(readFileSync(new URL('../server/agent/profile.mjs', import.meta.url), 'utf8'), /streamIdleTimeoutMs: 60 \* 60_000/);
});