Skip to content

graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs

Python

bash: cover #850's promotion path, and name the way to wait

justrachdcd8c393faba
diff --git a/src/exec_bash.zig b/src/exec_bash.zig
index c76e2797..db2a9be1 100644
--- a/src/exec_bash.zig
+++ b/src/exec_bash.zig
@@ -7,6 +7,7 @@
//! id. Subagents stay on the #93 kill-at-120s path (no TTY, no /jobs UI).
const std = @import("std");
+const builtin = @import("builtin");
const Io = std.Io;
const Allocator = std.mem.Allocator;
const Value = std.json.Value;
@@ -123,6 +124,34 @@ test "#850: a large explicit timeout cannot extend the foreground bound" {
try std.testing.expect(std.mem.indexOf(u8, schema, "max 36000000") == null);
}
+// The behavior half of #850: a wait bounded at the default promotes rather than
+// parking the turn, the child is NOT killed, and it stays reachable through the
+// same bash_output/bash_kill the auto-background result points the model at.
+// The bound itself is the pure-function assertion above; 200ms stands in for
+// the expiry so the test does not sleep for the real one.
+test "#850: promotion at the bound leaves the child alive and reachable" {
+ if (builtin.os.tag == .windows or builtin.os.tag == .wasi) return error.SkipZigTest;
+ jobs.g_jobs = .{};
+ const gpa = std.testing.allocator;
+ const io = std.testing.io;
+ const id = (try jobs.spawnJob(gpa, io, "sleep 5; printf never")).id;
+ defer jobs.jobsReap(gpa, io);
+ const waited = try jobs.waitForeground(gpa, io, id, 200);
+ defer switch (waited) {
+ .running => |r| gpa.free(r.output),
+ .done => |d| gpa.free(d.output),
+ .cancelled => |c| gpa.free(c.output),
+ };
+ try std.testing.expect(waited == .running);
+ try std.testing.expectEqual(id, waited.running.id);
+ const snap = try jobs.jobOutput(gpa, io, id, 0);
+ defer gpa.free(snap.text);
+ try std.testing.expect(std.mem.indexOf(u8, snap.text, "running") != null);
+ const killed = try jobs.jobKill(gpa, io, id);
+ defer gpa.free(killed.text);
+ try std.testing.expect(std.mem.indexOf(u8, killed.text, "killed") != null);
+}
+
test "rootWaitMs: lean unattended oneshot defaults to 15s; shorter timeout still wins" {
const main_mod = @import("main.zig");
const nlt = @import("no_local_tools.zig");
diff --git a/src/schema.zig b/src/schema.zig
index 61e77589..b7e43ace 100644
--- a/src/schema.zig
+++ b/src/schema.zig
@@ -55,7 +55,7 @@ pub const base_specs = [_]ToolSpec{
.name = "bash",
.desc = "Run a shell command via /bin/sh -c in the current working directory. Returns stdout, stderr, and the exit code. A user-cancelled command reports cancelled (its whole local process group is killed; a remote process started over ssh may survive on the remote host). Foreground commands that are still running after 120s (or a shorter timeout ms) are moved to the background and return a job id — the process keeps running. For long-running commands set run_in_background true to skip the wait. You are notified on completion — do not poll. bash_output(wait_ms>0) blocks until exit (up to 10h); omit wait_ms for a snapshot. Stop it with bash_kill. A background job that writes nothing and is read by nobody for 2 hours is stopped for inactivity and you are told; rerun it only if it is still needed (the user pins a long-lived server with /jobs keep).",
.schema =
- \\{"type": "object", "properties": {"command": {"type": "string", "description": "Shell command to execute"}, "timeout": {"type": "integer", "description": "Optional foreground wait in milliseconds before auto-background. A shorter value promotes earlier; a larger value cannot extend past the 120s (lean -p: 15s) bound. 0 uses the default. Ignored when run_in_background is true."}, "run_in_background": {"type": "boolean", "description": "Start as a background job and return its id immediately instead of waiting (default false)"}}, "required": ["command"]}
+ \\{"type": "object", "properties": {"command": {"type": "string", "description": "Shell command to execute"}, "timeout": {"type": "integer", "description": "Optional foreground wait in milliseconds before auto-background. A shorter value promotes earlier; a larger value cannot extend past the 120s (lean -p: 15s) bound — to wait for a genuinely long command, set run_in_background true and use bash_output(wait_ms>0), which blocks until exit (10h cap). 0 uses the default. Ignored when run_in_background is true."}, "run_in_background": {"type": "boolean", "description": "Start as a background job and return its id immediately instead of waiting (default false)"}}, "required": ["command"]}
,
},
.{