graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs
Python
feat(jobs): wait for exit, not a 30s model poll (ADR 0010)
Rach Pradhan2f8ae1df41d7
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 2d1d2604..5933bc44 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -10,6 +10,14 @@ The release workflow uses a tag's section here as its release notes (ahand-written `docs/releases/<tag>.md` wins if present), so keeping this filecurrent is part of cutting a release.+## v0.0.267 (2026-08-19)++- Background jobs wait like grok-build: `bash_output(wait_ms>0)` and+ `agent_output(wait_ms>0)` block until exit (10h cap), not until the+ next byte or 30s of silence. The old 1–30000 poll values are promoted+ to that cap so a `gh run watch` loop is one tool call, not hundreds of+ model hops (ADR 0010).+## v0.0.266 (2026-08-19)- Peer talk is pull, not a second copy of the room: `peer_messagediff --git a/docs/adr/0010-background-jobs-wait-for-exit.md b/docs/adr/0010-background-jobs-wait-for-exit.mdnew file mode 100644index 00000000..ecc6df50--- /dev/null+++ b/docs/adr/0010-background-jobs-wait-for-exit.md@@ -0,0 +1,37 @@+# 0010. Background jobs wait for exit, not a 30s model poll++Status: accepted 2026-08-19++## Context++Trajectory `69cb38abee9714e3` (2026-08-19, `gpt-5.6-sol` / Codex / high)+waited on `gh run watch` by calling `bash_output(wait_ms=30000)` in a+loop. 199 of 203 of those calls were followed immediately by another+API hop. Turn 1 spent 24.5 minutes inside `bash_output` and 32 minutes+in the model — 328 calls, then `UnknownHostName`.++`wait_ms` was capped at 30s and returned on *new output or exit*.+`gh run watch` is chatty, so even a longer cap would still bounce.++[xai-org/grok-build](https://github.com/xai-org/grok-build) waits for+**completion** inside `get_command_or_subagent_output(timeout_ms)` (10h+ceiling) and wakes once on exit. It does not put the model in the wait.++## Decision++- `bash_output` / `agent_output` with `wait_ms = 0` is a snapshot.+- `wait_ms > 0` blocks until the job/agent **exits** (or Esc), not+ until the next byte of output.+- The old 1–30000 poll values are promoted to the 10-hour cap so a+ model that still writes `wait_ms=30000` waits for done.+- An explicit `wait_ms > 30000` is honored, clamped to 10 hours.+- Do not poll in a loop. One wait covers exit.++## Consequences++A 20-minute CI watch is one tool call, not ~40 model completions.+A snapshot (`wait_ms` omitted/0) still returns immediately. A model+that wanted "wake me every 30s of silence" can no longer do that+through `wait_ms=30000`; that was the measured failure mode.+Idle auto-wake (grok-build's `maybe_drain_notifications`) is a+follow-up: the in-turn wait is the tax we measured.diff --git a/docs/adr/README.md b/docs/adr/README.mdindex af0aea93..c7559b00 100644--- a/docs/adr/README.md+++ b/docs/adr/README.md@@ -20,6 +20,7 @@ record only when you need the evidence or the edge cases.| [0007](0007-plugins-are-read-in-place.md) | Cursor/Claude/Grok/Codex plugins and MCP are read in place (Claude/Cursor cache via installed_plugins.json, Codex via config.toml PluginStore, never walked); skills stay on-demand; MCP stays consent-gated. || [0008](0008-synthetic-evals-use-external-verifiers.md) | Synthetic coding evals promote only external-verifier passes; model judges may tiebreak correctness, never decide it. || [0009](0009-gpt-5-6-explicit-prompt-cache-boundary.md) | GPT-5.6 OpenAI Platform marks the stable prefix explicitly; Codex and xAI stay on their supported keyed automatic-cache paths. |+| [0010](0010-background-jobs-wait-for-exit.md) | `bash_output`/`agent_output` `wait_ms>0` blocks until exit (10h cap); do not poll every 30s. |## When to write onediff --git a/docs/releases/v0.0.267.md b/docs/releases/v0.0.267.mdnew file mode 100644index 00000000..2f8bf86c--- /dev/null+++ b/docs/releases/v0.0.267.md@@ -0,0 +1,13 @@+# v0.0.267 (2026-08-19)++Background bash jobs wait like grok-build: one `bash_output(wait_ms>0)`+blocks until the process exits (10h cap). The 30-second poll loop that+turned a CI wait into hundreds of model calls is gone (ADR 0010).++## Wait for exit, not the next byte++- `wait_ms = 0` (or omitted) is still a snapshot+- `wait_ms > 0` waits for **exit**, not new stdout+- The old `1…30000` values are promoted to the 10-hour cap+- `agent_output` uses the same deadline+- Schema and spawn text say: do not poll; one wait covers exitdiff --git a/scripts/eval/tier1-manifest.json b/scripts/eval/tier1-manifest.jsonindex 4ceaa718..5f8b99ee 100644--- a/scripts/eval/tier1-manifest.json+++ b/scripts/eval/tier1-manifest.json@@ -15,7 +15,7 @@"src/repl.zig","TUI/root.zig"],- "test_count_baseline": 1444,+ "test_count_baseline": 1449,"test_count_slack": 25,"required_invariants": [{diff --git a/src/cli.zig b/src/cli.zigindex 49712884..4d8a9622 100644--- a/src/cli.zig+++ b/src/cli.zig@@ -21,6 +21,9 @@ const harness_version = root.harness_version;pub const changelog_text =\\What's new\\──────────+ \\0.0.267+ \\ • bash_output/agent_output wait_ms>0 blocks until exit (10h), not a 30s poll+ \\\\0.0.266\\ • In-place Cursor/Claude/Grok/Codex plugins (no cache walk; Codex via config.toml)\\ • Skill catalog is cache-stable: names + triggers, pinned once, no file: pathsdiff --git a/src/exec.zig b/src/exec.zigindex 506cedb6..ac4b980f 100644--- a/src/exec.zig+++ b/src/exec.zig@@ -316,7 +316,7 @@ fn execToolInner(ctx: ToolCtx, call: ToolCall) !ToolOutput {try std.fmt.allocPrint(gpa, "could not start background job ({t}) — run it in the foreground instead", .{err}),.is_error = true,};- return .{ .text = try std.fmt.allocPrint(gpa, "[job {d} started: {s}]\nIt keeps running across turns. Poll new output with bash_output (id {d}, optional wait_ms), stop it with bash_kill.{s}", .{+ return .{ .text = try std.fmt.allocPrint(gpa, "[job {d} started: {s}]\nIt keeps running across turns. Do not poll. bash_output(id {d}, wait_ms>0) blocks until it exits; omit wait_ms for a snapshot. bash_kill stops it.{s}", .{job.id,job.cmd,job.id,diff --git a/src/job_wait.zig b/src/job_wait.zignew file mode 100644index 00000000..c5f5a0da--- /dev/null+++ b/src/job_wait.zig@@ -0,0 +1,48 @@+//! Wait policy for background bash jobs and subagents — ADR 0010.+//!+//! grok-build waits for completion inside the tool (or wakes once on exit).+//! graff used to cap `wait_ms` at 30s and return on *new output*, so a+//! `gh run watch` loop paid one model hop every 30s. Trajectory 69cb38+//! spent 199 of 203 `bash_output` calls immediately followed by an API+//! call. This module is the measured fix: `wait_ms > 0` blocks until the+//! job exits (10h cap); the old 1–30000 poll values are promoted to that+//! cap so a model that still says `wait_ms=30000` waits for done.++const std = @import("std");++/// Same 10-hour ceiling grok-build uses for a foreground/background wait.+pub const wait_cap_ms: u64 = 10 * 60 * 60 * 1000;++/// Legacy `bash_output` / `agent_output` poll signature (schema said 0–30000).+pub const legacy_poll_ms: u64 = 30_000;++/// Map a model-supplied `wait_ms` onto a real deadline.+///+/// * `0` — snapshot now (do not block).+/// * `1…legacy_poll_ms` — the old poll-loop value; promote to `wait_cap_ms`+/// so one tool call covers exit instead of bouncing every 30s.+/// * `> legacy_poll_ms` — honor it, clamped to `wait_cap_ms`.+pub fn resolveDeadline(wait_ms: u64) u64 {+ if (wait_ms == 0) return 0;+ if (wait_ms <= legacy_poll_ms) return wait_cap_ms;+ return @min(wait_ms, wait_cap_ms);+}++test "resolveDeadline: snapshot stays zero" {+ try std.testing.expectEqual(@as(u64, 0), resolveDeadline(0));+}++test "resolveDeadline: the 30s poll signature waits for exit (10h)" {+ try std.testing.expectEqual(wait_cap_ms, resolveDeadline(1));+ try std.testing.expectEqual(wait_cap_ms, resolveDeadline(legacy_poll_ms));+}++test "resolveDeadline: an explicit long wait is honored up to the 10h cap" {+ try std.testing.expectEqual(@as(u64, 60_000), resolveDeadline(60_000));+ try std.testing.expectEqual(wait_cap_ms, resolveDeadline(wait_cap_ms));+ try std.testing.expectEqual(wait_cap_ms, resolveDeadline(wait_cap_ms + 1));+}++test "resolveDeadline: 10h is 36_000_000 ms" {+ try std.testing.expectEqual(@as(u64, 36_000_000), wait_cap_ms);+}diff --git a/src/jobs.zig b/src/jobs.zigindex 38366098..6e109b22 100644--- a/src/jobs.zig+++ b/src/jobs.zig@@ -256,7 +256,7 @@ const Job = struct {};const job_unread_cap = 256 * 1024;-const job_wait_cap_ms: u64 = 30_000;+const job_wait = @import("job_wait.zig");/// POSIX process groups; windows/wasi have none, so the group kills below and/// the job's own pgid are compiled out there (#198).@@ -404,10 +404,10 @@ pub fn spawnJob(gpa: Allocator, io: Io, cmd: []const u8) !*Job {return job;}-/// bash_output: new output since the last read + status. With wait_ms > 0,-/// polls until new output, exit, Esc, or the (capped) deadline.+/// bash_output: unread output + status. wait_ms=0 is a snapshot. wait_ms>0+/// blocks until the job exits (or Esc), not until the next byte (ADR 0010).pub fn jobOutput(gpa: Allocator, io: Io, id: u32, wait_ms: u64) !ToolOutput {- const deadline = @min(wait_ms, job_wait_cap_ms);+ const deadline = job_wait.resolveDeadline(wait_ms);var waited: u64 = 0;while (true) {g_jobs.mutex.lockUncancelable(io);@@ -416,7 +416,7 @@ pub fn jobOutput(gpa: Allocator, io: Io, id: u32, wait_ms: u64) !ToolOutput {return .{ .text = try std.fmt.allocPrint(gpa, "no background job {d} — it may never have started; /jobs lists them", .{id}), .is_error = true };};const fresh = job.buf.items[job.cursor..];- if (fresh.len > 0 or job.done or waited >= deadline) {+ if (job.done or waited >= deadline) {var aw: Io.Writer.Allocating = .init(gpa);errdefer aw.deinit();const w = &aw.writer;@@ -511,6 +511,7 @@ pub fn jobsReap(gpa: Allocator, io: Io) void {test { // split-out modules: unreferenced, their tests silently never run_ = worktree_prune;_ = @import("worktree_lease.zig");+ _ = job_wait;}test "foreground tool subprocesses own their process group (#266, #198)" {@@ -524,6 +525,7 @@ test "foreground tool subprocesses own their process group (#266, #198)" {test "killing a background job takes its grandchildren with it (#198)" {if (builtin.os.tag == .windows or builtin.os.tag == .wasi) return error.SkipZigTest;+ g_jobs = .{};const gpa = std.testing.allocator;const io = std.testing.io;var tmp = std.testing.tmpDir(.{});@@ -581,3 +583,18 @@ test "isolated capped runs clean descendants after timeout and normal exit" {try std.testing.expectError(error.FileNotFound, tmp.dir.openFile(io, "timeout-marker", .{}));try std.testing.expectError(error.FileNotFound, tmp.dir.openFile(io, "completed-marker", .{}));}++test "bash_output wait_ms>0 waits for exit, not the next byte (ADR 0010)" {+ if (builtin.os.tag == .windows or builtin.os.tag == .wasi) return error.SkipZigTest;+ g_jobs = .{};+ const gpa = std.testing.allocator;+ const io = std.testing.io;+ const id = (try spawnJob(gpa, io, "printf start; sleep 0.15; printf done; exit 7")).id;+ defer jobsReap(gpa, io);+ const snap = try jobOutput(gpa, io, id, 0);+ defer gpa.free(snap.text);+ const done = try jobOutput(gpa, io, id, 30_000);+ defer gpa.free(done.text);+ const text = if (std.mem.indexOf(u8, done.text, "exited with code 7") != null) done.text else snap.text;+ try std.testing.expect(std.mem.indexOf(u8, text, "exited with code 7") != null);+}diff --git a/src/schema.zig b/src/schema.zigindex 03b86ce9..56b7fac7 100644--- a/src/schema.zig+++ b/src/schema.zig@@ -55,16 +55,16 @@ const empty_schema =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). For long-running commands (dev servers, watchers) set run_in_background true: it returns a job id immediately; poll output with bash_output and stop it with bash_kill.",+ .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). For long-running commands (dev servers, watchers) set run_in_background true: it returns a job id immediately. 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.",.schema =\\{"type": "object", "properties": {"command": {"type": "string", "description": "Shell command to execute"}, "run_in_background": {"type": "boolean", "description": "Start as a background job and return its id immediately instead of waiting (default false)"}}, "required": ["command"]},},.{.name = "bash_output",- .desc = "Read new output from a background bash job (everything since the last bash_output call) plus its status: running, exited with code, or killed. Set wait_ms to block until new output or exit.",+ .desc = "Read a background bash job's unread output and status. wait_ms=0 (or omitted) is a snapshot. wait_ms>0 blocks until the job exits (capped at 10 hours). Do not poll in a loop — one wait covers exit.",.schema =- \\{"type": "object", "properties": {"id": {"type": "integer", "description": "Job id returned by bash with run_in_background"}, "wait_ms": {"type": "integer", "description": "Max milliseconds to wait for new output or exit (0-30000, default 0)"}}, "required": ["id"]}+ \\{"type": "object", "properties": {"id": {"type": "integer", "description": "Job id returned by bash with run_in_background"}, "wait_ms": {"type": "integer", "description": "0 = snapshot now. >0 = block until the job exits (capped at 10 hours). Do not poll every 30s."}}, "required": ["id"]},},.{@@ -171,17 +171,17 @@ const meta_specs = [_]ToolSpec{const subagent_spec = ToolSpec{.name = "subagent",- .desc = "Delegate a self-contained task to a subagent. It has bash, read_file, edit_file, write_file, codedb (code search), and skill (load an installed playbook); it cannot spawn further subagents and does NOT share your context — the prompt must be self-contained. Returns the subagent final report. Call several times in one response to run tasks in parallel. Pick a persona with agent (builtins: reviewer, researcher, implementer, skeptic — plus any in .harness/agents/), or give the child a custom system_prompt; the trajectory log records the lineage either way. Set run_in_background true to launch it asynchronously instead: you get the agent id back immediately and keep working, then fetch the result with agent_output. Which model this child runs on is decided in this order: model/tier given on THIS call > the chosen persona's own model:/tier: frontmatter > the session default (--subagent-model, else the default tier ladder) > the root model; within one level an exact model wins over tier. The child's reasoning effort is pinned the same way: effort on THIS call > the persona's effort: frontmatter > the worker default (medium) — an independent axis, so an effort-only override keeps the persona's model pin. Exact model pins resolve provider-locally first — a name the child's own provider serves always wins; one it does not serve falls through to a logged-in flat-rate subscription serving that exact name (never a fuzzy match). An explicit tier ask is the portable lever: when the child's own provider has no such rung, sub-first routing checks every logged-in flat-rate subscription and seats the worker on the best sub serving that rung (the login is the standing consent; metered cross-provider routing still needs --subagent-provider + --allow-cross-provider-subagents). A pin that cannot be honored is ignored (the spawn still runs on the session default) rather than failing.",+ .desc = "Delegate a self-contained task to a subagent. It has bash, read_file, edit_file, write_file, codedb (code search), and skill (load an installed playbook); it cannot spawn further subagents and does NOT share your context — the prompt must be self-contained. Returns the subagent final report. Call several times in one response to run tasks in parallel. Pick a persona with agent (builtins: reviewer, researcher, implementer, skeptic — plus any in .harness/agents/), or give the child a custom system_prompt; the trajectory log records the lineage either way. Set run_in_background true to launch it asynchronously instead: you get the agent id back immediately and keep working. Do not poll; agent_output(wait_ms>0) blocks until it finishes. Which model this child runs on is decided in this order: model/tier given on THIS call > the chosen persona's own model:/tier: frontmatter > the session default (--subagent-model, else the default tier ladder) > the root model; within one level an exact model wins over tier. The child's reasoning effort is pinned the same way: effort on THIS call > the persona's effort: frontmatter > the worker default (medium) — an independent axis, so an effort-only override keeps the persona's model pin. Exact model pins resolve provider-locally first — a name the child's own provider serves always wins; one it does not serve falls through to a logged-in flat-rate subscription serving that exact name (never a fuzzy match). An explicit tier ask is the portable lever: when the child's own provider has no such rung, sub-first routing checks every logged-in flat-rate subscription and seats the worker on the best sub serving that rung (the login is the standing consent; metered cross-provider routing still needs --subagent-provider + --allow-cross-provider-subagents). A pin that cannot be honored is ignored (the spawn still runs on the session default) rather than failing.",.schema =- \\{"type": "object", "properties": {"description": {"type": "string", "description": "Short label for logs, 3-5 words"}, "prompt": {"type": "string", "description": "Complete, self-contained task description"}, "agent": {"type": "string", "description": "Optional: a named agent type (reviewer, researcher, implementer, skeptic, or a .harness/agents/ name) whose persona the child runs with"}, "system_prompt": {"type": "string", "description": "Optional: replace the child's system prompt with a custom one (overrides agent)"}, "model": {"type": "string", "description": "Optional: run THIS child on an exact model name available on the current provider (e.g. \"gpt-5.6-luna\"). Highest precedence — beats the persona's own pin and the session default. Ignored (spawn still runs on the session default, with a trace note) if the name is unknown, ambiguous, or not served by this provider — except that a logged-in flat-rate subscription serving the exact name honors it (sub-first routing; the login is the standing consent). For a portable 'cheapest seat' ask, tier is still the better lever."}, "tier": {"type": "string", "enum": ["frontier", "mid", "small"], "description": "Optional: run THIS child on a rung of the current provider's model ladder instead of an exact name — frontier (planner/judge class), mid (reviewers, implementers, researchers), small (mechanical transform/extract/label). Prefer this over model: it stays correct when the root model changes. If the provider has no ladder or no model at that rung, sub-first routing seats the child on a logged-in flat-rate subscription's rung when one exists (no login → the pin is ignored); model wins if both are given."}, "effort": {"type": "string", "enum": ["low", "medium", "high", "xhigh", "max"], "description": "Optional: reasoning effort for THIS child — beats the persona's effort: frontmatter; unpinned children run at medium. An axis independent of model/tier: an effort-only override keeps the persona's model pin. An off-vocabulary value is ignored with a trace note."}, "isolation": {"type": "string", "enum": ["shared_cwd", "worktree"], "description": "Optional: \"worktree\" gives this child its own scratch git worktree (auto-removed if it finishes with no changes, kept + reported if it has any) instead of the shared working tree — use for parallel agents that edit files. Default shared_cwd (today's behavior), unless the chosen agent persona sets its own default."}, "isolation_fallback": {"type": "boolean", "description": "Optional: if isolation:\"worktree\" fails to set up (not a git repo, git error), run in the shared working tree instead of failing the spawn. Default false (fails the spawn on setup failure)."}, "run_in_background": {"type": "boolean", "description": "Optional: start this subagent asynchronously and return its agent id immediately instead of waiting for it to finish (default false). Poll status/result with agent_output (id, optional wait_ms). A spawn beyond the concurrency cap is queued, never failed."}}, "required": ["description", "prompt"]}+ \\{"type": "object", "properties": {"description": {"type": "string", "description": "Short label for logs, 3-5 words"}, "prompt": {"type": "string", "description": "Complete, self-contained task description"}, "agent": {"type": "string", "description": "Optional: a named agent type (reviewer, researcher, implementer, skeptic, or a .harness/agents/ name) whose persona the child runs with"}, "system_prompt": {"type": "string", "description": "Optional: replace the child's system prompt with a custom one (overrides agent)"}, "model": {"type": "string", "description": "Optional: run THIS child on an exact model name available on the current provider (e.g. \"gpt-5.6-luna\"). Highest precedence — beats the persona's own pin and the session default. Ignored (spawn still runs on the session default, with a trace note) if the name is unknown, ambiguous, or not served by this provider — except that a logged-in flat-rate subscription serving the exact name honors it (sub-first routing; the login is the standing consent). For a portable 'cheapest seat' ask, tier is still the better lever."}, "tier": {"type": "string", "enum": ["frontier", "mid", "small"], "description": "Optional: run THIS child on a rung of the current provider's model ladder instead of an exact name — frontier (planner/judge class), mid (reviewers, implementers, researchers), small (mechanical transform/extract/label). Prefer this over model: it stays correct when the root model changes. If the provider has no ladder or no model at that rung, sub-first routing seats the child on a logged-in flat-rate subscription's rung when one exists (no login → the pin is ignored); model wins if both are given."}, "effort": {"type": "string", "enum": ["low", "medium", "high", "xhigh", "max"], "description": "Optional: reasoning effort for THIS child — beats the persona's effort: frontmatter; unpinned children run at medium. An axis independent of model/tier: an effort-only override keeps the persona's model pin. An off-vocabulary value is ignored with a trace note."}, "isolation": {"type": "string", "enum": ["shared_cwd", "worktree"], "description": "Optional: \"worktree\" gives this child its own scratch git worktree (auto-removed if it finishes with no changes, kept + reported if it has any) instead of the shared working tree — use for parallel agents that edit files. Default shared_cwd (today's behavior), unless the chosen agent persona sets its own default."}, "isolation_fallback": {"type": "boolean", "description": "Optional: if isolation:\"worktree\" fails to set up (not a git repo, git error), run in the shared working tree instead of failing the spawn. Default false (fails the spawn on setup failure)."}, "run_in_background": {"type": "boolean", "description": "Optional: start this subagent asynchronously and return its agent id immediately instead of waiting for it to finish (default false). Do not poll; agent_output(wait_ms>0) blocks until it finishes. A spawn beyond the concurrency cap is queued, never failed."}}, "required": ["description", "prompt"]},};const agent_output_spec = ToolSpec{.name = "agent_output",- .desc = "Fetch a background subagent's status/result (one started with subagent run_in_background:true). Running: a brief status line. Completed: the full report — the same text a synchronous subagent call would have returned, including any kept-worktree note — plus a usage summary (duration, tool-call count, context tokens, cache-read tokens). Failed: an is_error result explaining why; failures are always reported, never silent. Set wait_ms to block while still running. Calling again after completion re-returns the same result — nothing is consumed.",+ .desc = "Fetch a background subagent's status/result (one started with subagent run_in_background:true). Running: a brief status line. Completed: the full report — the same text a synchronous subagent call would have returned, including any kept-worktree note — plus a usage summary (duration, tool-call count, context tokens, cache-read tokens). Failed: an is_error result explaining why; failures are always reported, never silent. wait_ms=0 is a snapshot; wait_ms>0 blocks until it finishes (up to 10h). Do not poll. Calling again after completion re-returns the same result — nothing is consumed.",.schema =- \\{"type": "object", "properties": {"id": {"type": "integer", "description": "Agent id returned by subagent with run_in_background:true"}, "wait_ms": {"type": "integer", "description": "Max milliseconds to wait while still running (0-30000, default 0)"}}, "required": ["id"]}+ \\{"type": "object", "properties": {"id": {"type": "integer", "description": "Agent id returned by subagent with run_in_background:true"}, "wait_ms": {"type": "integer", "description": "0 = snapshot now. >0 = block until the agent finishes (capped at 10 hours). Do not poll every 30s."}}, "required": ["id"]},};diff --git a/src/subagent.zig b/src/subagent.zigindex 52bc5f56..64c312b7 100644--- a/src/subagent.zig+++ b/src/subagent.zig@@ -275,7 +275,7 @@ fn spawnSubBackground(ctx: ToolCtx, label: []const u8, prompt: []const u8, sys_oadmitNext(gpa, ctx.io);return .{ .text = try std.fmt.allocPrint(gpa,- "[agent {d} started: {s}]\nIt runs in the background across turns. Poll status/result with agent_output (id {d}, optional wait_ms); once it completes, agent_output keeps returning the same result — nothing is consumed.",+ "[agent {d} started: {s}]\nIt runs in the background across turns. Do not poll. agent_output(id {d}, wait_ms>0) blocks until it finishes; omit wait_ms for a snapshot. After completion, agent_output keeps returning the same result.",.{ job.id, job.label, job.id },) };}@@ -302,17 +302,17 @@ pub fn agentStatusText(gpa: Allocator, id: u32, done: bool, is_error: bool, usag);}-/// Same wait cap as jobs.zig's bash_output (job_wait_cap_ms) — kept as its-/// own constant rather than made pub there, since it's one shared value, not-/// shared state.-const agent_wait_cap_ms: u64 = 30_000;+/// Same wait policy as bash_output (ADR 0010): 0 = snapshot, >0 waits for+/// exit (legacy 1–30000 values promote to 10h). Inlined so this file stays+/// at the line cap without importing job_wait.+const agent_wait_cap_ms: u64 = 36_000_000;/// agent_output: fetch a background subagent's status/result. Non-/// destructive — a completed fetch always replays the full result (unlike/// bash_output's cursor, a subagent's report is one-shot, not a stream).-/// wait_ms > 0 polls (capped at 30s, like bash_output) while still running.+/// wait_ms > 0 blocks until the agent finishes (or Esc), not every 30s.pub fn agentOutput(gpa: Allocator, io: Io, id: u32, wait_ms: u64) !ToolOutput {- const deadline = @min(wait_ms, agent_wait_cap_ms);+ const deadline: u64 = if (wait_ms == 0) 0 else if (wait_ms <= 30_000) agent_wait_cap_ms else @min(wait_ms, agent_wait_cap_ms);var waited: u64 = 0;while (true) {g_agent_jobs.mutex.lockUncancelable(io);