Skip to content

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

Python

fix: GPT-6+ on Codegraff uses OpenAI compact; Grok keeps the client summarizer

justrach589110bc4ebd
diff --git a/docs/adr/0002-xai-defaults-to-the-responses-wire.md b/docs/adr/0002-xai-defaults-to-the-responses-wire.md
index 705f601a..4c2cf4e3 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 + server compaction)
+# 0002. xAI defaults to the Responses wire (WS; client compact)
-Status: accepted 2026-08-15
+Status: accepted 2026-08-15; compaction arm amended 2026-09-05
## Context
@@ -20,16 +20,17 @@ endpoints reject every request; fixed alongside the flip.
`g_xai_responses` defaults to true: xAI sessions run on
api.x.ai/v1/responses, which gives WebSocket turns (with the WS→SSE
-fallback ladder), first-party server-side compaction for both
-autocompaction and manual `/compact` (#503), and structured outputs.
-`GRAFF_XAI_WIRE=chat` (any value other than `responses`) opts a session
-back onto chat completions.
+fallback ladder) and structured outputs. Compaction does **not** use
+xAI's `POST /v1/responses/compact` blob — the client summarizer
+(`agent_compact.zig`) outperformed it, so `/compact` and autocompact stay
+on that path. `GRAFF_XAI_WIRE=chat` (any value other than `responses`)
+opts a session back onto chat completions.
## Consequences
-- Lossless compaction by default; the intent-aware client summary remains
- the fallback when the endpoint refuses or fails, and the chat wire keeps
- it as primary.
+- Grok compaction is the inspectable client summary on both the Responses
+ and chat wires. xAI's compact endpoint remains in the tree unused
+ (`xai_compact_url`); do not wire it back without a new recall A/B.
- WS eligibility stays an explicit provider list (codex, xai, and Codegraff
when its selected alias is Responses-kind) — Platform OpenAI has no WS
server and must never probe one.
diff --git a/docs/adr/0003-codegraff-wire-follows-model-capability.md b/docs/adr/0003-codegraff-wire-follows-model-capability.md
index f0af83bd..1cc80fd9 100644
--- a/docs/adr/0003-codegraff-wire-follows-model-capability.md
+++ b/docs/adr/0003-codegraff-wire-follows-model-capability.md
@@ -6,26 +6,30 @@ Status: accepted 2026-08-17
The Codegraff gateway has one OpenAI-shaped public contract but two transport
capability sets. Chat Completions accepts every alias and translates Claude and
-Gemini at the edge. Responses (HTTP or WebSocket) is native only for the
-GPT-5.6 family and grok-4.6; Claude and Gemini return 400 there. A single static
-provider wire therefore either leaves native Responses features unused or
-breaks translated models.
+Gemini at the edge. Responses (HTTP or WebSocket) is native for OpenAI GPT-5.6+
+(including Codex `gpt-5.6-*` and GPT-6 `gpt-6-astra`) and grok-4.6; Claude and
+Gemini return 400 there. A frozen 5.6 alias list left later GPT generations on
+Chat Completions, so `/compact` fell through to a client summarizer instead of
+`/v1/responses/compact`. A single static provider wire therefore either leaves
+native Responses features unused or breaks translated models.
## Decision
-Resolve the Codegraff provider's wire per model. `gpt-5.6`,
-`gpt-5.6-sol`, `gpt-5.6-terra`, `gpt-5.6-luna`, and `grok-4.6` use
-`/v1/responses` and may use its WebSocket transport. Every other gateway alias
-uses `/v1/chat/completions` unless the public gateway contract adds it to the
-native Responses set.
+Resolve the Codegraff provider's wire per model. GPT-5.6 and every later GPT
+generation (`gpt-5.6`, `gpt-5.6-sol`/`terra`/`luna`, `gpt-6-astra`, …) plus
+`grok-4.6` use `/v1/responses` and may use its WebSocket transport. `/compact`
+on Codegraff GPT uses the standalone `/responses/compact` endpoint, same as
+direct OpenAI. Grok compaction stays on the client summary (xAI's blob path
+when seated on xAI). Every other gateway alias uses `/v1/chat/completions`.
## Consequences
-- GPT-5.6 and grok-4.6 receive native Responses request shapes, prompt cache
- keys, streaming events, and the WS-to-SSE fallback ladder.
+- GPT-5.6+ and GPT-6 receive native Responses request shapes, prompt cache
+ keys, streaming events, the WS-to-SSE fallback ladder, and OpenAI server
+ compaction. Grok-4.6 gets the same Responses wire, not OpenAI compact.
- Claude and Gemini remain on the edge-translated Chat Completions path.
- Switching models on one Codegraff credential must rebuild both `kind` and
- endpoint; the allowlist is the contract boundary and needs updating when the
- gateway adds another native Responses family.
+ endpoint. New GPT generations matching `gpt-5.6*` or `gpt-{N>=6}*` join
+ Responses without another allowlist edit; Claude/Gemini still must not.
Evidence: [Codegraff gateway contract](https://codegraff.com/docs/gateway).
diff --git a/docs/adr/README.md b/docs/adr/README.md
index a6674ac1..1c831dfa 100644
--- a/docs/adr/README.md
+++ b/docs/adr/README.md
@@ -12,8 +12,8 @@ record only when you need the evidence or the edge cases.
| ADR | The rule |
|---|---|
| [0001](0001-structured-outputs-are-a-formatting-step.md) | Structured output is a final formatting step. Never constrain the agentic phase with a schema grammar, and do not use `--output-schema` unless a program consumes the result. |
-| [0002](0002-xai-defaults-to-the-responses-wire.md) | xAI runs on the Responses wire by default (WS turns, lossless server compaction). `GRAFF_XAI_WIRE=chat` opts out; WS stays an explicit provider list. |
-| [0003](0003-codegraff-wire-follows-model-capability.md) | Codegraff uses Responses + WS for GPT-5.6 and grok-4.6 aliases; Claude, Gemini, and other aliases stay on Chat Completions. |
+| [0002](0002-xai-defaults-to-the-responses-wire.md) | xAI runs on the Responses wire by default (WS turns). Compaction is the client summarizer, not xAI's blob endpoint. `GRAFF_XAI_WIRE=chat` opts out. |
+| [0003](0003-codegraff-wire-follows-model-capability.md) | Codegraff uses Responses + WS for GPT-5.6+ (incl. GPT-6 Astra / Codex `gpt-5.6-*`) and grok-4.6; Claude, Gemini, and other aliases stay on Chat Completions. |
| [0004](0004-peer-speech-is-a-working-set.md) | Peer speech is pull: a one-line `[peer]` wake in history, bodies in the inbox ring; compact drops spent injects and never treats them as the human. |
| [0005](0005-standing-goal-lives-in-the-prefix.md) | Standing goal is one prefix line; the user-message essay injects on change only, never every N turns. |
| [0006](0006-workspace-switch-is-a-tool.md) | Mid-session worktree switch is a real `workspace` tool; a skill cannot move file-tool cwd. |
diff --git a/src/agent_compact.zig b/src/agent_compact.zig
index 1a4d1770..915a987e 100644
--- a/src/agent_compact.zig
+++ b/src/agent_compact.zig
@@ -106,6 +106,13 @@ pub fn compactPrelude(self: *Agent) ?usize {
// AFTER compaction; this covers the request compaction itself makes.
self.closeCodexWs();
if (self.messages.items.len == 0) return null;
+ // Opaque server blobs (xAI leftover, OpenAI compact item) are not
+ // summarizable — the client model cannot see inside them.
+ if (self.messages.items[0] == .object) {
+ if (self.messages.items[0].object.get("type")) |t| {
+ if (t == .string and std.mem.eql(u8, t.string, "compaction")) return null;
+ }
+ }
pinChildTask(self);
self.last_request_context_overflow = false;
return self.effectiveContextTokens();
diff --git a/src/agent_server_compact.zig b/src/agent_server_compact.zig
index b551a9b4..859a87e6 100644
--- a/src/agent_server_compact.zig
+++ b/src/agent_server_compact.zig
@@ -121,12 +121,15 @@ pub fn writeContextManagementBody(s: anytype, threshold: u64) !void {
pub const ManualRoute = enum { local, standalone, in_stream };
-/// Only first-party OpenAI Responses providers get server-side manual compact:
-/// direct API traffic uses `/responses/compact`; ChatGPT/Codex forces the
-/// supported in-stream directive. Every other provider stays on local summary.
+/// First-party OpenAI Responses shapes get server-side manual compact:
+/// direct API and Codegraff GPT-5.6+ use `/responses/compact`; ChatGPT/Codex
+/// forces the supported in-stream directive. Grok (Codegraff or otherwise)
+/// stays on the client summary — xAI's blob path is better there, and the
+/// OpenAI compact endpoint is the wrong shape.
pub fn manualRoute(p: Provider) ManualRoute {
if (p.kind != .responses) return .local;
if (std.mem.eql(u8, p.id, "openai")) return .standalone;
+ if (std.mem.eql(u8, p.id, "codegraff") and @import("provider_codegraff.zig").openaiGptFamily(p.model)) return .standalone;
if (std.mem.eql(u8, p.id, "codex")) return .in_stream;
return .local;
}
@@ -267,9 +270,9 @@ fn fallbackLocal(self: *Agent, err: anyerror) anyerror!usize {
/// exists. A failed or malformed server result never touches live history and
/// falls back to the existing inspectable local summary.
pub fn manualCompact(self: *Agent) anyerror!usize {
- // #503: an explicit-compact provider (xAI, #502) serves manual /compact
- // from its first-party endpoint too — the same one-POST blob as the
- // autocompaction path, with the client summary as the fallback.
+ // An explicit-compact provider (unused for xAI: client summary won)
+ // serves manual /compact from a first-party endpoint, with the client
+ // summary as the fallback.
if (self.provider.serverCompactUrl() != null) {
self.closeCodexWs();
if (self.messages.items.len == 0) {
@@ -384,10 +387,10 @@ pub fn autocompactResumed(self: *Agent) void {
}
pub fn autocompactIf(self: *Agent, recovery_meter: u64, server_arm: bool) void {
- // #502: an explicit-compact provider (xAI) gets first-party compaction —
- // one POST folds the whole history into an opaque blob, no summary model
- // call. Any failure falls through to the client policy so a broken
- // endpoint can never wedge the session.
+ // An explicit-compact provider (not xAI — client summary won) gets
+ // first-party compaction: one POST folds history into an opaque blob.
+ // Any failure falls through to the client policy so a broken endpoint
+ // can never wedge the session.
if (self.provider.serverCompactUrl() != null) {
if (explicitCompact(self)) return;
self.compactOrRecover(self.provider.nearContextLimit(recovery_meter));
diff --git a/src/agent_server_compact_tests.zig b/src/agent_server_compact_tests.zig
index bb9c99c7..015169b1 100644
--- a/src/agent_server_compact_tests.zig
+++ b/src/agent_server_compact_tests.zig
@@ -49,9 +49,24 @@ fn item(a: std.mem.Allocator, typ: []const u8, call_id: ?[]const u8) !std.json.V
return .{ .object = obj };
}
-test "manual server compaction routes direct OpenAI and Codex only" {
+test "manual server compaction routes direct OpenAI, Codegraff, and Codex" {
var p: Provider = .{ .id = "openai", .kind = .responses, .auth = .bearer, .url = "https://api.openai.com/v1/responses", .api_key = "k", .model = "m", .context = 272_000 };
try std.testing.expectEqual(ManualRoute.standalone, manualRoute(p));
+ p.id = "codegraff";
+ p.url = "https://gateway.codegraff.com/v1/responses";
+ p.model = "gpt-6-astra";
+ try std.testing.expectEqual(ManualRoute.standalone, manualRoute(p));
+ try std.testing.expect(manualServerEligible(p));
+ p.model = "gpt-5.6-sol";
+ try std.testing.expectEqual(ManualRoute.standalone, manualRoute(p));
+ p.model = "grok-4.6";
+ try std.testing.expectEqual(ManualRoute.local, manualRoute(p));
+ try std.testing.expect(!manualServerEligible(p));
+ p.id = "xai";
+ p.model = "grok-4.6";
+ try std.testing.expectEqual(ManualRoute.local, manualRoute(p));
+ try std.testing.expect(!manualServerEligible(p));
+ try std.testing.expect(p.serverCompactUrl() == null);
p.id = "codex";
try std.testing.expectEqual(ManualRoute.in_stream, manualRoute(p));
try std.testing.expect(manualServerEligible(p));
@@ -135,7 +150,10 @@ test "enabled: responses-only; server is the default; override wins" {
p.id = "kilo"; // third-party Responses hosts keep the local summary
try std.testing.expect(!enabled(p));
p.id = "xai";
- try std.testing.expect(enabled(p)); // ADR 0002: explicit /responses/compact
+ try std.testing.expect(!enabled(p)); // client summarizer, not xAI blob
+ p.id = "codegraff";
+ p.model = "gpt-6-astra";
+ try std.testing.expect(enabled(p)); // GPT-5.6+ on the gateway uses /responses/compact
p.kind = .openai;
try std.testing.expect(!enabled(p));
p.kind = .responses;
diff --git a/src/provider.zig b/src/provider.zig
index 831772d3..bb599e76 100644
--- a/src/provider.zig
+++ b/src/provider.zig
@@ -25,11 +25,10 @@ pub var g_context_override: ?u64 = null;
pub var g_compact_pct_override: ?u8 = null;
/// #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.
+/// DEFAULT — WebSocket turns with the SSE/full-resend fallback ladder.
+/// Compaction stays on the client summarizer (it beat xAI's blob endpoint).
+/// 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";
@@ -199,11 +198,11 @@ pub const Provider = struct {
return p.context / 100 * pct;
}
- /// The provider's explicit server-side compaction endpoint, if it has one
- /// (#502). codex compacts in-stream via context_management and returns null.
- pub fn serverCompactUrl(p: Provider) ?[]const u8 {
- if (p.kind != .responses) return null;
- if (std.mem.eql(u8, p.id, "xai")) return xai_compact_url;
+ /// The provider's explicit server-side compaction endpoint, if we use it.
+ /// xAI still *has* POST /v1/responses/compact; we do not call it — the
+ /// client summarizer outperformed that blob. Codex/OpenAI compact through
+ /// other routes (in-stream / `/responses/compact`).
+ pub fn serverCompactUrl(_: Provider) ?[]const u8 {
return null;
}
diff --git a/src/provider_codegraff.zig b/src/provider_codegraff.zig
index ecf6e132..a9db998f 100644
--- a/src/provider_codegraff.zig
+++ b/src/provider_codegraff.zig
@@ -5,22 +5,42 @@ const std = @import("std");
pub const responses_url = "https://gateway.codegraff.com/v1/responses";
/// The gateway exposes every alias on Chat Completions, but only native OpenAI
-/// and xAI aliases on Responses. Keep this allowlist aligned with the public
-/// gateway contract so Claude and Gemini never reach their rejected route.
+/// and xAI aliases on Responses. Claude and Gemini return 400 there — keep
+/// those on Chat Completions. OpenAI GPT-5.6+ (including Codex `gpt-5.6-*`
+/// and GPT-6 `gpt-6-astra`) and grok-4.6 are the native set.
pub fn usesResponses(provider_id: []const u8, model: []const u8) bool {
if (!std.mem.eql(u8, provider_id, "codegraff")) return false;
- return std.mem.eql(u8, model, "gpt-5.6") or
- std.mem.eql(u8, model, "gpt-5.6-sol") or
- std.mem.eql(u8, model, "gpt-5.6-terra") or
- std.mem.eql(u8, model, "gpt-5.6-luna") or
- std.mem.eql(u8, model, "grok-4.6");
+ if (openaiGptFamily(model)) return true;
+ return std.mem.eql(u8, model, "grok-4.6");
+}
+
+/// GPT-5.6 and every later GPT generation, including Codex suffixes
+/// (`gpt-5.6-sol`) and GPT-6 names (`gpt-6-astra`). Earlier GPT aliases
+/// (`gpt-5.5`, `gpt-4o`, `gpt-oss-*`) stay on Chat Completions.
+pub fn openaiGptFamily(model: []const u8) bool {
+ const rest = if (std.mem.startsWith(u8, model, "gpt-")) model["gpt-".len..] else return false;
+ if (rest.len == 0) return false;
+ if (std.mem.startsWith(u8, rest, "5.")) {
+ const after = rest["5.".len..];
+ var i: usize = 0;
+ while (i < after.len and after[i] >= '0' and after[i] <= '9') i += 1;
+ if (i == 0) return false;
+ const minor = std.fmt.parseInt(u32, after[0..i], 10) catch return false;
+ return minor >= 6;
+ }
+ var i: usize = 0;
+ while (i < rest.len and rest[i] >= '0' and rest[i] <= '9') i += 1;
+ if (i == 0) return false;
+ const major = std.fmt.parseInt(u32, rest[0..i], 10) catch return false;
+ return major >= 6;
}
test "Codegraff Responses allowlist matches the public gateway contract" {
- for ([_][]const u8{ "gpt-5.6", "gpt-5.6-sol", "gpt-5.6-terra", "gpt-5.6-luna", "grok-4.6" }) |model|
+ for ([_][]const u8{ "gpt-5.6", "gpt-5.6-sol", "gpt-5.6-terra", "gpt-5.6-luna", "gpt-6-astra", "gpt-6.5", "grok-4.6" }) |model|
try std.testing.expect(usesResponses("codegraff", model));
- for ([_][]const u8{ "gpt-5.5", "grok-4.3", "claude-opus-4.8", "gemini-3.7-flash", "glm-5.3-flash" }) |model|
+ for ([_][]const u8{ "gpt-5.5", "gpt-4o", "gpt-oss-120b", "grok-4.3", "claude-opus-4.8", "gemini-3.7-flash", "glm-5.3-flash" }) |model|
try std.testing.expect(!usesResponses("codegraff", model));
try std.testing.expect(!usesResponses("openai", "gpt-5.6"));
+ try std.testing.expect(!usesResponses("openai", "gpt-6-astra"));
}
diff --git a/src/provider_codegraff_tests.zig b/src/provider_codegraff_tests.zig
index 07a20899..40589239 100644
--- a/src/provider_codegraff_tests.zig
+++ b/src/provider_codegraff_tests.zig
@@ -9,7 +9,7 @@ fn build(model: []const u8) provider.Provider {
}
test "Codegraff selects the gateway wire and endpoint per model" {
- for ([_][]const u8{ "gpt-5.6", "gpt-5.6-sol", "gpt-5.6-terra", "gpt-5.6-luna", "grok-4.6" }) |model| {
+ for ([_][]const u8{ "gpt-5.6", "gpt-5.6-sol", "gpt-5.6-terra", "gpt-5.6-luna", "gpt-6-astra", "grok-4.6" }) |model| {
const got = build(model);
try std.testing.expectEqual(provider.Provider.Kind.responses, got.kind);
try std.testing.expectEqualStrings("https://gateway.codegraff.com/v1/responses", got.url);
@@ -56,7 +56,7 @@ test "Codegraff Responses aliases pin a sticky prompt_cache_key" {
break :blk obj;
} });
- for ([_][]const u8{ "gpt-5.6", "grok-4.6" }) |model| {
+ for ([_][]const u8{ "gpt-5.6", "gpt-6-astra", "grok-4.6" }) |model| {
var root: Agent = .{
.gpa = std.testing.allocator,
.arena = arena,
diff --git a/src/repl_compact.zig b/src/repl_compact.zig
index 92180f5d..734b19ac 100644
--- a/src/repl_compact.zig
+++ b/src/repl_compact.zig
@@ -1,4 +1,4 @@
-//! TUI /compact glue — run Agent.compact() on a throwaway quiet agent built
+//! TUI /compact glue — run Agent.manualCompact() on a throwaway quiet agent built
//! from the same history the next turn would send, then hand back the
//! rewritten turns. Split from repl_glue.zig for the 600-line cap.
@@ -85,12 +85,12 @@ pub fn replCompactCb(ctx_ptr: ?*anyopaque, gpa: Allocator, history: []const repl
return false;
};
}
- // Whatever compact() did to the borrowed list — rewrite, or nothing at all
+ // Whatever manualCompact() did to the borrowed list — rewrite, or nothing at all
// on a failure that leaves history untouched — is the session's state now.
defer if (c.convo) |cv| {
cv.list().* = agent.messages;
};
- const n = agent.compact() catch |err| {
+ const n = agent.manualCompact() catch |err| {
out.note = (switch (err) {
error.EmptySummary => gpa.dupe(u8, "compaction failed: empty summary, history unchanged"),
error.IncompleteSummary => gpa.dupe(u8, "compaction failed: incomplete summary, history unchanged"),
diff --git a/src/router_catalog_tests.zig b/src/router_catalog_tests.zig
index 3fb54768..8994728e 100644
--- a/src/router_catalog_tests.zig
+++ b/src/router_catalog_tests.zig
@@ -367,7 +367,7 @@ test "xAI defaults to the Responses wire; GRAFF_XAI_WIRE=chat opts out (#502)" {
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.
+ // grok silently loses 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;
@@ -378,7 +378,7 @@ test "xAI defaults to the Responses wire; GRAFF_XAI_WIRE=chat opts out (#502)" {
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);
- try std.testing.expectEqualStrings(provider.xai_compact_url, resp.serverCompactUrl().?);
+ try std.testing.expect(resp.serverCompactUrl() == null); // client summarizer, not xAI's blob
// withModel keeps the wire choice.
const moved = resp.withModel("grok-4.6");
try std.testing.expectEqual(Provider.Kind.responses, moved.kind);