Commit Graph
8 Commits
Author SHA1 Message Date
yetone 437bf023b8 codex, chatgpt-api: a conversation with tools reuses its cached prompt, its session sent in session-id/thread-id as Codex 0.162 sends it (#1473 inthink, #933 Scallions)
The ChatGPT backend looks up a conversation's prompt cache by the session
headers, not by the body's prompt_cache_key. I probed a real Pro account
(gpt-6.1-sol, 13 tools, about 7.6K-token prompt) directly:
- key in body only, 6 requests: cached 0 every time
- no key and no headers: 0 every time
- session-id + thread-id: 0, then 7552 x5
- old session_id/conversation_id: 0, then 7552
- a bare request with no tools: 4096 every time. That is the
  instructions' shared cache, so #1473's "bare requests hit" pattern
  fits this.
Codex CLI 0.162 (captured with codex exec against a fake server) now
sends only session-id and thread-id. It no longer sends the underscored
names, which a proxy may drop.

Changes:
- codexSign: sets session-id and thread-id from the prepared body's key
  (sessionHeaders). It drops the underscored names. A keyless body keeps
  the session the client named.
- codexHeader: relays session-id/thread-id from Codex clients.
- ChatGPT API (SIWC) provider: it sent only Authorization. Now it names
  the conversation (conversationKey for keyless clients) and sends the
  same session headers. Scallions' screenshots: chatgpt-api/ got 0%
  cache where codex/ got 10-99%.
  This was NOT tried against api.openai.com with a real ChatGPT API
  sign-in, since none is available here. Left for the reporter to
  confirm.

Run:
- Sandbox magpie on a real Codex account, client sending no key: old
  build cached 0/7296 erratically; new build 0, 0, then 7296 x4.
- go test ./internal/provider ./internal/gateway: ok.
- Break check: reverting codex_request.go and chatgpt_api.go turns
  TestCodexSignSessionHeaders, TestCodexSignAndBody and
  TestChatGPTAPISession red.
- gofmt -l: clean. GOOS=linux and GOOS=windows go vet: clean.
base_instructions and the identity line are unchanged.
2026-10-10 18:54:16 +08:00
yetone acdaa28aa1 codex: a conversation that searched the web declares cached search to the ChatGPT backend, so its compaction and turns aren't refused "response protection is unavailable" (#1270, #1099)
The ChatGPT backend answers HTTP 200 and only `event: error` "response
protection is unavailable" to any request whose input replays one of its
own web_search_call items while the request doesn't declare the web_search
tool. Probed on a real ChatGPT Pro account (gpt-6.1-sol, 2026-10-09) with
a real searched turn: refused with tools [], with function tools only and
with a compaction_trigger; answered once {"type":"web_search",
"external_web_access":false} is declared. A Responses Lite request refuses
a top-level web_search (400) but takes it in an additional_tools item. So
xjdata's case (Codex compacting a custom provider's conversation itself, a
plain /responses with tools [] that magpie's codexCompact never sees) failed
every time once the session had searched, and congee949's thread
descriptions too.

What changed:
- provider.DeclareSearch / declareSearch: when the input holds a
  web_search_call and nothing declares search, add cached-only web_search to
  the tools, or for Lite (header, reasoning.context all_turns, or an
  additional_tools item present) to the additional_tools item (prepended
  when there is none). With no tools offered, tool_choice becomes "none" so
  the model can't search; a forced choice is kept. Otherwise the body is
  unchanged (bytes untouched when no web_search_call is in it).
- codexBody (every ChatGPT account route: serveAgent, codexCompact, warmup,
  magpie's codex/* models) calls it; codexUpstreamOn calls it for Codex's
  own sign-in relayed to the backend's /responses.
- Not changed: siwc, API-key passthrough to api.openai.com, the legacy
  /responses/compact endpoint (no evidence they are refused so; not probed).
- docs/subsystems/gateway-routing.md names the cause and the fix.

Tests: internal/gateway/search_history_test.go replays the backend's real
items from that probe against a fake that refuses as the backend did.
TestSearchedConversationCompactsOnAnAccount, ...FunctionTools and
...OnCodexSignIn fail on the old code with "event: error"; ...CompactionTrigger
fails with "asked 2 times, not once". TestUnsearchedConversationUnchanged
and provider TestDeclareSearch cover what's left alone.

Run: gofmt -l (clean); go vet, GOOS=linux go vet -tags nogui, GOOS=windows
go vet -tags nogui on internal/provider and internal/gateway; HOME=<temp>
go test -tags nogui ./internal/provider ./internal/gateway (ok). Real
account, sandbox magpie on 127.0.0.1:3491 under a scratch HOME, replaying
the real searched history: old binary -> /v1/responses codex/gpt-6.1-sol
text compaction with tools [] and /backend-api/codex/responses (standard
and Lite compaction_trigger) all "response protection is unavailable";
new binary -> all response.completed, Lite with a compaction item.
Codex CLI 0.161.0 end to end was not done: on a custom provider it
offered no web_search tool, so no search could get into its history.
2026-10-09 22:40:53 +08:00
yetone 4a8338cced codex: Codex's Ultrafast (service_tier "ultrafast") reaches the ChatGPT backend when magpie's pool of Codex accounts serves the turn, as it does on Codex's own sign-in; it was dropped for anything but Fast's "priority", and OpenAI's API still gets it as Fast (yxinyu715 on X: two Pro accounts, Ultrafast does nothing through magpie)
Run: TestCodexPoolKeepsUltrafast fails on the old code (backend asked for <nil>) and passes now; go test ./internal/gateway ./internal/provider ./internal/codexcat pass; go vet clean. Not tried with a real account offering Ultrafast: the owner's accounts don't list it.
2026-10-08 16:53:56 +08:00
Zhaofeng 1a283b95fc fix(gateway): normalize standalone Responses tool outputs (#544)
* fix(gateway): normalize standalone Responses tool outputs

* fix(gateway): preserve native notifications and tool result ordering
2026-10-02 18:26:23 +08:00
yetone dd12c75bff codex: a turn relayed through Codex accounts says it is the Codex client it came from, or newer, so a model Codex CLI reaches on its own is no longer refused through magpie (Discord, lantern2077 / TuskerManshu: gpt-6.1-sol through a routing group answered 400 "The 'gpt-6.1-sol' model is not supported when using Codex with a ChatGPT account" while Codex CLI alone could use it) — the ChatGPT backend serves a model only to a client new enough for it. Re-signing a pool turn, codexSign set User-Agent codex_cli_rs/<codexVersion()>, the newest of a constant 0.154.0, ~/.codex/models_cache.json's client_version (written by the Codex before the last update) and codex --version when codex was on PATH, ~/.local/bin or Homebrew's — nvm, mise, fnm, npm prefixes, pnpm and Volta were out of reach, above all in magpie serve — while the client's own version header was relayed: one turn saying two versions, the older in the User-Agent. Now codexSign writes one version in both, never older than the relayed one; the gateway notes the newest version a Codex client (originator or codex… User-Agent) has come with (SawCodexClient) and codexVersion, also asked by the accounts' model lists, takes it; the fallback is 0.159.0; the models cache is read from CODEX_HOME when set; codexExecutable also looks in proc.UserBinDirs() (every Node of nvm, mise and fnm, ~/.npmrc's prefix, pnpm, bun, Volta; %APPDATA%\npm and the like on Windows; codex.cmd/.exe there). Tested with TestCodexPoolSaysTheClientsVersion against a fake backend refusing gpt-6.1-sol below 0.161.0: Codex CLI 0.161.0 through the pool failed on main with codex_cli_rs/0.154.0 and passes; TestCodexVersionSeen (Claude Code's User-Agent ignored, CLI and Desktop versions read, never lowered, the model list asked with it), TestCodexVersion with CODEX_HOME, TestCodexExecutableOffPath (nvm, mise, an .npmrc prefix with PATH /usr/bin:/bin). go vet ./internal/..., go build -tags nogui (and GOOS=linux, GOOS=windows) and go test -tags nogui ./... pass. Not tried against the real backend: the version gating is read from the error and the models cache, not seen on the wire. 2026-09-30 10:06:15 +08:00
yetone 0ce1888a32 codex: Fast mode through a ChatGPT account — a GPT model Codex's own catalog doesn't list carries the Fast tier Codex gives its GPT models, and the priority service_tier Codex sends for /fast reaches the backend instead of being dropped; other providers' models don't offer it, and other tiers are still left out 2026-09-27 17:42:43 +08:00
Charan RathoreandCursor Agent 20fe8b4fac provider: a second Codex account's prompts stay cached when two saves share an mtime - the list on disk was merged, but the in-process cache re-read it only when ModTime changed, so a second write in the same tick left the first account's list in memory; a successful save now drops that cache, and a test puts the mtime back with Chtimes so the collision happens every run (#74)
Co-authored-by: Cursor Agent <cursoragent@cursor.com>
2026-09-26 00:26:41 +08:00
yetone 2b80641dfc codex: a ChatGPT account's requests are made as Codex CLI makes them, as Alma's Codex plugin does — the backend gates its newest models on a Codex User-Agent (gpt-5.6-luna answered 404 "Model not found" to magpie's), so a request now says it comes from codex_cli_rs, carries the instructions the account's model list gives each model (kept on disk beside the list, for the gateway to find though another process asked, else Codex CLI's copy, else Codex's generic prompt) with the client's own riding first in the input, and is shaped the way Codex sends one: no stored references or item ids, a tool output without its call told as a note, reasoning summaries and encrypted content asked for, tool_choice auto; and a conversation whose client names none gets a prompt_cache_key of its own, the same on every turn, taken from how the conversation starts, so its cached prompt is found again (Claude Code through magpie went from 74% of its input cached to 96%, where requests without one landed on caches that didn't have it) 2026-09-25 11:44:17 +08:00