Skip to content

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

Python

feat(xai): honor /effort on native grok-4.6

Rach Pradhan581290f4ed52
diff --git a/scripts/eval/tier1-manifest.json b/scripts/eval/tier1-manifest.json
index ab1ad17d..0b718de5 100644
--- a/scripts/eval/tier1-manifest.json
+++ b/scripts/eval/tier1-manifest.json
@@ -15,7 +15,7 @@
"src/repl.zig",
"TUI/root.zig"
],
- "test_count_baseline": 1322,
+ "test_count_baseline": 1323,
"test_count_slack": 25,
"required_invariants": [
{
diff --git a/src/agent.zig b/src/agent.zig
index aee16c14..a6289c21 100644
--- a/src/agent.zig
+++ b/src/agent.zig
@@ -139,7 +139,7 @@ pub const Agent = struct {
model_catalog: ?models_cache.LazyCodexCatalog = null, // demand-loaded dynamic Codex rows (root only)
stored_keys_loaded: bool = true, // false after an explicit-provider launch; model surfaces fill the remaining Keychain slots
keep_context: bool = true, // carry the conversation across wire-format model switches (/keepcontext)
- reasoning: ReasoningEffort = .medium, // reasoning/thinking depth — codex, deepseek, codegraff (/effort, /reasoning)
+ reasoning: ReasoningEffort = .medium, // reasoning/thinking depth — xai, codex, deepseek, codegraff (/effort, /reasoning)
fast: bool = false, // codex "fast" mode → priority service_tier (/fast)
fallback_allow: []const []const u8 = &.{}, // explicit cross-provider allowlist from .harness/settings.json
fallback_active: bool = false, // current provider/model is a temporary fallback, not the saved preference
@@ -242,9 +242,9 @@ pub const Agent = struct {
}
/// Whether the active provider honors a reasoning-effort hint: the
- /// Responses API (codex) via reasoning.effort, and the OpenAI-compatible
- /// providers we know normalize a top-level reasoning_effort — the
- /// codegraff gateway and deepseek. Everything else ignores it.
+ /// Responses API (codex, native xAI) via reasoning.effort, and the
+ /// OpenAI-compatible providers that normalize reasoning_effort — native
+ /// xAI chat, the codegraff gateway, and deepseek. Everything else ignores it.
pub fn effortApplies(self: *const Agent) bool {
return schema.providerTakesEffort(self.provider.kind, self.provider.id, self.provider.model);
}
diff --git a/src/commands_model.zig b/src/commands_model.zig
index e13f909f..719a20e0 100644
--- a/src/commands_model.zig
+++ b/src/commands_model.zig
@@ -383,7 +383,7 @@ pub fn tryHandle(root: *Agent, keys: *Keys, arena: Allocator, line: []const u8,
_ = saveThinkingSettings(root.io, root.gpa, root.reasoning, root.fast, root.ultracode_mode, root.show_thinking, root.ai_title);
try out.print("reasoning effort: {s}{s}\n", .{
reasoning_levels[@intFromEnum(root.reasoning)].name,
- if (!root.effortApplies()) " (current model ignores it — applies to codex, deepseek, codegraff)" else "",
+ if (!root.effortApplies()) " (current model ignores it — applies to xai, codex, deepseek, codegraff)" else "",
});
try out.flush();
return true;
diff --git a/src/grok_spec_conformance.zig b/src/grok_spec_conformance.zig
index b89a9ab6..5a139f01 100644
--- a/src/grok_spec_conformance.zig
+++ b/src/grok_spec_conformance.zig
@@ -183,6 +183,32 @@ test "grok spec: Responses body has a stable prompt_cache_key; Anthropic does no
try std.testing.expect(cacheKeyIn(abody) == null);
}
+test "grok spec: native grok-4.6 sends effort; gateway grok-build does not" {
+ var arena_state = std.heap.ArenaAllocator.init(std.testing.allocator);
+ defer arena_state.deinit();
+ const a = arena_state.allocator();
+
+ var resp = try xaiAgent(a, "main", .responses);
+ resp.reasoning = .xhigh;
+ const rb = try resp.buildBody(null, false, true, true);
+ defer std.testing.allocator.free(rb);
+ try std.testing.expect(std.mem.indexOf(u8, rb, "\"effort\":\"xhigh\"") != null);
+
+ var chat = try xaiAgent(a, "main", .openai);
+ chat.reasoning = .xhigh;
+ const cb = try chat.buildBody(null, false, true, true);
+ defer std.testing.allocator.free(cb);
+ try std.testing.expect(std.mem.indexOf(u8, cb, "\"reasoning_effort\":\"xhigh\"") != null);
+
+ var gw = try xaiAgent(a, "main", .openai);
+ gw.provider.id = "codegraff";
+ gw.provider.model = "grok-build";
+ gw.reasoning = .xhigh;
+ const gb = try gw.buildBody(null, false, true, true);
+ defer std.testing.allocator.free(gb);
+ try std.testing.expect(std.mem.indexOf(u8, gb, "\"reasoning_effort\"") == null);
+}
+
test "grok spec: held xAI WS chains previous_response_id + delta; drop rebuilds full input" {
var arena_state = std.heap.ArenaAllocator.init(std.testing.allocator);
defer arena_state.deinit();
diff --git a/src/schema.zig b/src/schema.zig
index 9ad1b9ee..14e397c2 100644
--- a/src/schema.zig
+++ b/src/schema.zig
@@ -412,12 +412,12 @@ fn providerLoginKind(id: []const u8) []const u8 {
/// Whether a model exposes a user-selectable reasoning effort. Kimi maps the
/// setting through its live effort list into `thinking`; the other listed
/// providers use reasoning_effort / Responses reasoning.effort.
-/// Grok models reject the hint even through the codegraff gateway, so they are
-/// excluded up front (mirrors how opencode gates effort per-model) — the
-/// reactive drop-and-retry in request() still covers any other model that
+/// Native xAI grok honors low|medium|high|xhigh. grok-build and Codegraff-
+/// routed grok still reject the hint, so they stay excluded — the reactive
+/// drop-and-retry in request() still covers any other model that
/// turns out to reject it.
pub fn providerTakesEffort(kind: Provider.Kind, id: []const u8, model: []const u8) bool {
- if (std.mem.startsWith(u8, model, "grok")) return false;
+ if (std.mem.startsWith(u8, model, "grok")) return std.mem.eql(u8, id, "xai");
return kind == .responses or
(std.mem.eql(u8, id, "kimi") and pricing.kimiSupportsThinking(model)) or
(if (provider_mod.specFor(id)) |spec| spec.takes_effort else false);
@@ -564,14 +564,14 @@ test "learn_candidate is root-only and cannot become a subagent tool" {
try std.testing.expect(std.mem.indexOf(u8, learn_candidate_spec.desc, "adapters may send it") != null);
try std.testing.expect(std.mem.indexOf(u8, tools_openai_sub, "learn_candidate") == null);
}
-test "providerTakesEffort: effort-honoring providers, but never for grok models" {
+test "providerTakesEffort: native xAI grok takes effort; gateway grok does not" {
try std.testing.expect(providerTakesEffort(.responses, "codex", "gpt-5.5"));
try std.testing.expect(providerTakesEffort(.openai, "codegraff", "deepseek-v4-pro"));
try std.testing.expect(providerTakesEffort(.openai, "deepseek", "deepseek-v4-pro"));
try std.testing.expect(providerTakesEffort(.openai, "kimi", "k3"));
try std.testing.expect(!providerTakesEffort(.openai, "openai", "gpt-5.5")); // direct openai chat
- try std.testing.expect(!providerTakesEffort(.openai, "xai", "grok-4.3")); // xai not in the list
- // grok via the codegraff gateway must NOT get reasoning_effort (grok rejects it)
+ try std.testing.expect(providerTakesEffort(.responses, "xai", "grok-4.6"));
+ try std.testing.expect(providerTakesEffort(.openai, "xai", "grok-4.6")); // chat opt-out
try std.testing.expect(!providerTakesEffort(.openai, "codegraff", "grok-build"));
}
test "agent_output: root-only (subagent/workflow's run_in_background has nothing to poll from inside a child), never doubles as a meta tool" {