Skip to content

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

Python

join background agents before session teardown

Rach Pradhanf4d03170766b
diff --git a/scripts/test-acp-background-subagent.py b/scripts/test-acp-background-subagent.py
index 25422aa8..192e0b90 100644
--- a/scripts/test-acp-background-subagent.py
+++ b/scripts/test-acp-background-subagent.py
@@ -165,6 +165,10 @@ def run(binary, capability=True, cancel=False, disconnect=False, switch_session=
client.events.append(json.loads(line))
assert not client.pending, 'partial JSON frame on ACP teardown'
assert not any(row['event']['type'] == 'terminal' for row in child_events(client))
+ saved = json.loads((work / '.graff' / 'sessions' / f'{sid}.session.json').read_text())
+ child = next(row for row in saved['background_agents'] if row['label'] == 'Inspect in background')
+ assert child['done'] and not child['interrupted'], child
+ assert 'The child finished after the parent prompt.' in child['result'], child
return
if cancel:
agents = client.request('graff/agents', {'action': 'list', 'scope': 'device'})
diff --git a/src/session_run.zig b/src/session_run.zig
index bcde5c69..5aed4645 100644
--- a/src/session_run.zig
+++ b/src/session_run.zig
@@ -239,6 +239,7 @@ pub fn runOneshotPrompt(gpa: Allocator, io: Io, arena: Allocator, root: *agent_m
// One-shot returns here, before the REPL cleanup defer below is even
// registered, so free the root's gpa-backed buffers explicitly (else a
// tool-using one-shot leaks its tool log / render buffers on exit).
+ @import("subagent.zig").agentJobsReap(gpa, io);
@import("agent_render_cleanup.zig").deinit(root);
root.tools_used.deinit(gpa);
// Presence announced this session at boot (#469); a one-shot returns
@@ -467,6 +468,9 @@ pub fn compactResumedSession(root: *agent_mod.Agent) void {
/// final turn left uncommitted. Moved out of main() verbatim (600-line
/// goal); `root` is already stable main()-owned storage.
pub fn finalizeSession(gpa: Allocator, io: Io, arena: Allocator, out: *Io.Writer, root: *agent_mod.Agent, json_mode: bool) !void {
+ // Live children still use the session's presence/activity storage and
+ // must publish their final ledger rows before the last session save.
+ @import("subagent.zig").agentJobsReap(gpa, io);
// Task-outcome telemetry: a working goal that never completed counts as
// abandoned. Before presence.retire so the event can't outlive the flush.
@import("task_outcome.zig").noteSessionEnd(root);