Skip to content

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

Python

chatgpt-new: WebSocket turns, chaining, steering and async tools

justrach836914f2e43e
diff --git a/src/agent_ws.zig b/src/agent_ws.zig
index b5228886..caeccc11 100644
--- a/src/agent_ws.zig
+++ b/src/agent_ws.zig
@@ -51,7 +51,7 @@ const rawNonblockStdin = Agent.rawNonblockStdin;
const drainSteerStdin = Agent.drainSteerStdin;
/// WS: root Responses turns when enabled and not fallen back this session
-/// (codex + xai + Codegraff; Platform OpenAI GPT-6 for `response.steer`).
+/// (codex + xai + Codegraff + ChatGPT plan; Platform OpenAI GPT-6 for steering).
pub fn wsEligible(self: *Agent) bool {
return @import("agent_ws_steer.zig").providerHasWs(self.provider.id, self.provider.model) and transport_gate.eligible(.{ .kind = self.provider.kind, .is_sub = self.sub, .codex_ws = main_mod.g_codex_ws, .ws_off = self.ws_off, .has_out = self.out != null, .quiet = self.stream_quiet });
}
diff --git a/src/agent_ws_prewarm.zig b/src/agent_ws_prewarm.zig
index 8e38899b..6cfd9ce1 100644
--- a/src/agent_ws_prewarm.zig
+++ b/src/agent_ws_prewarm.zig
@@ -29,12 +29,13 @@ const WatchdogFired = http.WatchdogFired;
/// 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).
+/// Should this fresh connection prewarm? Codex, the ChatGPT plan 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
+ const brand = std.mem.eql(u8, self.provider.id, "codex") or std.mem.eql(u8, self.provider.id, "chatgpt-new") 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;
diff --git a/src/agent_ws_steer.zig b/src/agent_ws_steer.zig
index 489c7565..b0c4af41 100644
--- a/src/agent_ws_steer.zig
+++ b/src/agent_ws_steer.zig
@@ -22,9 +22,12 @@ pub fn modelSupports(model: []const u8) bool {
/// Who actually serves a Responses WebSocket. Platform OpenAI only for GPT-6
/// (mid-turn `response.steer`); GPT-5.6 stays HTTP SSE. Codex/xAI/gateway
-/// keep their existing sockets. 426 still latches SSE.
+/// keep their existing sockets. The ChatGPT plan route (ADR 0221) serves one
+/// for every model it lists; its HTTP path refuses previous_response_id, so
+/// the socket is what chains. 426 still latches SSE.
pub fn providerHasWs(id: []const u8, model: []const u8) bool {
if (std.mem.eql(u8, id, "codex") or std.mem.eql(u8, id, "xai") or std.mem.eql(u8, id, "codegraff")) return true;
+ if (std.mem.eql(u8, id, "chatgpt-new")) return true;
return std.mem.eql(u8, id, "openai") and modelSupports(model);
}
@@ -159,6 +162,9 @@ test "providerHasWs: Platform OpenAI GPT-6 only; Codex always" {
try std.testing.expect(providerHasWs("codex", "gpt-6-astra"));
try std.testing.expect(providerHasWs("xai", "grok-4.6"));
try std.testing.expect(providerHasWs("codegraff", "gpt-6-astra"));
+ try std.testing.expect(providerHasWs("chatgpt-new", "gpt-6.1-sol"));
+ try std.testing.expect(providerHasWs("chatgpt-new", "gpt-5.5"));
+ try std.testing.expect(modelSupports("gpt-6.1-sol")); // steering rides the same socket
}
test "buildSteerFrame is type + previous_response_id + input" {
diff --git a/src/async_tool_policy.zig b/src/async_tool_policy.zig
index af7b5d0d..ca7ad79c 100644
--- a/src/async_tool_policy.zig
+++ b/src/async_tool_policy.zig
@@ -9,7 +9,8 @@ pub fn configure(value: ?[]const u8) void {
pub fn enabled(provider: Provider) bool {
return configured and provider.kind == .responses and
- (std.mem.eql(u8, provider.id, "openai") or std.mem.eql(u8, provider.id, "codex")) and
+ (std.mem.eql(u8, provider.id, "openai") or std.mem.eql(u8, provider.id, "codex") or
+ std.mem.eql(u8, provider.id, "chatgpt-new")) and
(std.mem.eql(u8, provider.model, "gpt-6-astra") or std.mem.eql(u8, provider.model, "gpt-6-sol") or std.mem.eql(u8, provider.model, "gpt-6.1-sol"));
}
@@ -51,7 +52,7 @@ test "async tool policy exact route model and off switch" {
defer configured = saved;
configure(null);
var p = fixture();
- for ([_][]const u8{ "codex", "openai" }) |id| {
+ for ([_][]const u8{ "codex", "openai", "chatgpt-new" }) |id| {
p.id = id;
for ([_][]const u8{ "gpt-6-astra", "gpt-6-sol", "gpt-6.1-sol" }) |model| {
p.model = model;
diff --git a/src/codex_chain.zig b/src/codex_chain.zig
index 07254278..d6aeebf6 100644
--- a/src/codex_chain.zig
+++ b/src/codex_chain.zig
@@ -51,8 +51,10 @@ 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
/// `previous_response_id` + delta input (including store:false / ZDR).
+/// The ChatGPT plan route (ADR 0221) does, on the socket only.
pub fn chainBrandOk(provider_id: []const u8) bool {
- return std.mem.eql(u8, provider_id, "codex") or std.mem.eql(u8, provider_id, "xai");
+ return std.mem.eql(u8, provider_id, "codex") or std.mem.eql(u8, provider_id, "xai") or
+ std.mem.eql(u8, provider_id, "chatgpt-new");
}
/// A failed turn must drop the chain: not-found (ZDR / store:false evict),
@@ -78,7 +80,8 @@ pub fn shouldReanchorRequest(body: []const u8, message: []const u8, code: ?[]con
pub fn chainUsable(self: *const Agent) bool {
if (g_force_full_resend) return false;
const xai_chain = g_xai_ws_chain and std.mem.eql(u8, self.provider.id, "xai");
- if (!std.mem.eql(u8, self.provider.id, "codex") and !xai_chain) return false;
+ const always = std.mem.eql(u8, self.provider.id, "codex") or std.mem.eql(u8, self.provider.id, "chatgpt-new");
+ if (!always and !xai_chain) return false;
return usable(
self.codex_ws != null,
self.codex_prev_id != null,
@@ -185,9 +188,10 @@ test "chainUsable: xAI chains on a held socket when opted in" {
try std.testing.expect(usable(true, true, 1, 2, 0, 0, 7, 7));
}
-test "chainBrandOk: xAI and codex chain; anthropic does not" {
+test "chainBrandOk: xAI, codex and the ChatGPT plan chain; anthropic does not" {
try std.testing.expect(chainBrandOk("codex"));
try std.testing.expect(chainBrandOk("xai"));
+ try std.testing.expect(chainBrandOk("chatgpt-new"));
try std.testing.expect(!chainBrandOk("anthropic"));
try std.testing.expect(!chainBrandOk("kimi"));
}