graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs
Python
Preserve synthesis tool catalogs at the report boundary
Rach Pradhan5083ffeb3d1e
diff --git a/docs/adr/0300-workflow-synthesis-has-a-report-boundary.md b/docs/adr/0300-workflow-synthesis-has-a-report-boundary.mdindex eb66d568..9c5478b7 100644--- a/docs/adr/0300-workflow-synthesis-has-a-report-boundary.md+++ b/docs/adr/0300-workflow-synthesis-has-a-report-boundary.md@@ -12,8 +12,12 @@ failure while losing the previous phase's evidence from the workflow result.Canonical `synthesize` phases and pipeline stages have a worker-local allowanceof eight evidence-bearing model requests, followed by one report-only request.-The final request omits tools and explicitly asks for a qualified summary.-Dispatch also refuses tools at that boundary even if a model emits one anyway.+The final request explicitly asks for a qualified summary. On OpenAI chat and+Responses wires it retains the stable tool catalog with `tool_choice: "none"`,+so disabling execution does not also change the cacheable prefix. Auto-only+routes and other wires still omit tools; pre-existing text-only restrictions+are never widened. Dispatch refuses tools at the boundary even if a model+emits one anyway.The allowance stays on the worker across turn retries; it is not a renewedper-request or per-turn counter. Ordinary workers and root turns are unchanged.diff --git a/scripts/test-workflow-synthesis.py b/scripts/test-workflow-synthesis.pyindex a4c50121..fa4798eb 100644--- a/scripts/test-workflow-synthesis.py+++ b/scripts/test-workflow-synthesis.py@@ -68,7 +68,11 @@ class Model(fixture.ScriptedModel):if name == 'GENERAL':return {'text': 'GENERAL_DONE'}assert n == 9, (name, n, 'synthesis exceeded its request allowance')- assert not body.get('tools'), (name, 'report request still advertises tools')+ previous = calls[-2]+ assert body.get('tools') == previous['tools'], (name, 'report changed the tool catalog')+ assert body.get('tool_choice') == 'none', (name, 'report permits tool use')+ assert body['messages'][0] == previous['messages'][0], (name, 'report changed the system prefix')+ assert body.get('prompt_cache_key') == previous.get('prompt_cache_key'), (name, 'report changed cache routing')if name.startswith('BAD'):return fixture.tool('bash', command='printf FORBIDDEN > forbidden-' + name + '.txt')return {'text': 'SYNTHESIS_DONE_' + name}diff --git a/src/agent_request_body.zig b/src/agent_request_body.zigindex a9b31412..9df5df14 100644--- a/src/agent_request_body.zig+++ b/src/agent_request_body.zig@@ -161,7 +161,10 @@ pub fn buildBody(self: *Agent, tools_in: ?[]const u8, force_tool: bool, stream:try s.objectField("tools");// #261 follow-up: the rest need the root-schema repair too.try @import("tool_call_repair.zig").writeChatTools(&s, self.scratchAlloc(), if (at.active(self.provider) and !self.sub) at.stripTail(self, self.scratchAlloc(), t) else t, self.provider.id, self.provider.model);- if (force_tool or @import("meta_wire.zig").restricted(self.provider.id, self.provider.model)) {+ if (self.synthesis.keepsCatalog(self)) {+ try s.objectField("tool_choice");+ try s.write("none");+ } else if (force_tool or @import("meta_wire.zig").restricted(self.provider.id, self.provider.model)) {try s.objectField("tool_choice"); // #751: Meta is auto-onlytry s.write(@import("meta_wire.zig").toolChoice(force_tool, self.provider.id, self.provider.model));}diff --git a/src/agent_request_body_cache_test.zig b/src/agent_request_body_cache_test.zigindex 7d53b5a6..e0613474 100644--- a/src/agent_request_body_cache_test.zig+++ b/src/agent_request_body_cache_test.zig@@ -44,3 +44,37 @@ test "GPT-5.6 and later Platform marks the stable prefix; Codex and older routestry std.testing.expect(std.mem.indexOf(u8, old, "prompt_cache_breakpoint") == null);try std.testing.expect(std.mem.indexOf(u8, old, "prompt_cache_options") == null);}++test "workflow synthesis report keeps chat and Responses cache prefixes" {+ var arena_state = std.heap.ArenaAllocator.init(std.testing.allocator);+ defer arena_state.deinit();+ const a = arena_state.allocator();+ const catalog = "[{\"type\":\"function\",\"function\":{\"name\":\"ping\",\"description\":\"fixture\",\"parameters\":{\"type\":\"object\"}}}]";+ for ([_]@import("provider.zig").Provider.Kind{ .openai, .responses }) |kind| {+ var agent = try bodies.testAgentFor(a, "openai", kind, "gpt-5.6");+ agent.sub = true;+ agent.label = "synthesize";+ agent.synthesis = .{ .enabled = true, .requests = 7 };+ try agent.synthesis.beforeRequest(&agent);+ const before = try agent.buildBody(catalog, true, true, true);+ defer std.testing.allocator.free(before);+ try agent.synthesis.beforeRequest(&agent);+ const after = try agent.buildBody(if (agent.synthesis.keepsCatalog(&agent)) catalog else null, true, true, true);+ defer std.testing.allocator.free(after);+ const first = try std.json.parseFromSliceLeaky(std.json.Value, a, before, .{});+ const report = try std.json.parseFromSliceLeaky(std.json.Value, a, after, .{});+ try std.testing.expectEqualStrings(+ try std.json.Stringify.valueAlloc(a, first.object.get("tools").?, .{}),+ try std.json.Stringify.valueAlloc(a, report.object.get("tools").?, .{}),+ );+ try std.testing.expectEqualStrings(first.object.get("prompt_cache_key").?.string, report.object.get("prompt_cache_key").?.string);+ const first_prefix = if (kind == .responses) first.object.get("instructions").? else first.object.get("messages").?.array.items[0];+ const report_prefix = if (kind == .responses) report.object.get("instructions").? else report.object.get("messages").?.array.items[0];+ try std.testing.expectEqualStrings(+ try std.json.Stringify.valueAlloc(a, first_prefix, .{}),+ try std.json.Stringify.valueAlloc(a, report_prefix, .{}),+ );+ try std.testing.expectEqualStrings("required", first.object.get("tool_choice").?.string);+ try std.testing.expectEqualStrings("none", report.object.get("tool_choice").?.string);+ }+}diff --git a/src/agent_request_body_responses.zig b/src/agent_request_body_responses.zigindex 851147f4..f359267e 100644--- a/src/agent_request_body_responses.zig+++ b/src/agent_request_body_responses.zig@@ -83,7 +83,7 @@ pub fn write(self: *Agent, s: *std.json.Stringify, tools: ?[]const u8, force_tootry s.objectField("tools");try serde.writeOpenAITools(s, self.scratchAlloc(), async_payload); // #261 follow-uptry s.objectField("tool_choice");- try s.write(if (force_tool) "required" else "auto");+ try s.write(if (self.synthesis.keepsCatalog(self)) "none" else if (force_tool) "required" else "auto");try s.objectField("parallel_tool_calls");try s.write(true);}diff --git a/src/agent_turn.zig b/src/agent_turn.zigindex 3c7990cd..8df6379e 100644--- a/src/agent_turn.zig+++ b/src/agent_turn.zig@@ -82,7 +82,7 @@ pub fn run(self: *Agent, root_turn_prepared: *std.atomic.Value(bool)) anyerror![}if (self.sub) try self.synthesis.beforeRequest(self);const hist_len = self.messages.items.len;- const root = self.request(if (self.text_only) null else self.toolsJson()) catch |err| {+ const root = self.request(if (self.text_only and !self.synthesis.keepsCatalog(self)) null else self.toolsJson()) catch |err| {if (try @import("agent_length_cutoff.zig").recoverRunaway(self, err, hist_len)) continue;return review_deadline.finish(try @import("agent_model_loop.zig").finishError(self, err));};diff --git a/src/workflow_synthesis.zig b/src/workflow_synthesis.zigindex b6022f53..7a3c15fc 100644--- a/src/workflow_synthesis.zig+++ b/src/workflow_synthesis.zig@@ -22,6 +22,15 @@ pub const State = struct {return self.enabled and self.requests > evidence_requests;}+ pub fn keepsCatalog(self: State, agent: *const Agent) bool {+ if (!self.reporting() or (self.prior_text_only orelse true)) return false;+ return switch (agent.provider.kind) {+ .responses => true,+ .openai => !@import("meta_wire.zig").restricted(agent.provider.id, agent.provider.model),+ else => false,+ };+ }+pub fn beforeRequest(self: *State, agent: *Agent) !void {if (!self.enabled) return;// Kept on the worker, not the turn stack: transport retries cannot@@ -81,13 +90,14 @@ test "workflow synthesis restores the original tool restriction before retentionagent.synthesis = .{ .enabled = true, .requests = 8 };try agent.synthesis.beforeRequest(&agent);try std.testing.expect(agent.text_only);+ try std.testing.expectEqual(!prior, agent.synthesis.keepsCatalog(&agent));agent.synthesis.finish(&agent);try std.testing.expectEqual(prior, agent.text_only);try std.testing.expectError(error.WorkflowSynthesisLimit, agent.synthesis.beforeRequest(&agent));}}-test "workflow synthesis gate refuses tools even when a model ignores tool withdrawal" {+test "workflow synthesis gate refuses tools even when a model ignores report-only choice" {var arena = std.heap.ArenaAllocator.init(std.testing.allocator);defer arena.deinit();var agent = fixture(arena.allocator());@@ -98,6 +108,21 @@ test "workflow synthesis gate refuses tools even when a model ignores tool withdtry std.testing.expectEqualStrings(tool_refusal, denied.text);}+test "workflow synthesis withdraws catalogs on unsupported report-only wires" {+ var arena = std.heap.ArenaAllocator.init(std.testing.allocator);+ defer arena.deinit();+ var agent = fixture(arena.allocator());+ agent.synthesis = .{ .enabled = true, .requests = 8 };+ try agent.synthesis.beforeRequest(&agent);+ for ([_]@import("provider.zig").Provider.Kind{ .anthropic, .interactions }) |kind| {+ agent.provider.kind = kind;+ try std.testing.expect(!agent.synthesis.keepsCatalog(&agent));+ }+ agent.provider.kind = .openai;+ agent.provider.id = "meta";+ try std.testing.expect(!agent.synthesis.keepsCatalog(&agent));+}+test "workflow synthesis does not cap ordinary workers or discard earlier findings" {var arena = std.heap.ArenaAllocator.init(std.testing.allocator);defer arena.deinit();