Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

fix(prompt): keep long commands in a tracked foreground session

Saim Shafiquea86eb7a0a649
diff --git a/server/system-prompt.test.ts b/server/system-prompt.test.ts
index 5b81436731..e4b1c2850e 100644
--- a/server/system-prompt.test.ts
+++ b/server/system-prompt.test.ts
@@ -424,13 +424,32 @@ describe("longCommandsPrompt", () => {
const text = longCommandsPrompt(kind);
expect(text).toContain("`timeout` in milliseconds, up to 600000");
expect(text).toContain("Never wait inside a command for CI, a deploy or any other job to finish (no sleep loops or repeated polls): check it once");
- expect(text).toContain("tell the person what you made (with links), set wait_until or a one-time trigger to check back, and end your turn. When the person writes while you work, answer them first.");
+ expect(text).toContain("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");
+ expect(text).toContain("When the person writes while you work, answer them first.");
expect(text).not.toContain("vm_exec");
}
for (const kind of ["vm-private", "vm-shared"] as const) {
expect(longCommandsPrompt(kind)).toContain("vm_exec takes `timeout_seconds` instead (default 60, at most 300)");
}
});
+
+ it("keeps a long command in a tracked foreground session instead of detaching it", () => {
+ 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("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");
+ expect(text).toContain("cannot set a wait, so finish it in this turn");
+ }
+ });
+
+ 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("start it detached inside the VM (`nohup <command> > /tmp/<job>.log 2>&1 &`)");
+ }
+ });
});
it("tells Cloud bots which folders the person shares, that the copies are read-only, and where their own work goes", () => {
diff --git a/server/system-prompt.ts b/server/system-prompt.ts
index b96a323f10..b4c98f0a07 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, either pass a longer per-call timeout (Bash takes \`timeout\` in milliseconds, up to ${BASH_MAX_TIMEOUT_MS}) or start it detached with its output in a file (\`nohup <command> > /tmp/<job>.log 2>&1 &\`) and check that file in later calls. 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), set wait_until or a one-time trigger to check back, and end your turn. 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, 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.`;
const VM_LONG_COMMANDS_TEXT =
- " In your Local VM, vm_exec takes `timeout_seconds` instead (default 60, at most 300); start anything longer detached the same way, inside the VM, and check its log with later vm_exec calls.";
+ " 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.";
export function longCommandsPrompt(computer: ComputerPromptKind | null): string {
return LONG_COMMANDS_TEXT + (computer === "vm-private" || computer === "vm-shared" ? VM_LONG_COMMANDS_TEXT : "");
}