Skip to content

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

Python

codex: a tool load no longer ends the WebSocket chain

justrach1a3f8d23a568
diff --git a/scripts/codex_ws_test.py b/scripts/codex_ws_test.py
index 45b994c3..e271b225 100644
--- a/scripts/codex_ws_test.py
+++ b/scripts/codex_ws_test.py
@@ -526,6 +526,13 @@ def assert_midturn_requests(mock: CodexMock) -> None:
)
final_input = final.body.get("input")
+ # ADR 0221: where loaded tools ride additional_tools items, a compacted
+ # history re-announces them next to the handoff; nothing else may ride along.
+ handoff_items = (
+ [item for item in final_input if not (isinstance(item, dict) and item.get("type") == "additional_tools")]
+ if isinstance(final_input, list)
+ else []
+ )
final_texts = (
[text for item in final_input if (text := user_text(item)) is not None]
if isinstance(final_input, list)
@@ -534,7 +541,7 @@ def assert_midturn_requests(mock: CodexMock) -> None:
if (
final.body.get("type") != "response.create"
or not isinstance(final_input, list)
- or len(final_input) != 1
+ or len(handoff_items) != 1
or len(final_texts) != 1
or not final_texts[0].startswith(
"Context: the earlier conversation was compacted"
diff --git a/src/additional_tools.zig b/src/additional_tools.zig
index a1dfa1f9..574a7fd0 100644
--- a/src/additional_tools.zig
+++ b/src/additional_tools.zig
@@ -89,7 +89,7 @@ fn claudeRoute(p: Provider) bool {
/// The loaded tail as tool entries for the agent's wire: exactly what the
/// stable catalog would append to `tools`.
-fn tailEntries(self: *Agent, arena: Allocator) ![]const Value {
+fn tailEntries(self: *const Agent, arena: Allocator) ![]const Value {
const connected: []const mcp.Tool = if (self.registry) |reg| try reg.snapshotTools(arena) else &.{};
var aw: Io.Writer.Allocating = .init(arena);
var s: std.json.Stringify = .{ .writer = &aw.writer };
@@ -200,7 +200,7 @@ fn dropItems(messages: *std.json.Array) void {
/// The request's `tools` without the loaded tail. Always re-serialized on these
/// routes, even with nothing loaded, so the bytes stay identical from the first
/// request to the last.
-pub fn stripTail(self: *Agent, arena: Allocator, tools_json: []const u8) []const u8 {
+pub fn stripTail(self: *const Agent, arena: Allocator, tools_json: []const u8) []const u8 {
const tail = tailEntries(self, arena) catch return tools_json;
var v = std.json.parseFromSliceLeaky(Value, arena, tools_json, .{ .allocate = .alloc_always }) catch return tools_json;
if (v != .array) return tools_json;
diff --git a/src/codex_chain.zig b/src/codex_chain.zig
index d6aeebf6..9a4db601 100644
--- a/src/codex_chain.zig
+++ b/src/codex_chain.zig
@@ -30,7 +30,19 @@ const Agent = @import("agent.zig").Agent;
/// The live agent's chain-invariant properties. Both the check and the record
/// go through here, so they can never disagree about what was compared.
pub fn propsFor(self: *const Agent) u64 {
- return propsFp(self.provider.model, @tagName(self.reasoning), self.fast, self.toolsJson(), self.systemPrompt());
+ var arena_state = std.heap.ArenaAllocator.init(self.gpa);
+ defer arena_state.deinit();
+ return propsFp(self.provider.model, @tagName(self.reasoning), self.fast, wireTools(self, arena_state.allocator()), self.systemPrompt());
+}
+
+/// The `tools` a request carries. Where loads ride additional_tools items
+/// (ADR 0221) the loaded tail stays off the wire, so a load does not end the
+/// chain: its announcement travels in the delta instead.
+fn wireTools(self: *const Agent, arena: std.mem.Allocator) []const u8 {
+ const additional_tools = @import("additional_tools.zig");
+ const tools = self.toolsJson();
+ if (!additional_tools.active(self.provider)) return tools;
+ return additional_tools.stripTail(self, arena, tools);
}
/// GRAFF_CODEX_FULL_RESEND=1 (armed by session_settings.applyEnvKnobs):