graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs
Python
Resume the session when a background command exits
justrach03b27cc86280
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 5091ddfb..77038d41 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -12,6 +12,7 @@ current is part of cutting a release.## v0.0.302.4+- A background command that exits resumes the same session with its exit status and output, instead of waiting for another message (#1154).- Composer send/stop stays a circle: more inset so the 32px corner no longer clips it into a square (#1152).- New chat stays in the folder already open, on the desktop and through ACP. Worktrees and other GUI workspace changes have to match the ACP session; that rule is in AGENTS.md and docs/notices.- GUI transcript drag-selection paints, and each message has a copy icon at the bottom.diff --git a/TUI/turn.zig b/TUI/turn.zigindex e295700e..96bb049a 100644--- a/TUI/turn.zig+++ b/TUI/turn.zig@@ -74,7 +74,7 @@ pub fn maybeJobWake(self: *Model) void {if (self.pending != null or self.bg != null) return;if (self.input.getValue().len > 0 or self.images.items.len > 0 or self.steer_queue.items.len > 0) return;const f = engine.g_idle_wake_fn orelse return;- var buf: [512]u8 = undefined;+ var buf: [4096]u8 = undefined;const text = f(engine.g_turn_ctx, &buf) orelse return;self.push(.system, text) catch return;self.history.items[self.history.items.len - 1].notification = true;diff --git a/apps/native/app/api/acp/route.ts b/apps/native/app/api/acp/route.tsindex c6f71321..cdca769a 100644--- a/apps/native/app/api/acp/route.ts+++ b/apps/native/app/api/acp/route.ts@@ -17,7 +17,7 @@ import { rememberAnswer, validateAnswer } from "@/lib/ask-answer";import { formatTermination, recordTermination, type TerminateReason } from "@/lib/acp-terminate";import { bindSessionCwd, initializeWorker, serializeBootstrap } from "@/lib/acp-bootstrap";import { finishCancelledPrompt } from "@/lib/acp-cancel";-import { armIdle, cancelIdle, forgetPark, forgetParkMatching, keepPark, parkedChats, takeParked, type ParkedWorker } from "@/lib/acp-idle";+import { armIdle, cancelIdle, forgetPark, forgetParkMatching, keepPark, parkNow, parkedChats, takeParked, type ParkedWorker } from "@/lib/acp-idle";export const runtime = "nodejs";export const dynamic = "force-dynamic";@@ -198,7 +198,9 @@ function spawnAgent(chat: string, opts: SpawnOpts): Slot {slot.spawnError = err;});child.on("exit", () => {- if (slots.get(chat) === slot && !slot.restart) slots.delete(chat);+ if (slots.get(chat) !== slot || slot.restart) return;+ slots.delete(chat);+ parkNow(chat, parkSnapshot(slot));});slots.set(chat, slot);try { attachmentStore().enrollSession(imageScope, child.pid); }diff --git a/apps/native/components/site/idle-peer-turns.ts b/apps/native/components/site/idle-peer-turns.tsindex 85144213..63e26db8 100644--- a/apps/native/components/site/idle-peer-turns.ts+++ b/apps/native/components/site/idle-peer-turns.ts@@ -1,6 +1,6 @@import { applyAcpUpdate, emptyTurn, finishAcpTurn, type AssistantTurn } from "@/lib/acp";import { idleUpdates, type ChatHandle } from "@/lib/acp-client";-import { holdWhileIdle, waitWhile } from "@/lib/idle-http";+import { holdIdleUntilAbort } from "@/lib/idle-http";import type { Chat } from "./harness-types";/** Paint unsolicited ACP session/update while the page is idle (#1007).@@ -43,18 +43,13 @@ export async function pumpIdlePeerTurns(opts: {}));};- while (!opts.signal.aborted) {- await waitWhile(() => opts.running(), opts.signal);- if (opts.signal.aborted) return;- const result = await holdWhileIdle({- signal: opts.signal,- busy: opts.running,- open: async (signal) => {- for await (const update of idleUpdates(opts.handle, opts.sessionId, signal)) {- paint(update);- }- },- });- if (result !== "paused") return;- }+ await holdIdleUntilAbort({+ signal: opts.signal,+ busy: opts.running,+ open: async (signal) => {+ for await (const update of idleUpdates(opts.handle, opts.sessionId, signal)) {+ paint(update);+ }+ },+ });}diff --git a/apps/native/lib/acp-idle.test.ts b/apps/native/lib/acp-idle.test.tsindex d4866e3e..00305fce 100644--- a/apps/native/lib/acp-idle.test.ts+++ b/apps/native/lib/acp-idle.test.ts@@ -8,11 +8,13 @@ afterEach(() => {delete process.env.GRAFF_ACP_IDLE_MS;});-test("idleMs defaults to 30s and 0 disables parking", () => {+test("idleMs defaults to 0 so an open GUI tab is not parked", () => {delete process.env.GRAFF_ACP_IDLE_MS;- expect(idleMs()).toBe(30_000);+ expect(idleMs()).toBe(0);process.env.GRAFF_ACP_IDLE_MS = "0";expect(idleMs()).toBe(0);+ process.env.GRAFF_ACP_IDLE_MS = "40000";+ expect(idleMs()).toBe(40_000);});test("keepPark is only true, never an Array.map index", () => {@@ -34,6 +36,15 @@ test("armIdle parks a snapshot after the quiet period", async () => {expect(parkCount()).toBe(0);});+test("unset GRAFF_ACP_IDLE_MS never parks an open tab", async () => {+ delete process.env.GRAFF_ACP_IDLE_MS;+ let killed = 0;+ armIdle("idle-test", { resume: "session-open", model: null, cwd: "/tmp", yolo: true, mcp: false }, () => { killed += 1; });+ await new Promise(resolve => setTimeout(resolve, 40));+ expect(killed).toBe(0);+ expect(takeParked("idle-test")).toBeUndefined();+});+test("GRAFF_ACP_IDLE_MS=0 never parks", async () => {process.env.GRAFF_ACP_IDLE_MS = "0";let killed = 0;diff --git a/apps/native/lib/acp-idle.ts b/apps/native/lib/acp-idle.tsindex baf0094b..23aa4ad0 100644--- a/apps/native/lib/acp-idle.ts+++ b/apps/native/lib/acp-idle.ts@@ -1,5 +1,7 @@-/** Park an idle `graff acp` child after a quiet period. The session file- * stays on disk; the next bootstrap respawns with `--resume`.+/** Park an idle `graff acp` child after a quiet period. Off by default:+ * an open GUI tab keeps its worker so a background command can still+ * resume the turn when it exits. Set `GRAFF_ACP_IDLE_MS` to shed it;+ * the session file stays on disk and the next bootstrap uses `--resume`.** Do not park while a prompt, session/idle subscriber, or other busy* callback is live — stream close alone is not ownership of background work. */@@ -21,9 +23,9 @@ const parked = (g.__graffAcpParked ??= new Map());export function idleMs(): number {const raw = process.env.GRAFF_ACP_IDLE_MS;- if (raw === undefined || raw === "") return 30_000;+ if (raw === undefined || raw === "") return 0;const n = Number(raw);- if (!Number.isFinite(n) || n < 0) return 30_000;+ if (!Number.isFinite(n) || n < 0) return 0;return n;}@@ -58,6 +60,13 @@ export function takeParked(chat: string): ParkedWorker | undefined {return held;}+/** Keep a crashed or otherwise-exited worker resumable. Dispose/reset still+ * call forgetPark so a closed tab does not come back. */+export function parkNow(chat: string, snapshot: ParkedWorker): void {+ cancelIdle(chat);+ if (snapshot.resume) parked.set(chat, snapshot);+}+export function armIdle(chat: string, snapshot: ParkedWorker, kill: () => void, busy?: () => boolean): void {cancelIdle(chat);const wait = idleMs();diff --git a/apps/native/lib/idle-http.test.ts b/apps/native/lib/idle-http.test.tsindex 72c3bc88..87fb4c9f 100644--- a/apps/native/lib/idle-http.test.ts+++ b/apps/native/lib/idle-http.test.ts@@ -1,6 +1,6 @@import { test } from "node:test";import assert from "node:assert/strict";-import { holdWhileIdle, waitWhile } from "./idle-http.ts";+import { holdIdleUntilAbort, holdWhileIdle, waitWhile } from "./idle-http.ts";test("waitWhile returns immediately when idle", async () => {const ac = new AbortController();@@ -51,3 +51,20 @@ test("holdWhileIdle reports ended when the stream finishes while idle", async ()open: async () => {},}), "ended");});++test("holdIdleUntilAbort reopens after a dead ACP ends the stream", async () => {+ const ac = new AbortController();+ let opened = 0;+ const pumping = holdIdleUntilAbort({+ signal: ac.signal,+ busy: () => false,+ retryDelayMs: 10,+ pollMs: 10,+ open: async () => {+ opened += 1;+ if (opened >= 2) ac.abort();+ },+ });+ await pumping;+ assert.ok(opened >= 2);+});diff --git a/apps/native/lib/idle-http.ts b/apps/native/lib/idle-http.tsindex 54abb81d..e9ae276d 100644--- a/apps/native/lib/idle-http.ts+++ b/apps/native/lib/idle-http.ts@@ -50,3 +50,39 @@ export async function holdWhileIdle(opts: {if (opts.busy() || hold.signal.aborted) return "paused";return "ended";}++export function waitMs(ms: number, signal: AbortSignal): Promise<void> {+ return new Promise((resolve) => {+ if (signal.aborted || ms <= 0) {+ resolve();+ return;+ }+ const done = () => {+ clearTimeout(timer);+ signal.removeEventListener("abort", done);+ resolve();+ };+ const timer = setTimeout(done, ms);+ signal.addEventListener("abort", done, { once: true });+ });+}++/** Keep the idle pump open for the tab's lifetime. A dead ACP ends the+ * stream; retry so `session/idle` can spawn it again instead of going+ * silent until the next human prompt. */+export async function holdIdleUntilAbort(opts: {+ signal: AbortSignal;+ busy(): boolean;+ open(signal: AbortSignal): Promise<void>;+ pollMs?: number;+ retryDelayMs?: number;+}): Promise<void> {+ while (!opts.signal.aborted) {+ await waitWhile(() => opts.busy(), opts.signal, opts.pollMs);+ if (opts.signal.aborted) return;+ const result = await holdWhileIdle(opts);+ if (result === "aborted") return;+ if (result === "paused") continue;+ await waitMs(opts.retryDelayMs ?? 250, opts.signal);+ }+}diff --git a/src/acp.zig b/src/acp.zigindex 72488480..5b980e83 100644--- a/src/acp.zig+++ b/src/acp.zig@@ -173,11 +173,20 @@ pub fn handleLine(d: *Dispatch, arena: Allocator, w: *Io.Writer, line: []const uconst LiveTurn = @import("acp_live_turn.zig").LiveTurn;+var acp_inbox_nudge: ?*@import("acp_inbox.zig").Inbox = null;++fn nudgeAcp() void {+ if (acp_inbox_nudge) |inbox| inbox.nudge();+}+pub fn runAcpCommand(gpa: Allocator, io: Io, environ_map: anytype, root: *agent_mod.Agent, keys: *provider_mod.Keys, client: *std.http.Client, in: *Io.Reader, out: *Io.Writer, arena: Allocator, flags: args.Flags) !bool {if (!(flags.positionals.items.len > 0 and std.mem.eql(u8, flags.positionals.items[0], "acp"))) return false;_ = environ_map;_ = client;main_mod.unattended = true;+ // GUI is an interactive root (ADR 0154): park long shells and resume on exit.+ @import("subagent_interactive.zig").configure(true);+ defer @import("subagent_interactive.zig").configure(false);root.in = null;root.out = null; // not stream_quiet: that forces SSE and misses resume cachemain_mod.g_out = null;@@ -187,6 +196,13 @@ pub fn runAcpCommand(gpa: Allocator, io: Io, environ_map: anytype, root: *agent_var inbox: @import("acp_inbox.zig").Inbox = .{ .gpa = gpa, .io = io, .reader = in };try inbox.start();defer inbox.deinit();+ acp_inbox_nudge = &inbox;+ const prev_queued = @import("job_notify.zig").on_queued;+ @import("job_notify.zig").on_queued = nudgeAcp;+ defer {+ @import("job_notify.zig").on_queued = prev_queued;+ acp_inbox_nudge = null;+ }@import("acp_ask.zig").attach(io, gpa);defer @import("acp_ask.zig").detach();var live: LiveTurn = .{ .root = root, .keys = keys, .out = out, .inbox = &inbox };diff --git a/src/acp_idle.zig b/src/acp_idle.zigindex f99a89ee..55d86059 100644--- a/src/acp_idle.zig+++ b/src/acp_idle.zig@@ -16,8 +16,12 @@ pub fn maybeWake(d: *engine.Dispatch, arena: Allocator, w: *Io.Writer, io: Io, sconst sid = d.session_id orelse return;if (sid.len == 0) return;if (peer_idle.isBusy()) return; // in-flight prompt is not preempted (#1136)- var buf: [512]u8 = undefined;+ var buf: [4096]u8 = undefined;const wake = idle_wake.takeIdleWake(io, session_name, &buf) orelse return;+ const interactive = @import("subagent_interactive.zig");+ const was_notice = interactive.line_notice;+ interactive.line_notice = true;+ defer interactive.line_notice = was_notice;try promptWake(d, arena, w, wake);}@@ -86,6 +90,30 @@ test "#1136 maybeWake is silent while a root turn is in flight" {peer_idle.noteTurnEnd();}+test "#1154 a finished background job starts an ACP turn with its output" {+ peer_inbox.resetForTest();+ peer_idle.resetForTest();+ defer {+ peer_inbox.resetForTest();+ peer_idle.resetForTest();+ }+ const notify = @import("job_notify.zig");+ const io = std.testing.io;+ var scratch: [4096]u8 = undefined;+ while (notify.takeIdleWake(io, &scratch)) |_| {}+ notify.queue(io, 4, 0, false, "zig build test", false, "1/1 passed");+ var arena = std.heap.ArenaAllocator.init(std.testing.allocator);+ defer arena.deinit();+ var buf: [2048]u8 = undefined;+ var w: Io.Writer = .fixed(&buf);+ var d: engine.Dispatch = .{ .turn = echoTurn, .ctx = undefined, .session_id = "s1" };+ try maybeWake(&d, arena.allocator(), &w, io, "s1");+ const out = w.buffered();+ try std.testing.expect(std.mem.indexOf(u8, out, "echo:[job 4 exited 0: zig build test]") != null);+ try std.testing.expect(std.mem.indexOf(u8, out, "1/1 passed") != null);+ try std.testing.expect(std.mem.indexOf(u8, out, "gui_turn_end") != null);+}+test "#1007 maybeWake is silent without a session or mail" {peer_inbox.resetForTest();peer_idle.resetForTest();diff --git a/src/acp_inbox.zig b/src/acp_inbox.zigindex e7924237..cb8bcbb6 100644--- a/src/acp_inbox.zig+++ b/src/acp_inbox.zig@@ -71,6 +71,16 @@ pub const Inbox = struct {return null;}+ /// A finished background job wants a turn now. Safe from the pump thread:+ /// it only sets the tick the idle loop already drains.+ pub fn nudge(self: *Inbox) void {+ self.mutex.lockUncancelable(self.io);+ defer self.mutex.unlock(self.io);+ if (self.eof) return;+ self.tick = true;+ self.ready.broadcast(self.io);+ }+/// Called after prepareRootTurn, under the same lock as incoming cancel.pub fn begin(self: *Inbox) void {self.mutex.lockUncancelable(self.io);diff --git a/src/exec_bash.zig b/src/exec_bash.zigindex b4567e18..0b2bd64d 100644--- a/src/exec_bash.zig+++ b/src/exec_bash.zig@@ -81,7 +81,7 @@ fn startedText(gpa: Allocator, id: u32, cmd: []const u8, ssh: bool, auto_bg: booif (@import("job_wait.zig").followup_pending.load(.acquire)) {try w.print("Follow-up received while this was running; it was moved to the background so you can talk. Process is still running as job {d}. You are notified on exit — do not poll. action=output is a snapshot; action=kill stops it.", .{id});} else if (auto_bg) {- try w.print("Command exceeded the {d}s foreground wait and was automatically moved to the background. Process is still running as job {d}. You are notified on exit — do not poll. action=output is a snapshot; leave it on /jobs or action=kill it.", .{ wait_s, id });+ try w.print("Command exceeded the {d}s foreground wait and was automatically moved to the background. Process is still running as job {d}. You are notified on exit with the status and output — do not poll. action=output is a snapshot; leave it on /jobs or action=kill it.", .{ wait_s, id });} else {try w.print("This is a persistent server. It runs in the background across turns. You are notified on exit — do not poll. action=output id {d} reads unread output. action=kill stops it.", .{id});}diff --git a/src/job_notify.zig b/src/job_notify.zigindex db6c4abc..790c76de 100644--- a/src/job_notify.zig+++ b/src/job_notify.zig@@ -10,6 +10,9 @@ const engine_sink = @import("engine_sink.zig");const tool_pulse = @import("tool_pulse.zig");const Agent = agent_mod.Agent;+/// Tail kept on the notice so an idle wake can continue without polling (#1154).+const output_cap: usize = 3072;+pub const Notice = struct {id: u32,exit_code: ?u8 = null,@@ -17,8 +20,16 @@ pub const Notice = struct {idle: bool = false, // the idle policy stopped it (#199): no auto-turn wakepreview: [48]u8 = undefined,preview_len: u8 = 0,+ output: [output_cap]u8 = undefined,+ output_len: u16 = 0,+ output_truncated: bool = false,};+/// ACP (and any other idle loop) sets this so a finished job wakes the+/// session immediately, not only on the next poll. Must not re-enter jobs+/// or this module: the pump may still hold the jobs mutex.+pub var on_queued: ?*const fn () void = null;+const cap: usize = 16;var mu: Io.Mutex = .init;var ring: [cap]Notice = undefined;@@ -52,28 +63,53 @@ pub fn line(buf: []u8, n: Notice) []const u8 {return std.fmt.bufPrint(buf, "[job {d} ended: {s}]", .{ n.id, cmd }) catch buf[0..0];}+fn clipOutput(src: []const u8) struct { buf: [output_cap]u8, len: u16, truncated: bool } {+ var buf: [output_cap]u8 = undefined;+ if (src.len <= output_cap) {+ @memcpy(buf[0..src.len], src);+ return .{ .buf = buf, .len = @intCast(src.len), .truncated = false };+ }+ @memcpy(buf[0..output_cap], src[src.len - output_cap ..]);+ return .{ .buf = buf, .len = output_cap, .truncated = true };+}+fn wakeLine(buf: []u8, n: Notice) []const u8 {var head: [96]u8 = undefined;const h = line(&head, n);if (n.idle) return std.fmt.bufPrint(buf, "{s} — silent and unread past the idle stop; rerun it only if it is still needed.", .{h}) catch h;- return std.fmt.bufPrint(buf, "{s} — unread output via shell action=output; do not poll.", .{h}) catch h;+ const out = n.output[0..n.output_len];+ const body: []const u8 = if (out.len == 0) "(no output)" else out;+ const note: []const u8 = if (n.output_truncated) "\n[older output omitted]" else "";+ return std.fmt.bufPrint(buf, "{s}\n{s}{s}\nContinue the task from this result. do not poll.", .{ h, body, note }) catch h;}/// Standalone notification convenience (tests). The job pump MUST split/// queue (under jobs mutex) from publish (outside it); calling this after/// exposing done reintroduces #728. Publication is UI, not a model wake.pub fn record(io: Io, id: u32, exit_code: ?u8, killed: bool, cmd: []const u8, idle: bool) void {- queue(io, id, exit_code, killed, cmd, idle);+ queue(io, id, exit_code, killed, cmd, idle, "");publish(io, id, exit_code, killed);}/// Queue while holding the jobs mutex, in the same critical section as done./// Consumers hold jobs -> notification mutex in that same order. Never call/// a frontend here: it may re-enter jobOutput.-pub fn queue(io: Io, id: u32, exit_code: ?u8, killed: bool, cmd: []const u8, idle: bool) void {+pub fn queue(io: Io, id: u32, exit_code: ?u8, killed: bool, cmd: []const u8, idle: bool, output: []const u8) void {const clipped = clipCmd(cmd);- const n = Notice{ .id = id, .exit_code = exit_code, .killed = killed, .idle = idle, .preview = clipped.buf, .preview_len = clipped.len };+ const tail = clipOutput(output);+ const n = Notice{+ .id = id,+ .exit_code = exit_code,+ .killed = killed,+ .idle = idle,+ .preview = clipped.buf,+ .preview_len = clipped.len,+ .output = tail.buf,+ .output_len = tail.len,+ .output_truncated = tail.truncated,+ };mu.lockUncancelable(io);+ var queued = false;if (dismissedIndex(id)) |i| {std.mem.copyForwards(u32, dismissed[i .. dismissed_len - 1], dismissed[i + 1 .. dismissed_len]);dismissed_len -= 1;@@ -84,8 +120,10 @@ pub fn queue(io: Io, id: u32, exit_code: ?u8, killed: bool, cmd: []const u8, idl}ring[count] = n;count += 1;+ queued = true;}mu.unlock(io);+ if (queued) if (on_queued) |hook| hook();}/// Frontend-only publication AFTER releasing the jobs mutex. No wake is queued.@@ -187,7 +225,7 @@ fn drain(io: Io, buf: []u8, idle_too: bool) ?[]const u8 {keep += 1;continue;}- var one: [200]u8 = undefined;+ var one: [4096]u8 = undefined;const w = wakeLine(&one, ring[i]);if (used > 0) {if (used + 1 >= buf.len) break;@@ -211,7 +249,10 @@ fn drain(io: Io, buf: []u8, idle_too: bool) ?[]const u8 {pub fn deliver(root: *Agent) void {if (root.sub) return;@import("subagent_interactive.zig").deliver(root);- var buf: [512]u8 = undefined;+ // A parked shell is about to end this turn without another model call.+ // Leave the notice for the idle auto-turn so the result is not swallowed (#1154).+ if (@import("subagent_interactive.zig").yieldPending()) return;+ var buf: [4096]u8 = undefined;const text = takeWake(root.io, &buf) orelse return;@import("session_wake.zig").inject(root, text);}@@ -278,6 +319,37 @@ test "printRunning parks a persistent server instead of inviting a wait_ms polltry std.testing.expectEqualStrings("[job 446: running · 15s waited, then interrupted — persistent server; parked in the background. You are notified on exit; do not poll]", aw.written());}+test "#1154: idle wake carries exit status and output, and a pending yield does not swallow it" {+ const io = std.testing.io;+ count = 0;+ dismissed_len = 0;+ const interactive = @import("subagent_interactive.zig");+ interactive.configure(true);+ defer interactive.configure(false);+ interactive.armYield();+ queue(io, 12, 0, false, "zig build test", false, "All 2 tests passed.");+ var agent: Agent = undefined;+ agent.sub = false;+ agent.io = io;+ agent.session_name = "";+ deliver(&agent); // yield is armed: the notice stays queued+ var buf: [4096]u8 = undefined;+ const text = takeIdleWake(io, &buf) orelse return error.Empty;+ try std.testing.expect(std.mem.indexOf(u8, text, "[job 12 exited 0: zig build test]") != null);+ try std.testing.expect(std.mem.indexOf(u8, text, "All 2 tests passed.") != null);+ try std.testing.expect(std.mem.indexOf(u8, text, "do not poll") != null);+ try std.testing.expect(takeIdleWake(io, &buf) == null);++ var big: [output_cap + 32]u8 = undefined;+ @memset(&big, 'x');+ @memcpy(big[big.len - 8 ..], "TAIL-END");+ queue(io, 13, 1, false, "make", false, &big);+ const tail = takeWake(io, &buf) orelse return error.Empty;+ try std.testing.expect(std.mem.indexOf(u8, tail, "TAIL-END") != null);+ try std.testing.expect(std.mem.indexOf(u8, tail, "[older output omitted]") != null);+ try std.testing.expect(std.mem.indexOf(u8, tail, "[job 13 exited 1: make]") != null);+}+test "takeWake drains and formats the grok-build do-not-poll reminder" {const io = std.testing.io;count = 0;diff --git a/src/jobs.zig b/src/jobs.zigindex 40a82f80..624bc3da 100644--- a/src/jobs.zig+++ b/src/jobs.zig@@ -209,7 +209,7 @@ fn jobPump(job: *Job, gpa: Allocator, io: Io) void {const idle = job.stopped_idle;// Publish done + queue atomically against jobOutput/jobKill consuming it.// A bounded dismissed-id cache cannot close a queue-after-unlock race.- if (!quiet and !detached) job_notify.queue(io, id, code, killed, job.cmd, idle);+ if (!quiet and !detached) job_notify.queue(io, id, code, killed, job.cmd, idle, job.buf.items[job.cursor..]);g_jobs.mutex.unlock(io);if (detached) return;if (builtin.is_test) if (completion_test_hook) |hook| hook(io, id);diff --git a/src/readline.zig b/src/readline.zigindex 2e5d211c..b6417698 100644--- a/src/readline.zig+++ b/src/readline.zig@@ -192,8 +192,9 @@ pub fn readLine(if (buf.items.len == 0) {const idle_ms: i32 = if (@import("presence_accord.zig").enabled()) 50 else 200;while (!inputPendingTimed(idle_ms)) {- var wake_buf: [512]u8 = undefined;+ var wake_buf: [4096]u8 = undefined;if (idle_wake.takeIdleWake(root.io, root.session_name, &wake_buf)) |wake| {+ @import("subagent_interactive.zig").line_notice = true;buf.appendSlice(gpa, wake) catch break;try out.writeAll("\r\n");try out.flush();diff --git a/src/subagent_interactive.zig b/src/subagent_interactive.zigindex c0484452..e23130a4 100644--- a/src/subagent_interactive.zig+++ b/src/subagent_interactive.zig@@ -26,7 +26,18 @@ pub fn configure(on: bool) void {}pub fn request(ctx: tools.ToolCtx) void {- if (ctx.interactive_children and !ctx.from_sub) requested.store(true, .release);+ if (ctx.interactive_children and !ctx.from_sub) armYield();+}++/// The next model request will be replaced by the yield notice. Job completion+/// must stay queued for the idle auto-turn instead of landing in a turn that+/// is about to return without another model call (#1154).+pub fn armYield() void {+ if (enabled.load(.acquire)) requested.store(true, .release);+}++pub fn yieldPending() bool {+ return enabled.load(.acquire) and requested.load(.acquire);}pub fn beforeRequest(root: anytype) !?[]const u8 {