Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix(server): free a turn whose engine process exited
subfocusxf05c45e90adc
diff --git a/server/chat-notices.ts b/server/chat-notices.tsindex 430e0bca74..826523adb0 100644--- a/server/chat-notices.ts+++ b/server/chat-notices.ts@@ -11,6 +11,7 @@ export const CHAT_NOTICE = {"chat.notice.cutOffByRestart": "{name} was cut off by a restart; resuming","chat.notice.stalled": "no activity for {minutes} minutes — the turn was stopped","chat.notice.stalledCommand": "the command `{command}` ran for {minutes} minutes without finishing and looks stuck — the turn was stopped",+ "chat.notice.engineExited": "the process running this turn's AI ended — the turn was stopped","chat.notice.followupInterrupted":"Queued follow-up interrupted by restart or restore — it may have already run. Review the result before sending it again.","chat.notice.usageLimit": "This {provider} account has reached its usage limit{detail}. Wait for it to reset, or switch this bot to another AI.",diff --git a/server/drivers/acp/acp.test.ts b/server/drivers/acp/acp.test.tsindex af01ed5df8..a9caf24c42 100644--- a/server/drivers/acp/acp.test.ts+++ b/server/drivers/acp/acp.test.ts@@ -391,7 +391,7 @@ describe("ACP turns (fake CLI)", () => {// The stall watchdog sees no tool left running, so the turn's own silence limit applies.let now = 0;const limits: number[] = [];- const dog = new TurnWatchdog({ stallMs: 10, toolStallMs: 1_000, parkedStallMs: 10_000, checkMs: 60_000, now: () => now, onStall: (_turn, silentMs) => limits.push(silentMs) });+ const dog = new TurnWatchdog({ stallMs: 10, toolStallMs: 1_000, parkedStallMs: 10_000, engineExitStallMs: 10_000, checkMs: 60_000, now: () => now, onStall: (_turn, silentMs) => limits.push(silentMs) });dog.watch("t-finished-tools", "bot");for (const event of recorder.events) dog.observe(event);now = 10;diff --git a/server/index.ts b/server/index.tsindex a4ef605015..75e95ead72 100644--- a/server/index.ts+++ b/server/index.ts@@ -333,7 +333,7 @@ import { Handoffs, handedStateUsable, isContextMessage, recordHanded, renderUnseimport { extractReplayImages, extractTurnImages, videoFramesWithin } from "./turn-images.ts";import { callTitleExcerpt } from "./thread-title.ts";import { generateThreadTitle, llmThreadTitlesEnabled } from "./thread-title-generate.ts";-import { engineCommandCpuMs, engineProcessGone, stallLimitMs, stallNotice, TurnWatchdog } from "./turn-watchdog.ts"; import { createIdleThreads } from "./host/idle-threads.ts";+import { engineCommandCpuMs, engineProcessExited, engineProcessGone, ENGINE_EXIT_STALL_MS, stallLimitMs, stallNotice, TurnWatchdog } from "./turn-watchdog.ts"; import { createIdleThreads } from "./host/idle-threads.ts";import { TurnResources, type TurnOwner } from "./turn-resources.ts";import { createPhoneHold } from "./phone-screen/hold.ts"; import { createPhoneGate } from "./routes/phone-gate.ts";import { endHoldUnlessOn, usbPhoneOffered, usbPhoneTakeoverEnabled } from "./phone-screen/flag.ts";@@ -4992,9 +4992,9 @@ function stoppedTurnText(threadId: string, turnId: string | undefined, cause?: s});}const watchdog = new TurnWatchdog({- stallMs: TURN_STALL_MS, toolStallMs: TOOL_STALL_MS, parkedStallMs: COMPUTER_WAIT_MAX_MS + TURN_STALL_MS, commandCpuMs: (turn, since) => engineCommandCpuMs(runningTurnInstance(botForThread(turn.botId, turn.threadId), turn.threadId)?.adapter, turn.threadId, since),- checkMs: 60_000, unheld: { threads: () => idleThreads.unheld(), free: (threadId, botId) => idleThreads.free(botId, threadId) }, engineGone: (turn) => engineProcessGone(runningTurnInstance(botForThread(turn.botId, turn.threadId), turn.threadId)?.adapter, turn.threadId),- onStall: (turn, silentMs) => {+ stallMs: TURN_STALL_MS, toolStallMs: TOOL_STALL_MS, parkedStallMs: COMPUTER_WAIT_MAX_MS + TURN_STALL_MS, engineExitStallMs: ENGINE_EXIT_STALL_MS, commandCpuMs: (turn, since) => engineCommandCpuMs(runningTurnInstance(botForThread(turn.botId, turn.threadId), turn.threadId)?.adapter, turn.threadId, since),+ checkMs: 60_000, unheld: { threads: () => idleThreads.unheld(), free: (threadId, botId) => idleThreads.free(botId, threadId) }, engineGone: (turn) => engineProcessGone(runningTurnInstance(botForThread(turn.botId, turn.threadId), turn.threadId)?.adapter, turn.threadId), engineExited: (turn) => engineProcessExited(runningTurnInstance(botForThread(turn.botId, turn.threadId), turn.threadId)?.adapter, turn.threadId),+ onStall: (turn, silentMs, reason) => {const stalledResourceOwner = turnResourceOwners.get(turn.threadId);const stalledGeneration = directTurnGenerationByThread.get(turn.threadId);const stalledProviderTurn = directRequestOwners.get(turn.threadId);@@ -5005,10 +5005,10 @@ const watchdog = new TurnWatchdog({const bot = botForThread(turn.botId, turn.threadId);const routineRun = activeRoutineRunForThread(turn.threadId);void runningTurnInstance(bot, turn.threadId)?.adapter.interruptTurn(turn.threadId).catch(() => {});- const minutes = Math.round(silentMs / 60_000), notice = stallNotice(turn, silentMs, Date.now()), stallCause = chatNotice(notice.key, notice.params), cause = engineMemory.stallCause(turn.threadId, stallCause);+ const minutes = Math.round(silentMs / 60_000), notice = stallNotice(turn, silentMs, Date.now(), reason), stallCause = chatNotice(notice.key, notice.params), cause = engineMemory.stallCause(turn.threadId, stallCause);const stalled = stoppedTurnText(turn.threadId, liveTurnByThread.get(turn.threadId), cause);if (routineRun?.target === "bot") {- routines?.failThread(turn.threadId, engineMemory.stallCause(turn.threadId, `No activity for ${minutes} minutes — the routine was stopped`), { cause: "stalled" });+ routines?.failThread(turn.threadId, engineMemory.stallCause(turn.threadId, reason === "engine-exited" ? stallCause : `No activity for ${minutes} minutes — the routine was stopped`), { cause: "stalled" });}store.appendMessage(turn.threadId, {role: "bot",diff --git a/server/turn-watchdog.test.ts b/server/turn-watchdog.test.tsindex fda1bc842a..15fc1519e8 100644--- a/server/turn-watchdog.test.ts+++ b/server/turn-watchdog.test.ts@@ -1,3 +1,4 @@+import { spawn } from "node:child_process";import { readFileSync } from "node:fs";import vm from "node:vm";import ts from "@typescript/typescript6";@@ -8,11 +9,12 @@ import type { ProviderAdapter, RuntimeEvent } from "./contracts.ts";import { EngineMemory } from "./engine-memory.ts";import type { Message } from "./store.ts";import { TurnStops, stoppedTurnOutcome } from "./turn-outcome.ts";-import { engineCommandCpuMs, engineProcessGone, stallLimitMs, stallNotice, stuckCommand, TurnWatchdog, type TurnWatchdogOptions, type WatchedTurn } from "./turn-watchdog.ts";+import { engineCommandCpuMs, engineProcessExited, engineProcessGone, ENGINE_EXIT_STALL_MS, stallLimitMs, stallNotice, stuckCommand, TurnWatchdog, type StallReason, type TurnWatchdogOptions, type WatchedTurn } from "./turn-watchdog.ts";const STALL = 10_000;const TOOL_STALL = 50_000;const PARKED_STALL = 1_000 * STALL;+const ENGINE_EXIT_STALL = 2_000;const base = { eventId: "e1", provider: "claudeAgent", threadId: "t1", createdAt: "2026-01-01T00:00:00.000Z" };const text: RuntimeEvent = { ...base, type: "content.delta", streamKind: "assistant_text", delta: "working" };const toolStarted = (itemId: string): RuntimeEvent => ({ ...base, type: "item.started", itemType: "tool", itemId });@@ -23,6 +25,7 @@ function rig(extra: Partial<TurnWatchdogOptions> = {}) {let now = 0;const stalls: WatchedTurn[] = [];const limits: number[] = [];+ const reasons: StallReason[] = [];const adapters = new Map<string, Pick<ProviderAdapter, "enginePid">>();const alive = new Set<number>();const working: Array<{ threadId: string; botId: string }> = [];@@ -31,9 +34,11 @@ function rig(extra: Partial<TurnWatchdogOptions> = {}) {stallMs: STALL,toolStallMs: TOOL_STALL,parkedStallMs: PARKED_STALL,+ engineExitStallMs: ENGINE_EXIT_STALL,checkMs: 60_000,engineGone: (turn) => engineProcessGone(adapters.get(turn.threadId), turn.threadId, (pid) => alive.has(pid)),- onStall: (turn, silentMs) => { stalls.push(turn); limits.push(silentMs); },+ engineExited: (turn) => engineProcessExited(adapters.get(turn.threadId), turn.threadId, (pid) => alive.has(pid)),+ onStall: (turn, silentMs, reason) => { stalls.push(turn); limits.push(silentMs); reasons.push(reason); },unheld: {threads: () => [...working],free: (threadId) => { freed.push(threadId); working.splice(working.findIndex((thread) => thread.threadId === threadId), 1); },@@ -41,7 +46,7 @@ function rig(extra: Partial<TurnWatchdogOptions> = {}) {now: () => now,...extra,});- return { dog, stalls, limits, adapters, alive, working, freed, tick: (ms: number) => (now += ms) };+ return { dog, stalls, limits, reasons, adapters, alive, working, freed, tick: (ms: number) => (now += ms) };}const ENGINE_PID = 4242;@@ -143,6 +148,88 @@ describe("TurnWatchdog", () => {expect(engineProcessGone(tracked(ENGINE_PID), "t1", () => false)).toBe(true);});+ it("reads an engine's process as exited only when its driver names one that is gone", () => {+ expect(engineProcessExited(undefined, "t1")).toBe(false);+ expect(engineProcessExited({}, "t1")).toBe(false);+ expect(engineProcessExited(tracked(undefined), "t1")).toBe(false);+ expect(engineProcessExited(tracked(process.pid), "t1")).toBe(false);+ expect(engineProcessExited(tracked(ENGINE_PID), "t1", () => false)).toBe(true);+ });++ it("stops a turn whose engine process exited, without waiting for the tool's own limit", () => {+ const { dog, stalls, limits, reasons, adapters, alive, tick } = rig();+ adapters.set("t1", tracked(ENGINE_PID));+ alive.add(ENGINE_PID);+ dog.watch("t1", "bot1");+ dog.observe(toolStarted("tool-1"));+ alive.delete(ENGINE_PID);+ tick(ENGINE_EXIT_STALL - 1);+ dog.sweep();+ expect(stalls).toHaveLength(0);+ tick(2);+ dog.sweep();+ expect(stalls).toEqual([expect.objectContaining({ threadId: "t1", botId: "bot1" })]);+ expect(limits).toEqual([ENGINE_EXIT_STALL]);+ expect(reasons).toEqual(["engine-exited"]);+ expect(dog.watching("t1")).toBe(false);+ });++ it("leaves a turn whose engine still runs to the tool's own limit", () => {+ const { dog, stalls, limits, reasons, adapters, alive, tick } = rig();+ adapters.set("t1", tracked(ENGINE_PID));+ alive.add(ENGINE_PID);+ dog.watch("t1", "bot1");+ dog.observe(toolStarted("tool-1"));+ tick(ENGINE_EXIT_STALL * 2);+ dog.sweep();+ expect(stalls).toHaveLength(0);+ tick(TOOL_STALL);+ dog.sweep();+ expect(limits).toEqual([TOOL_STALL]);+ expect(reasons).toEqual(["silent"]);+ });++ it("does not stop a turn for an engine it cannot see: a driver that names no process proves nothing", () => {+ for (const adapter of [tracked(undefined), {}] as const) {+ const { dog, stalls, limits, reasons, adapters, alive, tick } = rig();+ adapters.set("t1", adapter);+ alive.add(ENGINE_PID);+ dog.watch("t1", "bot1");+ dog.observe(toolStarted("tool-1"));+ tick(ENGINE_EXIT_STALL * 2);+ dog.sweep();+ expect(stalls).toHaveLength(0);+ tick(TOOL_STALL);+ dog.sweep();+ expect(limits).toEqual([TOOL_STALL]);+ expect(reasons).toEqual(["silent"]);+ }+ });++ it("stops a turn whose engine's own process is gone, the way a killed engine leaves it", async () => {+ const child = spawn(process.execPath, ["-e", "setTimeout(() => {}, 25)"], { stdio: "ignore" });+ const pid = child.pid!;+ await new Promise((resolve) => child.once("exit", resolve));+ let now = 0;+ const stalls: StallReason[] = [];+ const dog = new TurnWatchdog({+ stallMs: STALL, toolStallMs: TOOL_STALL, parkedStallMs: PARKED_STALL, engineExitStallMs: ENGINE_EXIT_STALL, checkMs: 60_000,+ engineExited: (turn) => engineProcessExited(tracked(pid), turn.threadId),+ onStall: (_turn, _silentMs, reason) => stalls.push(reason),+ now: () => now,+ });+ dog.watch("t1", "bot1");+ dog.observe(toolStarted("tool-1"));+ now = ENGINE_EXIT_STALL;+ dog.sweep();+ expect(stalls).toEqual(["engine-exited"]);+ });++ it("tells the person that the engine's process ended, not that the turn was silent", () => {+ expect(stallNotice({}, STALL, STALL, "engine-exited")).toEqual({ key: "chat.notice.engineExited", params: {} });+ expect(stallNotice({}, STALL, STALL).key).toBe("chat.notice.stalled");+ });+it("a settled turn is forgotten", () => {const { dog, stalls, tick } = rig();dog.watch("t1", "bot1");@@ -260,7 +347,7 @@ describe("TurnWatchdog", () => {it("does not count the time the computer slept as a turn's silence", () => {vi.useFakeTimers({ now: 0 });const stalls: WatchedTurn[] = [];- const dog = new TurnWatchdog({ stallMs: STALL, toolStallMs: TOOL_STALL, parkedStallMs: PARKED_STALL, checkMs: 1_000, onStall: (turn) => stalls.push(turn) });+ const dog = new TurnWatchdog({ stallMs: STALL, toolStallMs: TOOL_STALL, parkedStallMs: PARKED_STALL, engineExitStallMs: ENGINE_EXIT_STALL, checkMs: 1_000, onStall: (turn) => stalls.push(turn) });try {dog.start();dog.watch("t1", "bot1");@@ -282,7 +369,7 @@ describe("TurnWatchdog", () => {it("still counts silence across sweeps that are only a little late", () => {vi.useFakeTimers({ now: 0 });const stalls: WatchedTurn[] = [];- const dog = new TurnWatchdog({ stallMs: STALL, toolStallMs: TOOL_STALL, parkedStallMs: PARKED_STALL, checkMs: 1_000, onStall: (turn) => stalls.push(turn) });+ const dog = new TurnWatchdog({ stallMs: STALL, toolStallMs: TOOL_STALL, parkedStallMs: PARKED_STALL, engineExitStallMs: ENGINE_EXIT_STALL, checkMs: 1_000, onStall: (turn) => stalls.push(turn) });try {dog.start();dog.watch("t1", "bot1");@@ -523,7 +610,7 @@ describe("the stall handler", () => {const context = vm.createContext({process: { env },RoomTurnStallRegistry: class { stall() {} },- TurnStops, stoppedTurnOutcome, reportsToRequester: () => true, stallLimitMs,+ TurnStops, stoppedTurnOutcome, reportsToRequester: () => true, stallLimitMs, ENGINE_EXIT_STALL_MS,TurnWatchdog: class { options: unknown; constructor(options: { onStall: (turn: WatchedTurn) => void }) { this.options = options; } },store: { messagesFor: () => messages, activePath: () => messages, appendMessage() {} },turnResourceOwners: new Map(), directTurnGenerationByThread: new Map([["t1", "gen-1"]]), directRequestOwners: new Map(),@@ -543,7 +630,7 @@ describe("the stall handler", () => {it("tells a stalled turn's requester why it stopped and what it did", () => {const { context, settled, delegations } = load();- context.watchdog.options.onStall({ threadId: "t1", botId: "eli" }, 20 * 60_000);+ context.watchdog.options.onStall({ threadId: "t1", botId: "eli" }, 20 * 60_000, "silent");const told = 'No activity for 20 minutes — the turn was stopped. Before it stopped it made 1 tool call: Bash ×1.\nIts last message, quoted: "Exporting the second half now."';expect(settled).toEqual([{ generation: "gen-1", text: told }]);expect(delegations).toEqual([]);@@ -551,15 +638,21 @@ describe("the stall handler", () => {it("names the silence that stopped a turn whose tool was running", () => {const { context, settled } = load();- context.watchdog.options.onStall({ threadId: "t1", botId: "eli" }, 120 * 60_000);+ context.watchdog.options.onStall({ threadId: "t1", botId: "eli" }, 120 * 60_000, "silent");expect(settled[0]!.text).toMatch(/^No activity for 120 minutes — the turn was stopped\. Before it stopped/);});+ it("says the engine's process ended when the turn was stopped for that", () => {+ const { context, settled } = load();+ context.watchdog.options.onStall({ threadId: "t1", botId: "eli" }, 2 * 60_000, "engine-exited");+ expect(settled[0]!.text).toMatch(/^The process running this turn's AI ended — the turn was stopped\. Before it stopped/);+ });+it("names the shell command that was still running and how long it ran", () => {const { context, settled } = load();const startedAt = Date.now() - 120 * 60_000;const runningTools = new Map([["i1", { startedAt, command: "ffmpeg -i talk.mov talk.mp4" }]]);- context.watchdog.options.onStall({ threadId: "t1", botId: "eli", runningTools }, 120 * 60_000);+ context.watchdog.options.onStall({ threadId: "t1", botId: "eli", runningTools }, 120 * 60_000, "silent");expect(settled[0]!.text).toMatch(/^The command `ffmpeg -i talk\.mov talk\.mp4` ran for 120 minutes without finishing and looks stuck — the turn was stopped\. Before it stopped/);});@@ -578,7 +671,7 @@ describe("the stall handler", () => {memory.turnStarted("t1");memory.tick();const { context, settled } = load(memory);- context.watchdog.options.onStall({ threadId: "t1", botId: "eli" }, 20 * 60_000);+ context.watchdog.options.onStall({ threadId: "t1", botId: "eli" }, 20 * 60_000, "silent");expect(settled[0]!.text).toMatch(/^No activity for 20 minutes — the turn was stopped\. This Cloud ran out of memory while 1 task ran at once \(not a problem with the AI provider\)\. Before it stopped/);});diff --git a/server/turn-watchdog.ts b/server/turn-watchdog.tsindex 7b424e11ca..14281d9a85 100644--- a/server/turn-watchdog.ts+++ b/server/turn-watchdog.ts@@ -1,5 +1,6 @@import { processAlive } from "./browser-processes.ts";import type { ProviderAdapter, RuntimeEvent } from "./contracts.ts";+import type { ServerTextParams } from "../shared/server-text.ts";import { sampleProcessTree, type ProcessSample } from "./drivers/acp/quiet-status.ts";import { redactSecretsInText } from "../shared/redact.ts";@@ -39,11 +40,22 @@ export function stuckCommand(turn: Partial<Pick<WatchedTurn, "runningTools">>, sreturn oldest ? { command: redactSecretsInText(oldest.command), minutes: Math.max(1, Math.round((stopAt - oldest.startedAt) / 60_000)) } : null;}+/** Why the watchdog stopped a turn: it went silent, or the process running its engine exited and the turn can never+ * answer. */+export type StallReason = "silent" | "engine-exited";++/** The silence that stops a turn whose engine process has exited: its engine can never answer it, so it waits only long+ * enough for the driver to report the turn's own end, and not for the tool limit. */+export const ENGINE_EXIT_STALL_MS = 2 * 60_000;+/** What the person is told when the watchdog stops a turn silent for silentMs: the shell command still running, with how- * long it ran, so they know what looked stuck; otherwise how long the turn was silent. */-export function stallNotice(turn: Partial<Pick<WatchedTurn, "runningTools">>, silentMs: number, stopAt: number) {+ * long it ran, so they know what looked stuck; otherwise how long the turn was silent. A turn whose engine process+ * exited is told that instead: no silence of its own stopped it. */+export function stallNotice(turn: Partial<Pick<WatchedTurn, "runningTools">>, silentMs: number, stopAt: number, reason: StallReason = "silent"):+ { key: "chat.notice.engineExited"; params: ServerTextParams } | { key: "chat.notice.stalledCommand"; params: { command: string; minutes: number } } | { key: "chat.notice.stalled"; params: { minutes: number } } {+ if (reason === "engine-exited") return { key: "chat.notice.engineExited", params: {} };const stuck = stuckCommand(turn, stopAt);- return stuck ? { key: "chat.notice.stalledCommand" as const, params: stuck } : { key: "chat.notice.stalled" as const, params: { minutes: Math.round(silentMs / 60_000) } };+ return stuck ? { key: "chat.notice.stalledCommand", params: stuck } : { key: "chat.notice.stalled", params: { minutes: Math.round(silentMs / 60_000) } };}// Number() also reads "Infinity" and "1e309" as numbers, and an endless limit would switch the watchdog off.@@ -60,6 +72,14 @@ export function engineProcessGone(adapter: Pick<ProviderAdapter, "enginePid"> |return pid === undefined || !alive(pid);}+/** The engine's process for the thread's turn has exited: the driver names one and that process is gone. A driver that+ * names no process for the turn proves nothing (the turn may not have started one yet), so this is false for it. */+export function engineProcessExited(adapter: Pick<ProviderAdapter, "enginePid"> | null | undefined, threadId: string, alive = processAlive): boolean {+ if (!adapter?.enginePid) return false;+ const pid = adapter.enginePid(threadId);+ return pid !== undefined && !alive(pid);+}+/** The CPU time used by the processes the thread's engine started since `since` (what a tool call started then runs, not* the engine or its tool servers); null when the driver tracks no engine process or the time cannot be read. */export async function engineCommandCpuMs(adapter: Pick<ProviderAdapter, "enginePid"> | null | undefined, threadId: string, since: number,@@ -77,14 +97,21 @@ export interface TurnWatchdogOptions {toolStallMs: number;/** The silence that stops a parked turn whose engine is known to be gone: longer than any wait the harness bounds itself. */parkedStallMs: number;+ /** The silence that stops a turn whose engine process has exited: its engine can never answer it, so it does not wait+ * for the tool limit, only long enough for the driver to report the turn's own end. */+ engineExitStallMs: number;checkMs: number;/** The turn's engine is known to have no process left for it; absent or false, a parked turn waits on. */engineGone?: (turn: WatchedTurn) => boolean;+ /** The turn's engine process has exited: the driver names one for the turn and that process is gone. Absent or false,+ * the turn waits for the silence its tools bound. */+ engineExited?: (turn: WatchedTurn) => boolean;/** The CPU time the processes of the turn's shell command started at `since` have used, null when unknown. Read once* per sweep after a turn running one has been silent for stallMs: time gained since the last read counts as an event. */commandCpuMs?: (turn: WatchedTurn, since: number) => Promise<number | null>;- /** silentMs: the silence that stopped the turn, stallMs, toolStallMs or parkedStallMs. */- onStall: (turn: WatchedTurn, silentMs: number) => void;+ /** silentMs: the silence that stopped the turn, stallMs, toolStallMs, parkedStallMs or engineExitStallMs. reason: why+ * the turn was stopped, so the person is told what actually happened to it. */+ onStall: (turn: WatchedTurn, silentMs: number, reason: StallReason) => void;/** The conversations shown working that nothing holds but a watched turn (no dispatch, engine or settling turn): one no* watched turn holds either is freed once it has stayed so for stallMs. */unheld?: { threads(): Iterable<{ threadId: string; botId: string }>; free(threadId: string, botId: string): void };@@ -193,20 +220,22 @@ export class TurnWatchdog {const at = this.now();for (const turn of this.turns.values()) {if (sleptMs) turn.lastEventAt = Math.min(at, turn.lastEventAt + sleptMs);- const silentMs = this.silenceLimit(turn);- if (silentMs === null) continue;+ const limit = this.silenceLimit(turn);+ if (limit === null) continue;if (at - turn.lastEventAt >= this.opts.stallMs) this.readCommandCpu(turn);- if (at - turn.lastEventAt < silentMs) continue;+ if (at - turn.lastEventAt < limit.ms) continue;this.turns.delete(turn.threadId);- this.opts.onStall(turn, silentMs);+ this.opts.onStall(turn, limit.ms, limit.reason);}this.freeUnheld(at);}/** null: the turn may wait on, parked while its engine is not known to be gone. */- private silenceLimit(turn: WatchedTurn): number | null {- if (parked(turn)) return this.opts.engineGone?.(turn) ? this.opts.parkedStallMs : null;- return turn.runningTools.size > 0 ? Math.max(this.opts.stallMs, this.opts.toolStallMs) : this.opts.stallMs;+ private silenceLimit(turn: WatchedTurn): { ms: number; reason: StallReason } | null {+ if (parked(turn)) return this.opts.engineGone?.(turn) ? { ms: this.opts.parkedStallMs, reason: "silent" } : null;+ // The engine's process is gone: nothing can finish this turn, so it waits for the driver's own word, not for a tool's.+ if (this.opts.engineExited?.(turn)) return { ms: this.opts.engineExitStallMs, reason: "engine-exited" };+ return { ms: turn.runningTools.size > 0 ? Math.max(this.opts.stallMs, this.opts.toolStallMs) : this.opts.stallMs, reason: "silent" };}/** Reads the CPU time of a silent turn's shell command; one whose time changed since the last read is working (it gaineddiff --git a/src/locales/en.json b/src/locales/en.jsonindex fe179d6e89..c4ab6a5b1b 100644--- a/src/locales/en.json+++ b/src/locales/en.json@@ -8286,6 +8286,7 @@"chat.notice.cutOffByRestart": "{name} was cut off by a restart; resuming","chat.notice.stalled": "no activity for {minutes} minutes — the turn was stopped","chat.notice.stalledCommand": "the command `{command}` ran for {minutes} minutes without finishing and looks stuck — the turn was stopped",+ "chat.notice.engineExited": "the process running this turn's AI ended — the turn was stopped","chat.notice.followupInterrupted": "Queued follow-up interrupted by restart or restore — it may have already run. Review the result before sending it again.","chat.notice.usageLimit": "This {provider} account has reached its usage limit{detail}. Wait for it to reset, or switch this bot to another AI.","server.cloudComputer.replaced": "{name}'s cloud computer stopped responding, so MausBot replaced it with a new one. Files that were only on the old computer are gone.",diff --git a/src/locales/pt-br.json b/src/locales/pt-br.jsonindex 2897a7539e..4dd9869ecb 100644--- a/src/locales/pt-br.json+++ b/src/locales/pt-br.json@@ -8254,6 +8254,7 @@"chat.notice.cutOffByRestart": "Uma reinicialização interrompeu {name}. Retomando.","chat.notice.stalled": "Sem atividade por {minutes} min. A sessão foi interrompida.","chat.notice.stalledCommand": "O comando `{command}` rodou por {minutes} min sem terminar e parece travado. A sessão foi interrompida.",+ "chat.notice.engineExited": "O processo que executava a IA desta sessão terminou — a sessão foi interrompida.","chat.notice.followupInterrupted": "Uma reinicialização ou restauração interrompeu a mensagem na fila, mas talvez ela já tenha sido processada. Confira o resultado antes de enviar novamente.","chat.notice.usageLimit": "Esta conta de {provider} atingiu o limite de uso{detail}. Espere o limite ser renovado ou troque a IA deste bot.","chat.notice.claudeExtraUsage": "O Claude recusou esta sessão porque este modelo consome os créditos de uso extra da sua conta, e esses créditos acabaram. O uso do seu plano não foi afetado: troque este bot para um modelo incluído no plano ou adicione uso extra na sua conta do Claude.",diff --git a/src/locales/source-hashes.json b/src/locales/source-hashes.jsonindex 74adbc6493..805be987da 100644--- a/src/locales/source-hashes.json+++ b/src/locales/source-hashes.json@@ -36640,6 +36640,7 @@"chat.helperSuggestion.from": "a18ce56f0c7920f241bf64e3146c8d865c3a1f5b9e8b793bd2e4c9729fd2de27","chat.helperSuggestion.about": "90a8c616bbb161c27ffad72536c2ba545bbe837e31c70c581a19c0d0d5bb0bbf","chat.notice.stalledCommand": "5aa1ec21810ef3815f243d2058f4e167ad71aee5a8fabe1543ca83c6144399d1",+ "chat.notice.engineExited": "655897876364cea09c9b39119d927c31e80e21ea8931d88d2966d37dfb5dbb02","settings.logins.onePassword.changeItem": "95e5d6046e9d25e73ce6f33a97f95108c2c3027ebb01c08a94739467135ff468","settings.logins.onePassword.vaultChoice": "79ecc022e82d6ad96c1f0f82806170d3a0e69d331ac91851a0dd8d6c806c503b","settings.logins.onePassword.itemNote": "eee14017812e91c3b664d8e16e51132ae281c22c00810c0da99fd732bb3ae486",@@ -45095,6 +45096,7 @@"chat.notice.resumingAfterRestart": "1e52c60fc922d7da83d35c8f2e9a68ad2485abcd37ff48791799ca4c3b1bea6d","chat.notice.cutOffByRestart": "5debd3edeaf83a10b0bccf1d4ee9b0749b889a458058bd79fea07cd6e837bbda","chat.notice.stalled": "70183df486ccdfdfd823159ad2596648df38f9a36e2997eea97a69b475838a16",+ "chat.notice.engineExited": "655897876364cea09c9b39119d927c31e80e21ea8931d88d2966d37dfb5dbb02","chat.notice.followupInterrupted": "f371e87dd3ef7c64c46b93b9d515ecd290e18d3afd70cf587f6e97103a5601d6","chat.notice.usageLimit": "428d0901e21186b98e7c6d41ded70e968e3dccffe8944dcd7419a336c8f67f1e","chat.notice.claudeExtraUsage": "1b905b6db852ae54b7488799625873edbb36c98d869b07ff11f4f157e2701000",@@ -57142,6 +57144,7 @@"chat.helperSuggestion.from": "a18ce56f0c7920f241bf64e3146c8d865c3a1f5b9e8b793bd2e4c9729fd2de27","chat.helperSuggestion.about": "90a8c616bbb161c27ffad72536c2ba545bbe837e31c70c581a19c0d0d5bb0bbf","chat.notice.stalledCommand": "5aa1ec21810ef3815f243d2058f4e167ad71aee5a8fabe1543ca83c6144399d1",+ "chat.notice.engineExited": "655897876364cea09c9b39119d927c31e80e21ea8931d88d2966d37dfb5dbb02","server.threads.posted": "31b437fbd41ce818b378556ddab0c7efb933ccf0d26ecc64cf5ea574adff9f8b","chat.peer.viewExchange": "754968620621cbdd1d8ff6cb80df890f32ef8270d2cae2c588e803c19f5c76d7","chat.peer.exchangeTitle": "fae710f53d65af25536e037a798b17dad5e103966059816852699abcfdb78e2a",diff --git a/src/locales/zh-tw.json b/src/locales/zh-tw.jsonindex 0dc5281d4f..3b38eb5eca 100644--- a/src/locales/zh-tw.json+++ b/src/locales/zh-tw.json@@ -7796,6 +7796,7 @@"chat.notice.cutOffByRestart": "{name} 因重新啟動而中斷;正在繼續","chat.notice.stalled": "已有 {minutes} 分鐘沒有活動,這個回合已停止","chat.notice.stalledCommand": "指令 `{command}` 已執行 {minutes} 分鐘仍未完成,看起來卡住了,這個回合已停止",+ "chat.notice.engineExited": "執行本輪 AI 的行程已結束,這個回合已停止","chat.notice.followupInterrupted": "排隊中的後續訊息因重新啟動或還原而中斷,可能已經執行過。再次傳送前請先檢查結果。","chat.notice.usageLimit": "這個 {provider} 帳號已達到使用上限{detail}。請等它重設,或把這個機器人切換到另一個 AI。","chat.notice.claudeExtraUsage": "Claude 拒絕了這個回合,因為這個模型會使用你帳號的額外用量,而這些額度已用完。你方案本身的用量不受影響:請把這個機器人切換到你方案包含的模型,或在你的 Claude 帳號中加購額外用量。",diff --git a/src/locales/zh.json b/src/locales/zh.jsonindex 23beed36b9..8539e452bc 100644--- a/src/locales/zh.json+++ b/src/locales/zh.json@@ -9587,6 +9587,7 @@"chat.notice.resumingAfterRestart": "重启后继续","chat.notice.cutOffByRestart": "{name} 因重启被打断;正在继续","chat.notice.stalled": "{minutes} 分钟没有活动——该轮次已停止",+ "chat.notice.engineExited": "运行本轮 AI 的进程已结束,该轮次已停止","chat.notice.followupInterrupted": "排队中的追问因重启或恢复而中断——它可能已经执行过。请先查看结果,再决定是否重新发送。","chat.notice.usageLimit": "这个 {provider} 账号已达到使用上限{detail}。请等它重置,或把这个机器人切换到别的 AI。","chat.notice.claudeExtraUsage": "Claude 拒绝了这个轮次,因为这个模型对你账号来说是走额外用量的,而那份额度已用完。你自己套餐的用量不受影响:请把这个机器人切换到套餐包含的模型,或在你的 Claude 账号里添加额外用量。",