Skip to content

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

Tell a bot that a shell command stopped at its time limit has an unknown outcome (#7979)

Milind Sonie9b81c01e53d
diff --git a/server/shell-timeout-hint.test.ts b/server/shell-timeout-hint.test.ts
index dff2ca34fb..6db55807cc 100644
--- a/server/shell-timeout-hint.test.ts
+++ b/server/shell-timeout-hint.test.ts
@@ -17,6 +17,20 @@ describe("shellTimeoutHint", () => {
expect(hint).not.toContain("mdfind");
});
+ it("says the outcome of a timed-out command is unknown and must be checked before it is run again", () => {
+ const hint = shellTimeoutHint("Bash", { command: "curl -sS -X PUT https://api.example.com/repos/o/r/pulls/7/merge", timeout: 60000 }, "Exit code 143\nCommand timed out after 1m 0s")!;
+ expect(hint).toContain("outcome is UNKNOWN");
+ expect(hint).toContain("may already have taken effect");
+ expect(hint).toContain("Check the real state first");
+ expect(hint).toContain("not a failure report");
+ // The check comes before the advice about a longer limit, which is for the run after it.
+ expect(hint.indexOf("Check the real state first")).toBeLessThan(hint.indexOf("larger `timeout`"));
+ });
+
+ it("does not warn about outcomes for a whole-disk find, which changes nothing", () => {
+ expect(shellTimeoutHint("Bash", { command: "find / -name model.bin" }, TIMED_OUT)).not.toContain("UNKNOWN");
+ });
+
it("points a timed-out whole-disk find at mdfind or a scoped folder", () => {
for (const command of ["find / -iname '*.bin'", "ls; find / -name model.bin", "sudo find / -name x", "(find / -type f)"]) {
const hint = shellTimeoutHint("Bash", { command }, TIMED_OUT)!;
diff --git a/server/shell-timeout-hint.ts b/server/shell-timeout-hint.ts
index 434a442e4b..094669d569 100644
--- a/server/shell-timeout-hint.ts
+++ b/server/shell-timeout-hint.ts
@@ -4,12 +4,19 @@ import { BASH_MAX_TIMEOUT_TEXT } from "./system-prompt.ts";
const TIMED_OUT = /\bCommand timed out after\b/u;
const DISK_SCAN = /(?:^|[;&|(]\s*|\bsudo\s+)find\s+\/(?:\s|$)/mu;
+/** A command stopped at its limit may have done its work already (a request sent whose answer never came back), and
+ * running it again would do that work twice: the bot is told the outcome is unknown, not that the command failed. */
+const UNKNOWN_OUTCOME = "It was stopped part-way, so this is not a failure report: if it changes anything outside this shell (a merge, a push, a deploy, "
+ + "a payment, a sent message, any API write) its outcome is UNKNOWN and it may already have taken effect. Check the real state first "
+ + "(read it back from the service) and run it again only if that shows it did not happen.";
+
export function shellTimeoutHint(toolName: unknown, toolInput: unknown, error: unknown): string | null {
if (toolName !== "Bash" || typeof error !== "string" || !TIMED_OUT.test(error)) return null;
const command = toolInput && typeof toolInput === "object" ? (toolInput as { command?: unknown }).command : undefined;
const scan = typeof command === "string" && DISK_SCAN.test(command);
return [
"That command hit the shell time limit and its output was lost. Do not rerun it the same way.",
+ ...(scan ? [] : [UNKNOWN_OUTCOME]),
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_TEXT}) and keep it in the foreground until it exits. Split very long media jobs into shorter pieces.`,