Skip to content

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

Python

feat(xai): Responses wire + WebSocket turns by default

Rach Pradhan56882fab546b
diff --git a/CHANGELOG.md b/CHANGELOG.md
index d9ba0694..cb720b6d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -10,6 +10,16 @@ The release workflow uses a tag's section here as its release notes (a
hand-written `docs/releases/<tag>.md` wins if present), so keeping this file
current is part of cutting a release.
+## v0.0.259 (unreleased)
+
+- Grok now defaults to xAI's Responses wire: WebSocket turns (with the SSE
+ fallback ladder), lossless first-party server compaction, and structured
+ outputs work out of the box on a SuperGrok subscription. Set
+ `GRAFF_XAI_WIRE=chat` to return to chat completions.
+- Fixed duplicate MCP tool definitions when a deferred server start raced the
+ eager codedb-pro companion; strict Responses endpoints rejected every turn
+ over the duplicate.
+
## v0.0.258 (2026-08-15)
- Full Grok support on a SuperGrok subscription (#502): opt into xAI's
diff --git a/src/agent_server_compact_tests.zig b/src/agent_server_compact_tests.zig
index e59971b6..5e91f987 100644
--- a/src/agent_server_compact_tests.zig
+++ b/src/agent_server_compact_tests.zig
@@ -309,8 +309,9 @@ test "manualCompact (#503): a blob-anchored history on an explicit-compact provi
defer arena_state.deinit();
const a = arena_state.allocator();
var agent = testAgent(a, .responses);
+ const saved_wire = provider.g_xai_responses;
provider.g_xai_responses = true;
- defer provider.g_xai_responses = false;
+ defer provider.g_xai_responses = saved_wire;
agent.provider = .{ .id = "xai", .kind = .responses, .auth = .bearer, .url = provider.xai_responses_url, .api_key = "k", .model = "grok-4.6", .context = 100_000 };
// History = one opaque compaction item + one turn: small and blob-anchored,
// so the anti-thrash guard refuses the endpoint before any POST — and the
diff --git a/src/args.zig b/src/args.zig
index 49591032..26b171e7 100644
--- a/src/args.zig
+++ b/src/args.zig
@@ -249,7 +249,7 @@ pub fn parse(init: std.process.Init) !Flags {
// GRAFF_LEAN sets the same global in session_settings.applyEnvKnobs).
if (flags.effectiveLean()) no_local_tools.lean = true;
- // #502: GRAFF_XAI_WIRE=responses must land before the initial Keys.build
+ // #502: GRAFF_XAI_WIRE (default responses; =chat opts out) must land before the initial Keys.build
// (startup.resolveKeys) or the xAI provider is built on the chat wire and
// the knob silently no-ops; applyEnvKnobs re-parses the same value later.
if (init.environ_map.get("GRAFF_XAI_WIRE")) |xw|
diff --git a/src/provider.zig b/src/provider.zig
index d4916c66..80841c5c 100644
--- a/src/provider.zig
+++ b/src/provider.zig
@@ -24,11 +24,13 @@ pub var g_context_override: ?u64 = null;
/// (default 80). null → 80. Unlike codex we allow lowering AND raising (1..100).
pub var g_compact_pct_override: ?u8 = null;
-/// #502: GRAFF_XAI_WIRE=responses (session_settings.applyEnvKnobs) serves xAI
-/// over the OpenAI Responses wire at api.x.ai/v1/responses instead of chat
-/// completions — the prerequisite for first-party server compaction and
-/// Responses-WebSocket turns. Verified live on the SuperGrok OAuth path.
-pub var g_xai_responses: bool = false;
+/// #502: xAI rides the OpenAI Responses wire at api.x.ai/v1/responses BY
+/// DEFAULT — that unlocks first-party server compaction (lossless blob;
+/// recall A/B: blob 12/12 vs client summary 11/12 on buried facts) and
+/// WebSocket turns with the SSE/full-resend fallback ladder. Verified live
+/// on the SuperGrok OAuth path. GRAFF_XAI_WIRE=chat (or anything other than
+/// "responses") opts back into chat completions.
+pub var g_xai_responses: bool = true;
pub const xai_responses_url = "https://api.x.ai/v1/responses";
/// xAI's explicit compaction endpoint (POST {model, input} → one opaque
diff --git a/src/router_catalog_tests.zig b/src/router_catalog_tests.zig
index 9a2b0574..267f692d 100644
--- a/src/router_catalog_tests.zig
+++ b/src/router_catalog_tests.zig
@@ -306,15 +306,21 @@ test "providerFor (#377): family-prefixed spelling routes to the direct provider
try std.testing.expectEqualStrings("codegraff", (try no_kimi.providerFor("kimi-k3")).id);
}
-test "GRAFF_XAI_WIRE=responses moves xAI onto the Responses wire (#502)" {
+test "xAI defaults to the Responses wire; GRAFF_XAI_WIRE=chat opts out (#502)" {
const Keys = provider.Keys;
const Provider = provider.Provider;
const all = Keys{ .values = @splat("k") };
+ const saved = provider.g_xai_responses;
+ defer provider.g_xai_responses = saved;
+ // The compiled-in default IS the responses wire — a regression here means
+ // grok silently loses server compaction, WS turns, and structured outputs.
+ try std.testing.expect(provider.g_xai_responses);
+ // GRAFF_XAI_WIRE=chat (any non-"responses" value) restores chat completions.
+ provider.g_xai_responses = false;
const chat = try all.providerById("xai", "grok-4.3");
try std.testing.expectEqual(Provider.Kind.openai, chat.kind);
try std.testing.expect(chat.serverCompactUrl() == null); // chat wire: no blob replay path
provider.g_xai_responses = true;
- defer provider.g_xai_responses = false;
const resp = try all.providerById("xai", "grok-4.3");
try std.testing.expectEqual(Provider.Kind.responses, resp.kind);
try std.testing.expectEqualStrings(provider.xai_responses_url, resp.url);
diff --git a/src/session_settings.zig b/src/session_settings.zig
index 0a993d08..c2ef8ed5 100644
--- a/src/session_settings.zig
+++ b/src/session_settings.zig
@@ -152,9 +152,9 @@ pub fn applyEnvKnobs(arena: Allocator, environ_map: anytype) !void {
const off = std.mem.eql(u8, v, "0") or std.ascii.eqlIgnoreCase(v, "false") or std.ascii.eqlIgnoreCase(v, "off");
server_compact.g_server_compact_override = !off;
}
- // #502: GRAFF_XAI_WIRE=responses moves xAI onto the OpenAI Responses wire
- // (api.x.ai/v1/responses) — first-party server compaction + WS turns.
- // Anything else (or unset) keeps the chat-completions wire.
+ // #502: xAI defaults to the Responses wire (api.x.ai/v1/responses) —
+ // first-party server compaction + WS turns. GRAFF_XAI_WIRE=chat (anything
+ // but "responses") moves it back to chat completions; unset keeps the default.
if (environ_map.get("GRAFF_XAI_WIRE")) |v| {
provider_mod.g_xai_responses = std.ascii.eqlIgnoreCase(std.mem.trim(u8, v, " \t"), "responses");
}