Skip to content

Qwen3.8-Flash-Next on any consumer hardware: one-click install for Windows / Linux. Strata inference engine, OpenAI/Anthropic API on localhost, optional image input.

C++

A turn always ends: watchdog for a silent model or a tool that never returns; launches return at once

Niko1221ddfed500a970
diff --git a/apps/host/server/agent/agent-bridge.mjs b/apps/host/server/agent/agent-bridge.mjs
index feb9f1868..1910724cf 100644
--- a/apps/host/server/agent/agent-bridge.mjs
+++ b/apps/host/server/agent/agent-bridge.mjs
@@ -57,7 +57,7 @@ const deferred = () => { let resolve; const promise = new Promise(r => { resolve
* @param {string} [options.nodePath] the Node runtime that runs the Harness
* @param {(line:string)=>void} [options.log]
*/
-export function createAgentBridge({ dataDir, componentsDir = null, bundledDir = null, gate = true, localInstances, connections, tools = () => undefined, skillsDir = () => null, onGoal = () => {}, onPlan = () => {}, onQueue = () => {}, proxyBase = null, expertSampling = () => null, env = process.env, nodePath = process.execPath, log = () => {}, startTimeoutMs = 120_000 }) {
+export function createAgentBridge({ dataDir, componentsDir = null, bundledDir = null, gate = true, localInstances, connections, tools = () => undefined, skillsDir = () => null, onGoal = () => {}, onPlan = () => {}, onQueue = () => {}, proxyBase = null, expertSampling = () => null, stallMs = 4 * 60_000, stallToolMs = 20 * 60_000, env = process.env, nodePath = process.execPath, log = () => {}, startTimeoutMs = 120_000 }) {
const root = join(dataDir, 'agent');
const home = join(root, 'home');
const sessionsFile = join(root, 'sessions.json');
@@ -311,14 +311,33 @@ export function createAgentBridge({ dataDir, componentsDir = null, bundledDir =
abortFromRuntime: reason => finishTurn(reason), finish: failure => finishTurn(failure),
// Helper agents (subagents) the Harness started for this chat, and the state of the run around them.
children: new Map(), subagentCalls: new Map(), parentOpen: false, stopping: false, settleTimer: null, mode: appliedMode,
- plan: null, advancing: false, goalRun: false,
+ plan: null, advancing: false, goalRun: false, lastActivity: Date.now(), watchdog: null,
research: researchTopic ? { phase: 'gather', nudged: false, waitingStart: false } : null,
};
c.turn = turn;
+ /**
+ * A turn must always end. If the Harness sends nothing at all for a while (a tool that never returns, a model server that went
+ * quiet, a lost event) the turn is stopped and ended with a plain message instead of showing "thinking" forever. A running tool gets
+ * a longer allowance than a quiet model (a build can be silent for minutes). Whatever the assistant finished is kept.
+ */
+ turn.watchdog = setInterval(() => {
+ if (turn.finished || turn.stopping) return;
+ const toolRunning = [...projector.tools.values()].some(x => x.card?.state === 'running' || x.card?.state === 'proposed') || pending.size > 0 && pendingFor(chatId).length > 0;
+ const limit = toolRunning ? stallToolMs : stallMs;
+ if (Date.now() - turn.lastActivity < limit) return;
+ turn.stalledFor = Math.round((Date.now() - turn.lastActivity) / 1000);
+ turn.stopping = true;
+ void runtime.gw.rpc('session/cancel', { request: { sessionId } }).catch(() => {});
+ for (const h of turn.children.values()) if (!h.done) void runtime.gw.rpc('subagents/interruptByParent', { childSessionId: h.id, parentSessionId: sessionId, mode: 'continuable' }).catch(() => {});
+ const mins = Math.max(1, Math.round(turn.stalledFor / 60));
+ turn.finish(`The assistant stopped answering for ${mins > 1 ? mins + ' minutes' : 'a minute'}, so I ended this turn. Anything it already finished is kept. Send your message again to go on.`);
+ }, Math.min(15_000, Math.max(200, Math.floor(stallMs / 4))));
+ turn.watchdog.unref?.();
function finishTurn(failure) {
if (turn.finished) return;
turn.finished = true;
clearTimeout(turn.settleTimer);
+ clearInterval(turn.watchdog);
turn.follow?.close();
for (const child of turn.children.values()) child.follow?.close();
if (turn.stopping && !failure) projector.ended = { kind: 'aborted', reason: { kind: 'user' } };
@@ -357,6 +376,7 @@ export function createAgentBridge({ dataDir, componentsDir = null, bundledDir =
function handle(item) {
if (turn.finished) return;
+ turn.lastActivity = Date.now();
if (item.type === 'event') {
const e = item.event;
if (e.seq <= turn.lastSeq) return;
@@ -393,6 +413,7 @@ export function createAgentBridge({ dataDir, componentsDir = null, bundledDir =
emitRow(child, true);
const fold = item => {
if (turn.finished) return;
+ turn.lastActivity = Date.now();
// A helper that finishes before its throttled "working" row went out would show queued -> completed and never "working": send the held row first.
if (item.type === 'event' && item.event.type === 'turn/end' && child.rowPending) emitRow(child, true);
const { frames, row } = cp.consume(item);
diff --git a/apps/host/server/agent/preset.mjs b/apps/host/server/agent/preset.mjs
index 40ebbfdb0..d14c7e89e 100644
--- a/apps/host/server/agent/preset.mjs
+++ b/apps/host/server/agent/preset.mjs
@@ -43,6 +43,7 @@ export const AGENT_PROMPT = [
'Answer questions directly and briefly; use a tool only when the task needs one. The person reads your replies in a chat: use plain words, not tool names or technical jargon.',
'Look before you change: read a file before you edit or overwrite it, and prefer a small edit to a rewrite. Search with the glob and grep tools and read files with the read tool; use the shell for running programs.',
'When you start a program or open a folder or file for the person, the command returning without an error means it worked: say plainly that it is open. Do not say you could not confirm it. If a command fails, say what went wrong in one sentence and what you will try next.',
+ 'To open a page or a file for the person (a browser, an app, a folder), start it so the command returns at once and never wait for the program to close: on Windows use Start-Process, on macOS open, on Linux xdg-open. Then say plainly that it is open.',
'Tokens prefixed with @ are files or folders the person pointed at. A failed or refused action changed nothing; say so, and do not claim work you did not do.',
].join('\n\n');
diff --git a/apps/host/tests/agent-watchdog.test.mjs b/apps/host/tests/agent-watchdog.test.mjs
new file mode 100644
index 000000000..29c2055a3
--- /dev/null
+++ b/apps/host/tests/agent-watchdog.test.mjs
@@ -0,0 +1,28 @@
+// A turn always ends: when the model goes silent the watchdog stops it with a plain message.
+import test from 'node:test';
+import assert from 'node:assert/strict';
+import { mkdtempSync, mkdirSync, rmSync } from 'node:fs';
+import { tmpdir } from 'node:os';
+import { join } from 'node:path';
+import { startScriptedWorker } from './helpers/scripted-worker.mjs';
+import { createAgentBridge } from '../server/agent/agent-bridge.mjs';
+import { resolveHarness } from '../server/agent/harness-runtime.mjs';
+const HARNESS = process.env.STRATA_HARNESS_DIR;
+const skip = !HARNESS || !resolveHarness({ env: process.env }).ok ? 'STRATA_HARNESS_DIR is not set to a built Harness' : false;
+
+test('a silent model ends the turn with a plain message, and the chat works again afterwards', { skip }, async (t) => {
+ const worker = await startScriptedWorker({});
+ const dir = mkdtempSync(join(tmpdir(), 'strata-wd-')); const ws = join(dir, 'ws'); mkdirSync(ws, { recursive: true });
+ 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 });
+ t.after(async () => { await bridge.close(); await worker.close(); try { rmSync(dir, { recursive: true, force: true, maxRetries: 3 }); } catch { /* best effort */ } });
+ const out = [];
+ const t0 = Date.now();
+ await bridge.runTurn({ chatId: 'w1', message: 'SCRIPT:hang', workspacePath: ws, mode: 'bypass', onFrame: f => out.push(f) });
+ assert.ok(Date.now() - t0 < 30_000, 'it ended by itself');
+ const err = out.find(f => f.type === 'error');
+ assert.match(err.message, /stopped answering/); assert.match(err.message, /Send your message again/);
+ assert.equal(out.at(-1).type, 'error');
+ const again = [];
+ await bridge.runTurn({ chatId: 'w1', message: 'SCRIPT:echo fine', workspacePath: ws, mode: 'bypass', onFrame: f => again.push(f) });
+ assert.match(again.filter(f => f.type === 'delta').map(f => f.text).join(''), /fine/);
+});
diff --git a/apps/host/tests/helpers/scripted-worker.mjs b/apps/host/tests/helpers/scripted-worker.mjs
index 0ff247bf0..b8db5cc6e 100644
--- a/apps/host/tests/helpers/scripted-worker.mjs
+++ b/apps/host/tests/helpers/scripted-worker.mjs
@@ -131,6 +131,7 @@ export async function startScriptedWorker({ port = 0, chunkDelayMs = 40, model =
const n = parseInt(args, 10) || 400;
return say(Array.from({ length: n }, (_, i) => `w${i} `));
}
+ if (name === 'hang') { send({ role: 'assistant', content: '' }); return; } // headers sent, then silence: a model server that went quiet
if (name === 'echo') return say([args]);
if (name === 'retrywrite' || name === 'retryshell') {
const [file, ...rest] = args.split(/\s+/);