okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221Agent watchdog: the engine's prompt-read progress counts as activity; local routes get a 60 min stream-idle timeout (#3623)425bca719

main
3.4 KiB44 linesraw
1// A turn always ends: when the model goes silent the watchdog stops it with a plain message.
2import test from 'node:test';
3import assert from 'node:assert/strict';
4import { mkdtempSync, mkdirSync, rmSync } from 'node:fs';
5import { tmpdir } from 'node:os';
6import { join } from 'node:path';
7import { startScriptedWorker } from './helpers/scripted-worker.mjs';
8import { createAgentBridge } from '../server/agent/agent-bridge.mjs';
9import { resolveHarness } from '../server/agent/harness-runtime.mjs';
10const HARNESS = process.env.STRATA_HARNESS_DIR;
11const skip = !HARNESS || !resolveHarness({ env: process.env }).ok ? 'STRATA_HARNESS_DIR is not set to a built Harness' : false;
12
13test('a silent model ends the turn with a plain message, and the chat works again afterwards', { skip }, async (t) => {
14  const worker = await startScriptedWorker({});
15  const dir = mkdtempSync(join(tmpdir(), 'strata-wd-')); const ws = join(dir, 'ws'); mkdirSync(ws, { recursive: true });
16  const bridge = createAgentBridge({ dataDir: dir, localInstances: () => [{ id: 'i', label: 'S', baseUrl: worker.url, modelId: 'scripted-model', context: 32768, slots: 2 }], connections: () => [], env: process.env, startTimeoutMs: 90_000, stallMs: 2500, stallToolMs: 6000 });
17  t.after(async () => { await bridge.close(); await worker.close(); try { rmSync(dir, { recursive: true, force: true, maxRetries: 3 }); } catch { /* best effort */ } });
18  const out = [];
19  const t0 = Date.now();
20  await bridge.runTurn({ chatId: 'w1', message: 'SCRIPT:hang', workspacePath: ws, mode: 'bypass', onFrame: f => out.push(f) });
21  assert.ok(Date.now() - t0 < 30_000, 'it ended by itself');
22  const err = out.find(f => f.type === 'error');
23  assert.match(err.message, /stopped answering/); assert.match(err.message, /Send your message again/);
24  assert.equal(out.at(-1).type, 'error');
25  const again = [];
26  await bridge.runTurn({ chatId: 'w1', message: 'SCRIPT:echo fine', workspacePath: ws, mode: 'bypass', onFrame: f => again.push(f) });
27  assert.match(again.filter(f => f.type === 'delta').map(f => f.text).join(''), /fine/);
28});
29
30test('engine progress keeps a long prompt read alive past the stall limit, then the normal limit applies (#3623)', { skip }, async (t) => {
31  const worker = await startScriptedWorker({});
32  const dir = mkdtempSync(join(tmpdir(), 'strata-wd-')); const ws = join(dir, 'ws'); mkdirSync(ws, { recursive: true });
33  const started = Date.now();
34  const bridge = createAgentBridge({ dataDir: dir, localInstances: () => [{ id: 'i', label: 'S', baseUrl: worker.url, modelId: 'scripted-model', context: 32768, slots: 2 }], connections: () => [], env: process.env, startTimeoutMs: 90_000, stallMs: 2500, stallToolMs: 6000, engineGraceMs: 60_000,
35    // The engine moves for 7 s (a prompt being read), then goes quiet.
36    engineProgress: () => (Date.now() - started < 7_000 ? `reading:${Date.now()}` : null) });
37  t.after(async () => { await bridge.close(); await worker.close(); try { rmSync(dir, { recursive: true, force: true, maxRetries: 3 }); } catch { /* best effort */ } });
38  const out = [];
39  const t0 = Date.now();
40  await bridge.runTurn({ chatId: 'w2', message: 'SCRIPT:hang', workspacePath: ws, mode: 'bypass', onFrame: f => out.push(f) });
41  assert.ok(Date.now() - started > 7_000, 'the 2.5 s stall limit did not fire while the engine was reading');
42  assert.ok(Date.now() - t0 < 40_000, 'and it still ended by itself once the engine went quiet');
43  assert.match(out.find(f => f.type === 'error').message, /stopped answering/);
44});