Skip to content

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

Python

xAI WS generate:false prewarm on a fresh socket.

justrach656466645a31
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 6fb4391f..49ee8a22 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -13,7 +13,7 @@ current is part of cutting a release.
## v0.0.302.4
- Task workspace housekeeping: `graff worktree update` merges the remote base; `gc` drops dead session trees and clean trees whose GitHub PR is MERGED (dirty trees stay). Desktop: Update from main, Clear unused trees. Asking to free space unfolds `workspace` so `action=gc` is callable this turn.
-- xAI Responses WS chains `previous_response_id` on the held socket (store:false in-memory cache). A stalled first handshake or 426 latches HTTPS SSE for the session; chrome shows a dim `using HTTPS SSE` notice. `GRAFF_XAI_WS_CHAIN=0` opts out.
+- xAI Responses WS chains `previous_response_id` on the held socket (store:false in-memory cache) and `generate:false` prewarms a fresh socket. A stalled first handshake or 426 latches HTTPS SSE for the session; chrome shows a dim `using HTTPS SSE` notice. `GRAFF_XAI_WS_CHAIN=0` opts out.
## v0.0.302.3
diff --git a/src/agent_ws_prewarm.zig b/src/agent_ws_prewarm.zig
index 9340c42c..36c95a9f 100644
--- a/src/agent_ws_prewarm.zig
+++ b/src/agent_ws_prewarm.zig
@@ -24,11 +24,13 @@ const serde = @import("serde.zig");
const WatchdogFired = http.WatchdogFired;
-/// Should this fresh connection prewarm? Codex brand, session start (nothing
-/// sent, no chain anchor), and not under the full-resend experiment (seeding
-/// the chain would fight the flag's premise).
+/// 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 (!std.mem.eql(u8, self.provider.id, "codex")) 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;
if (codex_chain.g_force_full_resend) return false;
return self.codex_ws != null and self.codex_prev_id == null and self.codex_sent_upto == 0;
}
@@ -193,6 +195,31 @@ test "stripTransportFields: WS frames omit the SSE-only stream field" {
try stdt.testing.expectEqualStrings(clean, stripTransportFields(clean));
}
+test "eligible: xAI session start when chaining is on" {
+ const stdt = std;
+ var arena_state = stdt.heap.ArenaAllocator.init(stdt.testing.allocator);
+ defer arena_state.deinit();
+ var agent = Agent{
+ .io = stdt.testing.io,
+ .client = undefined,
+ .provider = .{ .id = "xai", .kind = .responses, .auth = .bearer, .url = "https://api.x.ai/v1/responses", .api_key = "k", .model = "grok-4.6", .context = 500_000 },
+ .messages = stdt.json.Array.init(arena_state.allocator()),
+ .sub = false,
+ .label = "main",
+ .out = null,
+ .arena = arena_state.allocator(),
+ .gpa = stdt.testing.allocator,
+ };
+ var held: ws.WsClient = undefined;
+ agent.codex_ws = &held;
+ const saved = codex_chain.g_xai_ws_chain;
+ defer codex_chain.g_xai_ws_chain = saved;
+ codex_chain.g_xai_ws_chain = true;
+ try stdt.testing.expect(eligible(&agent));
+ codex_chain.g_xai_ws_chain = false;
+ try stdt.testing.expect(!eligible(&agent));
+}
+
test "eligible: codex session start only" {
const stdt = std;
var arena_state = stdt.heap.ArenaAllocator.init(stdt.testing.allocator);
diff --git a/src/main.zig b/src/main.zig
index 7251c897..bde415d3 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -580,6 +580,7 @@ test { // ── Unit tests (`zig build test`): pull in tests from imported modu
_ = @import("agent_request_search_tests.zig");
_ = @import("agent_ws_steer.zig");
_ = @import("agent_ws_signal.zig");
+ _ = @import("agent_ws_prewarm.zig");
_ = @import("tui_acp_updates.zig");
_ = @import("acp_preauth.zig"); // credential-free ACP loop must stay in the test root
_ = @import("task_outcome.zig"); // goal-outcome telemetry events