graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs
0221. The ChatGPT plan's new sign-in is an opt-in chatgpt-new provider; Codex stays the primary route
Status: accepted 2026-09-30
Context
OpenAI documents a sign-in for open-source apps that run on the user's own
machine (Sign in with ChatGPT for open-source apps).
The user registers the app in their ChatGPT account, and its OAuth access token
pays for Responses API requests from their ChatGPT plan. The codex provider
signs in through the Codex CLI's client and calls the ChatGPT backend; this flow
gives Graff its own registration and uses the public
https://api.openai.com/v1/responses.
The route is a preview with narrower limits than the metered API. OpenAI's preview-limits and token-reference pages list them; each limit was probed live on 2026-09-30, and all 45 checks behaved as documented:
- Request shape. HTTP requests set
store: falseandstream: true, sendinputas an array, and carry instructions ininstructionsor developer messages; a system-role item is rejected. The route rejectsbackground,conversation,max_output_tokens,max_tool_calls,metadata,moderation,multi_agent,prompt,prompt_cache_retention,safety_identifier,temperature,top_logprobs,top_p,truncationanduser, and, found by probing,prompt_cache_optionsandprompt_cache_breakpoint.prompt_cache_keyis accepted. - Conversation state. HTTP rejects
previous_response_id. The Responses WebSocket (wss://api.openai.com/v1/responses, bearer only) serves every listed model, and thereprevious_response_idchains withstore: false, but only to a response made on the same connection: a second socket getsInvalid `previous_response_id`. Agenerate: falseprewarm returns a chainable id, and GPT-6 models acceptresponse.steerwith string or item input, end the originalincompletewith reasonsteered, and stream a successor. - Tools. OpenAI asks for function and custom tools grouped in namespaces
or supplied as
additional_toolsinput items (roledeveloper); both work, and flat function and custom tools are accepted too.web_searchworks, subject to model and workspace policy. Image generation and tool search are refused withsubscription_sharing_unsupported_capability; file search, Code Interpreter, computer use, hosted MCP andprogrammatic_tool_callingare unsupported tool types. - Inputs. Text, images and files work (an inline PDF was read). Audio input, the Files API and transcription do not.
- Other endpoints.
/responses/compact,/responses/input_tokens, chat completions, embeddings and images are not authorized.GET /v1/modelsworks but hides newer models unlessclient_versionis sent. - Behavior. Structured outputs, reasoning summaries and in-stream
context_managementcompaction work over HTTP and the socket. The threshold counts input items, not instructions or tools, and a later turn answered from the compaction blob alone. Prompt-cache reads are intermittent (a repeated prefix sometimes reads back a few thousand tokens); writes are never reported.service_tier: "priority"is accepted and ignored. - Errors. OpenAI's recovery table for plan errors:
subscription_sharing_usage_limit_exceeded(429; the allowance is spent until it resets),…_usage_unavailableand…_user_unavailable(503; retry with bounded backoff),…_user_not_eligibleand…_route_not_supported(403),…_unsupported_capability(400), and…_invalid_user(401; sign in again). Any of them can also arrive mid-stream asresponse.failed, and OpenAI never moves the request to another billing path. Some responses still carry older names for the same codes (subscription_sharing_v2_…), and a grant that does not cover the request fails withchatpass_v2_…. An expired access token is a 401 with{"detail":{"error_code":"invalid_token"}}. A rejected field is a 400 whosedetailnames it. - Tokens. The access token is a one-hour RS256 JWT (
audhttps://api.openai.com/v1,isshttps://auth.openai.com, the issuedclient_id, the granted scopes, and opaque OpenAI metadata graff never reads). OpenAI documents that a refresh returns a new access token and a replacement refresh token, and that refresh tokens last 30 days, renewed by every refresh.earliest_refresh_atfalls six minutes before expiry. - Refresh does not work yet. Every refresh tried so far was refused with
HTTP 400
{"error":"invalid_grant"}and no description. That includes an unused refresh token sent 63 seconds afterearliest_refresh_atwith exactly the documented request (the issuedclient_id, the refresh token andresource, noscope) from a clock in step with OpenAI's. Until that changes a sign-in lasts one hour: a turn still running when the access token expires fails withinvalid_token, and the person signs in again.
OpenAI also documents running Codex app-server on the same token (stdio to
app-server, then HTTP/SSE, with supports_websockets=false). Graff calls
the Responses API itself, so it keeps the WebSocket and renews the token in
process rather than restarting anything.
Decision
- Codex first. Codex stays the primary ChatGPT route:
chatgptstill names its login (/login chatgpt,graff login),codexprecedeschatgpt-newin the provider table so a bare model name and the startup default resolve to Codex when both are signed in, and graff never moves a session between the two routes on its own. The new route waits, fully working, for the change on OpenAI's side that forces the new method; switching then means pointing thechatgptlogin alias and the ChatGPT defaults atchatgpt-new. - A separate
chatgpt-newprovider (ProviderSpec.login = .chatgpt_browser,sub_login), not a login onopenaiorcodex: its model rows carry 272k windows (contextForclamps it like codex), it bills flat-rate, and its request shape differs from the metered API's. graff login chatgpt-new(orchat-gpt-new). The first sign-in registers withclient_id=dynamic_agent_clientandagent_name_hint=Graff; later sign-ins reuse the issued client id withlogin_hint(neverid_token_hint: the URL reaches the browser opener's argv, so it carries no saved token). PKCE S256, an OIDC nonce,resource=https://api.openai.com/v1, a loopback callback on127.0.0.1(port 1455, then 1456–1459), and oneext_agent_host_id(urn:uuid:, version 4) per machine.- Nothing is saved before the ID token verifies: RS256 against the
published JWKS, then issuer, audience (the issued client id), expiry and
nonce. Plan usage needs the
chatgpt.tokens.use.directscope; a sign-in without it is saved but never used for requests. - One record per machine in graff's own directory,
<home>/.graff/credentials/chatgpt-new.json(0600 in a 0700 directory, written atomically), with the host id beside it. A sign-in saved under the earlier<home>/.openai/credentials/graff-oauth.jsonmoves there on first read: a rename, never a copy, because two copies of a rotating refresh token split and the stale one spends the sign-in. Refresh sendsresourceand the issued client id five minutes before expiry (inside the six-minute window) or after a 401, under the existing refresh mutex, and never beforeearliest_refresh_at, which OpenAI names as the earliest renewal. A lock file beside the record serializes refreshes across graff processes, as OpenAI asks: the loser of a race would present a replaced token (refresh_token_reused) and force a new sign-in, so it re-reads the record under the lock and adopts the winner's token. OpenAI's answer to a refused renewal (time, code and description) is kept in the record aslast_refresh_error; a code OpenAI calls unusable also clears the refresh token, and a network failure keeps everything.graff logout chatgpt-newrevokes the refresh token and keeps the client id and host id. - Request shape: no prompt-cache options or anchor (those stay keyed to
openai),reasoning.summary: "auto", in-stream compaction (manualRoutereturns.in_stream), no hosted tool search, asyncwebfetchon GPT-6 models, and RLMllm_querysends a streamed body and reads its SSE text. The tool catalog goes flat, as it does to the metered API; if the route starts enforcing namespaces, the fix is to wrap it in one. - Deferred tools keep
toolsfrozen. The stable catalog appends each loaded tool to the end oftools, but OpenAI renders tools ahead of every message and checks cache breakpoints only at message ends, so each load made the next request miss the cache for the whole conversation. Codex hides that tail behind hosted tool search; this route refuses it. So here the tail never reachestools: before each request, every loaded tool that the history does not carry yet is announced in one developer-roleadditional_toolsinput item, the mechanism OpenAI's prompt-caching guide recommends (additional_tools.zig). An item that compaction prunes is announced again; on any other route the items are removed and the tail carries the tools as before. Before this, the MCP suite hit the cache on 12 to 29% of its input on this route against 60 to 65% on Codex. - MiMo keeps
toolsfrozen too. MiMo's chat wire renderstoolsahead of the system prompt: a probe that appended one tool went from a full cache hit to none, so every load re-billed the whole prompt. Chat has noadditional_toolsitem, but MiMo calls a tool that a system message announces, so on MiMo routes the loaded tail rides one system message per load, tagged so the tag never reaches the wire. MiMo's parser types arguments only for declared tools and returns an announced tool's values as strings ("5","[\"a\"]");tool_call_repair.retypeArgsrestores their schema types. Other chat providers keep the tail until each is checked the same way. - DeepSeek announces loaded tools in a user message. DeepSeek renders
toolsafter the system prompt and before the messages, so a load re-billed the whole conversation. Its cache only hits up to a point an earlier request ended or split, so the first request after a load often kept little beyond the system prompt. A system announcement would be worse. V4 Pro's template moves every system message up into the system prompt, so an appended one re-billed the tools as well. A user message renders where it was appended and kept the full cache on V4 Pro and V4 Flash. The model called an announced tool with typed arguments on every try, as it does a declared one. So DeepSeek's announcement is a user message. Its tag makes it a notice (session_wake.isNotice), so/edit, ACP replay and prompt lookups never take it for a prompt, and the TUI transcript leaves it out. A wire change drops it (history_translate). Hot-context updates still ride a system message on chat wires, so on DeepSeek each project-instructions change costs one miss. - Claude on the Codegraff route announces loaded tools in a user message
too. There a changed
toolscost the whole cached prompt: a probe that appended one tool read nothing back, and a system message re-billed the conversation. Claude calls an announced tool, but like MiMo it returns the values as strings, soretypeArgsnow runs on every announcing chat route. It reads the root catalog, and a direct call to a deferred tool loads it without a rebuild (native_fold.gateExec,mcp_schema_gate.autoLoad): before a request the root now rebuilds the catalog when a loaded tool is missing from it (additional_tools.staleCatalog), which leaves the wire unchanged. Claude on Anthropic's own API still appends totools. Its fix is atool_additionblock in a mid-conversation system message (betainline-tools-2026-09-15), which declares the tool, so its arguments come back typed, and it needs a live check first. - Codex and the OpenAI API announce loads in an
additional_toolsitem. On Codex, graff marked the loaded taildefer_loadingbehind hosted tool search, but the array still grew: a replay of graff's own request after a load read nothing back from the cache, and the model then ran a hosted search for the tools it had just loaded. Withtoolsfrozen and the tail in a developeradditional_toolsitem, the same replay kept the cache and the model called the tool directly, over HTTP and on a chained WebSocket delta. Hostedtool_searchstays for tools deferred in the base catalog. The tail is stripped before the hosted splices, because hosted search with nothing deferred is a 400 (#746). The OpenAI API documents the same item. Models without hosted search (before GPT-5.4) keep appending. - The first request carries every MCP server that is ready.
-pstarts MCP in the background and never waits out a handshake (ADR 0035). A server restored from cache was ready before the first request, but that request sent the catalog snapshot taken before the join, soload_tool_schemas' listing grew on the second request: one sure cache miss per session on every provider. The first request now gives queued starts up to 100 ms, merges the finished ones, and sends the rebuilt catalog. - Transport: live turns use the Responses WebSocket like codex, chaining
previous_response_idon the held socket, steering GPT-6 turns, and prewarming whenGRAFF_WS_PREWARMis set. One-shot and quiet turns stay on HTTP, which never sendsprevious_response_id; a socket failure falls back to it. A chat turn closes the socket it opened. - Errors follow that table. A spent allowance fails fast, on a 429 or
mid-stream, with a link to ChatGPT's usage settings, and never falls back
to another credential. The two 503s take the overload ladder (three
retries, 1·2·4 s) and keep the credentials. Every other plan code, under
either name, a
chatpass_grant error, or one graff does not know yet, stops the turn; no plan code is retried as a gateway flake.invalid_tokenandsubscription_sharing_invalid_userare auth errors: one refresh and retry (never beforeearliest_refresh_at), then the error says to sign in again. - Compaction: the in-stream blob carries the prompts it pruned, so a history holding a blob counts as conversation state and is saved.
- The callback page follows codegraff.com's design, embeds its images so it makes no network request while the code is in the address bar, clears the code from the URL, and answers after the exchange so it shows the real outcome.
GRAFF_BROWSERchooses the browser every graff sign-in opens.
Cost
Tokens are per machine: another machine signs in again and reuses the
registration. Two ChatGPT routes coexist until the switch, so the picker
lists both. Hosted use (the gateway, hosted sandboxes) is out of scope;
OpenAI requires a separate agreement for it. The model list comes live from
the route's /v1/models (with client_version, like Codex's), cached for six
hours; the baked rows are only the offline fallback. HTTP requests re-send
the whole input and caching is intermittent, so one-shot runs pay the most;
live turns chain on the socket instead. While OpenAI refuses refreshes, a
sign-in lasts an hour and a longer task stops at the hour with a sign-in
error; once refresh works, a sign-in lives as long as graff refreshes it
within 30 days.
Compared with the Codex route
The same probes and the same graff build ran against both ChatGPT-plan routes on 2026-09-30, with gpt-6.1-sol:
- Same on both. The model list and context windows (272k by default,
872k at most). The request rules:
store: false,stream: true, array input, no system-role items, and the same refused fields (temperature,max_output_tokens,metadata,user,previous_response_idover HTTP and the others listed above). Function and custom tools (flat, in a namespace, or asadditional_tools), parallel tool calls,web_search, structured output, reasoning summaries, image and PDF input,service_tier, verbosity and in-stream compaction. On the socket: chaining on the same connection only, agenerate: falseprewarm, and steering a GPT-6 answer. In graff, a tool call's follow-up rides the socket as a delta on both routes, and a forced compaction kept every fact a later turn asked for. - Only on Codex. Hosted image generation, hosted
tool_search, thecodex.rate_limitsstream events and the plan windows/usageshows, and working token refresh. - On neither. File search, Code Interpreter, computer use, hosted MCP, programmatic tool calling and audio input.
For the harness, moving to the new route means deferred tools load through
graff's own load_tool_schemas rather than hosted tool search (graff
already does this on every provider except codex), image generation comes
from another provider, /usage can only link to ChatGPT's usage settings,
and a sign-in lasts an hour until OpenAI's refresh works.