graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs
Python
ws: make xAI chaining and the generate:false warmup opt-in
Rach Pradhancf50ce2b1dcc
diff --git a/docs/adr/0002-xai-defaults-to-the-responses-wire.md b/docs/adr/0002-xai-defaults-to-the-responses-wire.mdindex 6a9b4fa7..d24958ac 100644--- a/docs/adr/0002-xai-defaults-to-the-responses-wire.md+++ b/docs/adr/0002-xai-defaults-to-the-responses-wire.md@@ -1,6 +1,6 @@# 0002. xAI defaults to the Responses wire (WS; client compact)-Status: accepted 2026-08-15; compaction arm amended 2026-09-05; WS chaining on 2026-09-19+Status: accepted 2026-08-15; compaction arm amended 2026-09-05; WS chaining on 2026-09-19; WS chaining off again 2026-09-25## Context@@ -34,10 +34,20 @@ opts a session back onto chat completions.- WS eligibility stays an explicit provider list (codex, xai, and Codegraffwhen its selected alias is Responses-kind) — Platform OpenAI has no WSserver and must never probe one.-- xAI WS chaining is on: `previous_response_id` + delta input on the held- socket, matching the published store:false / ZDR in-memory cache. A- not-found, 25-minute cap, or drop re-anchors with full input (append-only- history; compact rewrites drop the chain). `GRAFF_XAI_WS_CHAIN=0` opts out.+- xAI WS chaining is off by default (`GRAFF_XAI_WS_CHAIN=1` opts in). The+ published contract says `previous_response_id` + delta input works on the+ held socket with store:false via the per-connection cache. Live, a chained+ store:false `response.create` gets one frame and then nothing until the+ stall watchdog fires (about two minutes), both after a normal turn and after+ a `generate:false` warmup; the same requests with store:true complete in+ seconds. graff sends store:false, so every chained turn stalled and paid a+ re-anchor. Unchained turns (full input every turn) are unaffected. When on:+ a not-found, 25-minute cap, or drop re-anchors with full input+ (append-only history; compact rewrites drop the chain). Turning it back on+ needs a live probe showing store:false chaining completes.+- The `generate:false` warmup (prewarm) is off by default for every provider+ (`GRAFF_WS_PREWARM=1` opts in). It runs after the user's prompt, in series,+ and measured slower on turn 1 than a cold turn, with no turn-2 gain.- Revisit if xAI's wire diverges from OpenAI Responses semantics or thecompact endpoint's blob replay pricing changes the cost picture.- Hosted `x_search` rides this wire by default (ADRdiff --git a/src/agent_ws_prewarm.zig b/src/agent_ws_prewarm.zigindex c097c58b..8e38899b 100644--- a/src/agent_ws_prewarm.zig+++ b/src/agent_ws_prewarm.zig@@ -24,10 +24,16 @@ const serde = @import("serde.zig");const WatchdogFired = http.WatchdogFired;+/// Off by default: the warmup runs after the user's prompt, in series, and+/// measured slower on turn 1 than a cold turn (and no faster on turn 2).+/// GRAFF_WS_PREWARM=1 opts in.+pub var g_enabled = false;+/// Should this fresh connection prewarm? Codex or xAI (on-socket chain),/// session start (nothing sent, no chain anchor), and not under the full-resend/// experiment (seeding the chain would fight the flag's premise).pub fn eligible(self: *const Agent) bool {+ if (!g_enabled) return false;const brand = std.mem.eql(u8, self.provider.id, "codex") or(std.mem.eql(u8, self.provider.id, "xai") and codex_chain.g_xai_ws_chain);if (!brand) return false;@@ -207,6 +213,10 @@ test "stripTransportFields: WS frames omit the SSE-only stream field" {test "eligible: xAI session start when chaining is on" {const stdt = std;+ try stdt.testing.expect(!g_enabled); // opt-in (GRAFF_WS_PREWARM=1)+ const saved_enabled = g_enabled;+ defer g_enabled = saved_enabled;+ g_enabled = true;var arena_state = stdt.heap.ArenaAllocator.init(stdt.testing.allocator);defer arena_state.deinit();var agent = Agent{@@ -232,6 +242,10 @@ test "eligible: xAI session start when chaining is on" {test "eligible: codex session start only" {const stdt = std;+ try stdt.testing.expect(!g_enabled); // opt-in (GRAFF_WS_PREWARM=1)+ const saved_enabled = g_enabled;+ defer g_enabled = saved_enabled;+ g_enabled = true;var arena_state = stdt.heap.ArenaAllocator.init(stdt.testing.allocator);defer arena_state.deinit();var agent = Agent{diff --git a/src/codex_chain.zig b/src/codex_chain.zigindex 667bb493..07254278 100644--- a/src/codex_chain.zig+++ b/src/codex_chain.zig@@ -40,10 +40,13 @@ pub fn propsFor(self: *const Agent) u64 {/// optimization trades cheap cache reads for full-price re-uploads.pub var g_force_full_resend = false;-/// xAI on-socket chaining (published WS contract: store:false / ZDR via the-/// per-connection cache). GRAFF_XAI_WS_CHAIN=0 opts out. A not-found, 25-min-/// cap, or drop re-anchors with full input (shouldDropChain).-pub var g_xai_ws_chain = true;+/// xAI on-socket chaining (`previous_response_id` + delta input on the held+/// socket). Off by default: with store:false a chained response.create gets+/// one frame and then silence until the stall watchdog fires (~2 min), both on+/// a normal turn and after a generate:false warmup; store:true chains fine.+/// GRAFF_XAI_WS_CHAIN=1 opts in. A not-found, 25-min cap, or drop re-anchors+/// with full input (shouldDropChain).+pub var g_xai_ws_chain = false;/// May this request chain onto the held response instead of re-anchoring?/// Brands whose Responses WS holds prior state in-memory and accept@@ -174,8 +177,11 @@ test "usable: chains only on a clean extension of what the server holds" {try std.testing.expect(!usable(true, true, 4, 6, 0, 0, 8, 7));}-test "chainUsable: xAI chains by default on a held socket" {- try std.testing.expect(g_xai_ws_chain);+test "chainUsable: xAI chains on a held socket when opted in" {+ try std.testing.expect(!g_xai_ws_chain); // off by default (store:false chained turns stall)+ const saved = g_xai_ws_chain;+ defer g_xai_ws_chain = saved;+ g_xai_ws_chain = true;try std.testing.expect(usable(true, true, 1, 2, 0, 0, 7, 7));}diff --git a/src/grok_spec_conformance.zig b/src/grok_spec_conformance.zigindex 7a296954..3f68428d 100644--- a/src/grok_spec_conformance.zig+++ b/src/grok_spec_conformance.zig@@ -241,7 +241,9 @@ test "grok spec: held xAI WS chains previous_response_id + delta; drop rebuildsagent.codex_prev_id = try std.testing.allocator.dupe(u8, "resp_live");agent.codex_sent_upto = 2;agent.codex_props_fp = codex_chain.propsFor(&agent);- try std.testing.expect(codex_chain.g_xai_ws_chain);+ const saved_chain = codex_chain.g_xai_ws_chain;+ defer codex_chain.g_xai_ws_chain = saved_chain;+ codex_chain.g_xai_ws_chain = true; // opt-in (GRAFF_XAI_WS_CHAIN=1)try std.testing.expect(codex_chain.chainUsable(&agent));const delta = try agent.buildBody(null, false, false, false);@@ -343,6 +345,9 @@ test "grok spec: compact/rewrite is not an append — chain drops (official cachagent.codex_prev_id = "resp_live";agent.codex_sent_upto = 1;agent.codex_props_fp = codex_chain.propsFor(&agent);+ const saved_chain = codex_chain.g_xai_ws_chain;+ defer codex_chain.g_xai_ws_chain = saved_chain;+ codex_chain.g_xai_ws_chain = true; // opt-in (GRAFF_XAI_WS_CHAIN=1)try std.testing.expect(codex_chain.chainUsable(&agent));agent.history_rewrites += 1;try std.testing.expect(!codex_chain.chainUsable(&agent));diff --git a/src/session_settings.zig b/src/session_settings.zigindex 806ed259..bfa549e6 100644--- a/src/session_settings.zig+++ b/src/session_settings.zig@@ -158,6 +158,7 @@ pub fn applyEnvKnobs(arena: Allocator, environ_map: anytype) !void {// GRAFF_CODEX_FULL_RESEND: presence-based — never chain previous_response_id// (codex_chain); the opencode-shape experiment for cache-hit measurement.if (environ_map.get("GRAFF_CODEX_FULL_RESEND") != null) @import("codex_chain.zig").g_force_full_resend = true;+ if (environ_map.get("GRAFF_WS_PREWARM")) |v| @import("agent_ws_prewarm.zig").g_enabled = std.mem.eql(u8, v, "1") or std.ascii.eqlIgnoreCase(v, "on") or std.ascii.eqlIgnoreCase(v, "true");// GRAFF_NO_NATIVE_FOLD: presence-based — restore full power-tool schemas// in every request (the pre-fold interactive surface).if (environ_map.get("GRAFF_NO_NATIVE_FOLD") != null) native_fold.enabled = false;@@ -248,7 +249,7 @@ pub fn applyEnvKnobs(arena: Allocator, environ_map: anytype) !void {if (v.len > 0) provider_mod.g_vercel_url_override = v;}ws.g_debug = environ_map.get("GRAFF_WS_DEBUG") != null;- // xAI on-socket chaining is on (ADR 0002). GRAFF_XAI_WS_CHAIN=0/off/false opts out.+ // xAI on-socket chaining is off by default (ADR 0002); GRAFF_XAI_WS_CHAIN=1 opts in, 0/off/false/no keeps it off.if (environ_map.get("GRAFF_XAI_WS_CHAIN")) |v| {const off = std.mem.eql(u8, v, "0") or std.ascii.eqlIgnoreCase(v, "off") or std.ascii.eqlIgnoreCase(v, "false") or std.ascii.eqlIgnoreCase(v, "no");@import("codex_chain.zig").g_xai_ws_chain = !off;