graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs
Python
fix: don't replay xAI reasoning blobs grok can't decrypt
justrach99d5b5dd1c18
diff --git a/src/agent_request_body_responses.zig b/src/agent_request_body_responses.zigindex 45480bff..e3ec1eb1 100644--- a/src/agent_request_body_responses.zig+++ b/src/agent_request_body_responses.zig@@ -56,7 +56,7 @@ pub fn write(self: *Agent, s: *std.json.Stringify, tools: ?[]const u8, force_too// this item server-side, so only a full anchor writes it.if (!chain and explicit_cache) try writeCacheAnchor(s);const from = if (chain) self.codex_sent_upto else 0;- if (!self.ws_prewarm) for (self.messages.items[from..]) |m| try @import("session_wake.zig").writeWire(s, m); // prewarm: NO input items; turn 1 chains onto the warmup id+ if (!self.ws_prewarm) for (self.messages.items[from..]) |m| try @import("session_wake.zig").writeWireInput(s, m, self.provider.model); // prewarm: NO input items; turn 1 chains onto the warmup idtry s.endArray();if (tools) |t| {const payload = blk: {@@ -98,7 +98,7 @@ pub fn write(self: *Agent, s: *std.json.Stringify, tools: ?[]const u8, force_tootry s.endObject();try s.objectField("include");try s.beginArray();- try s.write("reasoning.encrypted_content");+ if (!@import("effort_route.zig").grokFamily(self.provider.model)) try s.write("reasoning.encrypted_content");if (is_codex and codex_tool_search.web_search) try s.write("web_search_call.action.sources");try s.endArray();try s.objectField("store");diff --git a/src/agent_request_encrypted_tests.zig b/src/agent_request_encrypted_tests.zigindex ca408a27..967682ed 100644--- a/src/agent_request_encrypted_tests.zig+++ b/src/agent_request_encrypted_tests.zig@@ -50,3 +50,31 @@ test "latest Responses models request and replay encrypted reasoning" {try std.testing.expect(std.mem.indexOf(u8, body, "previous_response_id") == null);}}++test "grok (xAI) drops encrypted reasoning blobs it cannot decrypt cross-request (ADR 0002)" {+ // grok rides full-resend over the held socket; xAI's store:false blobs only+ // decrypt inside a live chain, so a replayed blob throws could-not-decrypt.+ // The reasoning item is dropped from the input without breaking the array or+ // its neighbors (both flanking user turns must survive the skip).+ var arena_state = std.heap.ArenaAllocator.init(std.testing.allocator);+ defer arena_state.deinit();+ const a = arena_state.allocator();++ var agent = try testAgentFor(a, "codegraff", .responses, "grok-4.6");+ try agent.messages.append(.{ .object = try userMsg(a, "alpha-user") });+ try withEncryptedHistory(a, &agent);+ try agent.messages.append(.{ .object = try userMsg(a, "beta-user") });+ const body = try agent.buildBody(null, false, true, true);+ defer std.testing.allocator.free(body);+ _ = try std.json.parseFromSliceLeaky(std.json.Value, a, body, .{}); // input array intact+ try std.testing.expect(std.mem.indexOf(u8, body, "encrypted_content") == null);+ try std.testing.expect(std.mem.indexOf(u8, body, "alpha-user") != null);+ try std.testing.expect(std.mem.indexOf(u8, body, "beta-user") != null);+}++fn userMsg(a: std.mem.Allocator, text: []const u8) !std.json.ObjectMap {+ var o: std.json.ObjectMap = .empty;+ try o.put(a, "role", .{ .string = "user" });+ try o.put(a, "content", .{ .string = text });+ return o;+}diff --git a/src/session_wake.zig b/src/session_wake.zigindex dd0f69a9..d5e2e7e4 100644--- a/src/session_wake.zig+++ b/src/session_wake.zig@@ -52,6 +52,25 @@ pub fn writeWire(s: *std.json.Stringify, m: std.json.Value) !void {}try s.endObject();}+/// writeWire for a Responses request `input`. grok (xAI family) drops reasoning+/// items: their `encrypted_content` blobs only decrypt inside a live chain (ADR+/// 0002), and grok rides full-resend over the held socket, so replaying a blob+/// fails with xAI's "Could not decrypt the provided encrypted_content". Writing+/// nothing omits the item from the enclosing array. grok reasoning is blob-only+/// (no summary), so dropping it costs no readable context — the blob was never+/// decryptable cross-request anyway.+pub fn writeWireInput(s: *std.json.Stringify, m: std.json.Value, model: []const u8) !void {+ if (dropReasoningFor(model, m)) return;+ try writeWire(s, m);+}++fn dropReasoningFor(model: []const u8, m: std.json.Value) bool {+ if (!@import("effort_route.zig").grokFamily(model)) return false;+ if (m != .object) return false;+ const t = m.object.get("type") orelse return false;+ return t == .string and std.mem.eql(u8, t.string, "reasoning");+}+pub fn writeWireArray(s: *std.json.Stringify, items: []const std.json.Value) !void {try s.beginArray();for (items) |m| try writeWire(s, m);