Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix(prompt): bound live-session polling, exempt long VM jobs, drop nohup retry hint
Saim Shafique209060eed50a
diff --git a/server/shell-timeout-hint.test.ts b/server/shell-timeout-hint.test.tsindex e01ac777a0..a1b000db78 100644--- a/server/shell-timeout-hint.test.ts+++ b/server/shell-timeout-hint.test.ts@@ -6,12 +6,14 @@ import { shellTimeoutHint } from "./shell-timeout-hint.ts";const TIMED_OUT = "Exit code 143\nCommand timed out after 2m 0s";describe("shellTimeoutHint", () => {- it("tells a timed-out media command to rerun with a longer timeout or detached", () => {+ it("tells a timed-out media command to rerun with a longer timeout in the foreground", () => {const hint = shellTimeoutHint("Bash", { command: "ffmpeg -i in.mp3 -ar 16000 out.wav" }, TIMED_OUT)!;expect(hint).toContain("Do not rerun it the same way");expect(hint).toContain("`timeout`");expect(hint).toContain("600000");- expect(hint).toContain("nohup");+ expect(hint).toContain("foreground");+ expect(hint).not.toContain("nohup");+ expect(hint).not.toContain("detached");expect(hint).not.toContain("mdfind");});diff --git a/server/shell-timeout-hint.ts b/server/shell-timeout-hint.tsindex 4eff652bf8..d3ea39248e 100644--- a/server/shell-timeout-hint.ts+++ b/server/shell-timeout-hint.ts@@ -12,7 +12,7 @@ export function shellTimeoutHint(toolName: unknown, toolInput: unknown, error: u"That command hit the shell time limit and its output was lost. Do not rerun it the same way.",scan? "Do not search the whole disk: use `mdfind -name <name>` on macOS, or `find` in a specific folder (your workspace, home, /Applications) with -maxdepth."- : `If it needs longer, rerun it with a larger \`timeout\` (in milliseconds, up to ${BASH_MAX_TIMEOUT_MS}), or start it detached with \`nohup <command> > /tmp/<job>.log 2>&1 &\` and check that log in later calls. Split very long media jobs into shorter pieces.`,+ : `If it needs longer, rerun it with a larger \`timeout\` (in milliseconds, up to ${BASH_MAX_TIMEOUT_MS}) and keep it in the foreground until it exits. Split very long media jobs into shorter pieces.`,].join(" ");}diff --git a/server/system-prompt.test.ts b/server/system-prompt.test.tsindex e4b1c2850e..1d0106351a 100644--- a/server/system-prompt.test.ts+++ b/server/system-prompt.test.ts@@ -437,6 +437,9 @@ describe("longCommandsPrompt", () => {for (const kind of [null, "local", "vps", "box"] as const) {const text = longCommandsPrompt(kind);expect(text).toContain("keep the command in the foreground until it exits");+ expect(text).toContain("until it reaches terminal exit or the timeout elapses");+ expect(text).toContain("still running and unresolved");+ expect(text).toContain("split it into shorter pieces that each finish within it");expect(text).toContain("Do not detach a command with nohup");expect(text).not.toContain("nohup <command>");expect(text).toContain("require the command's own fresh exit code and output");@@ -447,6 +450,7 @@ describe("longCommandsPrompt", () => {it("keeps the Local VM's own detached path, where the container outlives the call", () => {for (const kind of ["vm-private", "vm-shared"] as const) {const text = longCommandsPrompt(kind);+ expect(text).toContain("This is the exception to the no-detach rule above");expect(text).toContain("start it detached inside the VM (`nohup <command> > /tmp/<job>.log 2>&1 &`)");}});diff --git a/server/system-prompt.ts b/server/system-prompt.tsindex b4c98f0a07..a2bb9d13da 100644--- a/server/system-prompt.ts+++ b/server/system-prompt.ts@@ -217,9 +217,9 @@ export const CREDENTIAL_PROMPT =/** Ten minutes stays inside the 20-minute turn stall watchdog, which sees nothing while a command runs. */export const BASH_MAX_TIMEOUT_MS = 600_000;const LONG_COMMANDS_TEXT =- ` Long-running shell commands: a shell call is stopped after a default limit (2 minutes for a Bash call) and the output of a stopped command is lost. Before running anything that can take more than a minute, such as transcription (whisper), ffmpeg or ffprobe over long media, renders, large builds or big file transfers, pass a longer per-call timeout (Bash takes \`timeout\` in milliseconds, up to ${BASH_MAX_TIMEOUT_MS}) and keep the command in the foreground until it exits: if the call returns a live session, keep polling that session until it reaches terminal exit, then check its fresh exit code and output before moving on. Do not detach a command with nohup or \`&\`: a detached job is not tracked, its shell exit does not mean the work finished, and a later call may find no process left to wait on. A launch exit 0 or an old output file is not proof the work completed; require the command's own fresh exit code and output. Never scan the whole disk with \`find /\` or similar: search by name with \`mdfind -name\` on macOS, or search a specific folder such as your workspace or home with a depth limit. If a command times out, do not rerun it the same way. Never wait inside a command for CI, a deploy or any other job to finish (no sleep loops or repeated polls): check it once, and if it is still running, tell the person what you made (with links). Only on a turn the person started in their own chat, set wait_until or a one-time trigger to check back and end your turn; work handed to you by a bot, a routine or an outside event cannot set a wait, so finish it in this turn instead of scheduling a continuation you cannot authorize. When the person writes while you work, answer them first.`;+ ` Long-running shell commands: a shell call is stopped after a default limit (2 minutes for a Bash call) and the output of a stopped command is lost. Before running anything that can take more than a minute, such as transcription (whisper), ffmpeg or ffprobe over long media, renders, large builds or big file transfers, pass a longer per-call timeout (Bash takes \`timeout\` in milliseconds, up to ${BASH_MAX_TIMEOUT_MS}) and keep the command in the foreground until it exits: if the call returns a live session, keep polling that session until it reaches terminal exit or the timeout elapses, then check its fresh exit code and output before moving on; if it has not exited by then, stop polling and tell the person the command is still running and unresolved instead of claiming it finished. If a command cannot finish within the timeout, split it into shorter pieces that each finish within it, confirming each piece's fresh exit code and output. Do not detach a command with nohup or \`&\`: a detached job is not tracked, its shell exit does not mean the work finished, and a later call may find no process left to wait on. A launch exit 0 or an old output file is not proof the work completed; require the command's own fresh exit code and output. Never scan the whole disk with \`find /\` or similar: search by name with \`mdfind -name\` on macOS, or search a specific folder such as your workspace or home with a depth limit. If a command times out, do not rerun it the same way. Never wait inside a command for CI, a deploy or any other job to finish (no sleep loops or repeated polls): check it once, and if it is still running, tell the person what you made (with links). Only on a turn the person started in their own chat, set wait_until or a one-time trigger to check back and end your turn; work handed to you by a bot, a routine or an outside event cannot set a wait, so finish it in this turn instead of scheduling a continuation you cannot authorize. When the person writes while you work, answer them first.`;const VM_LONG_COMMANDS_TEXT =- " In your Local VM, vm_exec takes `timeout_seconds` instead (default 60, at most 300); the VM container keeps running between calls, so for anything longer start it detached inside the VM (`nohup <command> > /tmp/<job>.log 2>&1 &`) and check its log with later vm_exec calls.";+ " In your Local VM, vm_exec takes `timeout_seconds` instead (default 60, at most 300). This is the exception to the no-detach rule above: the VM container keeps running between calls, so for a job longer than 300 seconds start it detached inside the VM (`nohup <command> > /tmp/<job>.log 2>&1 &`) and check its log with later vm_exec calls.";export function longCommandsPrompt(computer: ComputerPromptKind | null): string {return LONG_COMMANDS_TEXT + (computer === "vm-private" || computer === "vm-shared" ? VM_LONG_COMMANDS_TEXT : "");}