Commit Graph
19 Commits
Author SHA1 Message Date
yetone e4197144a8 perf: every package's package-level regexps compile on first use
v0.1.3516 made gateway's and redact's patterns lazy. The other 299
package-level regexp.MustCompile calls, in 148 files across agent,
provider, gui, library, codexcat, sessions, usage, plugin and the rest,
now go through lazyre.New too, so a launch that never reaches them
(`magpie statusline`, run by Claude Code on every message) doesn't
compile them. Fields, maps and params that held them are *lazyre.RE.

Measured on mote (M5 Pro), sandbox HOME, v0.1.3516-equivalent build
(t42) against this one (t43):
- GODEBUG=inittrace=1 sum: 7.39 MB / 69,837 allocs -> 4.62 MB / 46,765
- `magpie statusline`, 3 runs each: instructions retired ~212M -> ~176M,
  peak memory footprint 19.2-19.4 MB -> 16.8-17.0 MB

Run: go vet ./... (darwin) ok; GOOS=windows go vet on each of the 30
changed packages ok; GOOS=linux go vet ok except ., internal/cli and
internal/gui, which stop in wails v3's cgo files when cross-compiled
(the same at main). New TestAllLazyPatternsCompile at the root compiles
all 574 registered patterns (ok), so a bad pattern fails a test rather
than a first use.
Not run before push: the changed packages' own test suites; they run
on mote after it.
2026-11-10 12:54:39 +08:00
yetone b4a9cd8db5 codex: a tool name the ChatGPT backend refuses goes as one it takes, and comes back as the agent's
wing3556 on Discord (11-02): a compaction through a Codex account failed
400 "Codex: Invalid response.create payload: Invalid 'input[83].name':
string does not match pattern. Expected a string that matches the
pattern '^[a-zA-Z0-9_.-]+\z'." The ChatGPT backend checks every tool
name in a request, a call's in input as well as a tool's in tools, and
refuses the whole request when one fails. A conversation can hold a call
by such a name: a model another provider served wrote one with a space,
a colon or non-ASCII in it, and the agent kept it beside its "no such
tool" answer. Every request that replayed it, the compaction above all,
then failed on Codex. Nothing on the way checked: buildResponses copies a
call's name as it is, and redaction keeps names as written.

What changed:
- provider.CodexToolName: a valid name stays as it is. Otherwise each
  refused byte becomes "_", the result is cut to 55 and gets "_" plus 8
  hex of its sha256, so it is the same on every request and two names
  never meet. CodexToolNames applies it to tools (namespace children
  too), function_call/custom_tool_call items, additional_tools and
  tool_search_output items, and tool_choice. A body with no bad name goes
  byte for byte.
- It runs where every request to the ChatGPT backend passes: codexBody
  (an account's, translated or relayed) and codexUpstreamOn (Codex's
  own sign-in, /responses and /responses/compact), beside DeclareSearch.
- A tool the agent declared under such a name is called back by its own
  name: translated replies through decoderFor (now given the request's
  tools; codexNamesBack), relayed Responses replies through nsTidy's new
  back map (codexRenamedIn).
- docs/subsystems/gateway-routing.md says so beside #1270's paragraph.

Not covered: namespaces, the OpenAI API (whose pattern has no "." and a
64 limit), Azure and Copilot Responses, filed as #4875.

Run on mote at this head:
- TestCodexToolNamesTheBackendTakes and TestCodexToolNamesKeepValid
  pass. The fake backend refuses a bad name with the reporter's 400 word
  for word; the test covers Claude Code's compaction on /v1/messages with
  four bad history names (sent twice, byte-equal), Chat with a declared
  "search:web" called back by that name, Responses relayed the same, and
  Codex's own /backend-api/codex/responses.
- go test ./internal/provider ./internal/gateway (-timeout 45m): provider ok;
  gateway ok but TestCodexPoolSaysTheClientsVersion, the red already
  filed as #4807 (full package run only, another test's Codex identity
  reaches it); it passes alone at this head.
- go vet ./... (darwin) and GOOS=linux/windows CGO_ENABLED=0 go vet
  -tags nogui ./...: ok. gofmt -l: clean.

Broken by hand:
- codexBody hook off: compaction red with the reporter's 400.
- codexUpstreamOn hook off, decoder restore off, passthrough restore off
  (together): the codex, chat and responses cases each red.

Not tried: wing3556's real conversation (we don't have its bytes, and
the agent is unknown; Claude Code is likely). No real ChatGPT account
was asked with a bad name, so whether the real backend also limits
length is unknown.
2026-11-02 15:15:21 +08:00
yetone 2503520f82 codexcat: each Codex model takes official Codex's own instructions for it (#3759, #4008, #4783)
Every magpie model in Codex's catalog (model_catalog_json) carried
gpt-5.2-codex_prompt.md ("You are Codex, based on GPT-5"), so a magpie
GPT-6 model, the auto group's included, ran on a GPT-5.2-era prompt while
official Codex sends GPT-6's own template. magpie still writes no words of
its own into the prompt and leaves the identity line alone: each entry now
takes the text official Codex sends that model, word for word.

- A model's slug (the id's last segment) is matched as Codex 0.166
  matches one (longest prefix of an official slug): first in the entries
  the user's ChatGPT account handed this Codex (models_cache.json), whose
  base_instructions and model_messages go over as sent; then in Codex
  rust-v0.166.0's bundled models.json (instructions_template only, as an
  older Codex may not read 0.166's model_messages), embedded as
  codex_instructions.json.
- Any other model, and a routing group, takes Codex's prompt for a model
  it doesn't know (models-manager/prompt.md, model_info_from_slug), which
  replaces codex_prompt.md: that is what official Codex sends it.
- ownEntry with no base_instructions, and internal/provider's
  codexInstructions fallback, take the same official text.
- testdata holds Codex's models.json and prompt.md at rust-v0.166.0;
  TestBundledIsCodexOwn fails when the embedded copies drift from them.
- GET /v1/codex/models (a remote Codex's model_catalog_url): entries are
  now ~21 KB, so Codex before 0.166's 1 MiB cap holds about 48 of them
  (was ~125). Codex 0.166 reads the catalog whole (models_endpoint.rs
  passes no body limit), and it sends ?client_version=, so the cap now
  applies only to a Codex below 0.166 or one that doesn't say
  (codexReadsWholeCatalog). docs/reference.md says so.
- docs/subsystems/agent-wiring.md: a "Codex instructions" row. The
  Antigravity cloak's comment no longer calls the GPT-5 prompt magpie's.

Run (mote's disk is full, 100% with other sessions' runs, so on WSL
magpie-desktop through wsl-run):
- go test ./internal/codexcat/: ok. go vet -tags nogui ./... and
  GOOS=windows go vet ./...: ok. gofmt -l: clean.
- go test -tags nogui -count=1 -timeout 45m codexcat, provider, agent,
  gui, gateway (every package that imports codexcat): codexcat, provider,
  gui ok. agent: TestGrokInstalled and TestOmpDetectedWithPiDir red, the
  same at origin/main 276c806db on the same box (#3548, #4033: WSL binfmt
  and install detection). gateway: TestCodexCatalogFitsCodexsLimit and
  TestCodexCatalogKeepsTheKeysUsedModelsFirst red from this change (the
  1 MiB cap, fixed above; both ok after, with every TestCodexCatalog*,
  TestCodexListed*, TestCodexApp*), and TestUnroutedHeldReportSaved, red
  only in the full run, ok alone here and at origin/main (#4300).
- Real Codex 0.166.0 (npm) in a sandbox HOME/CODEX_HOME, model_catalog_json
  from this codexcat, against a fake Responses gateway on 127.0.0.1:38611
  capturing each request: 0.166 sends the instructions as the first
  developer message (no top-level instructions). For magpie/gpt-6-astra it
  equals gpt-6-astra's instructions_template in Codex's models.json, byte
  for byte; for magpie/deepseek-v4-pro it equals prompt.md.

- After rebasing on origin/main 9da9bfabd: go vet (linux, windows) of
  codexcat, gateway, provider ok; codexcat ok; -run
  "Codex|Antigravity|Grok" in gateway and provider ok. Then rebased
  onto 546cdbde6 (7 commits in redact, gateway translation and a GUI
  test, none in codexcat or the Codex catalog) and not run again.

Broken by hand:
- The cap held for every client_version: both catalog tests FAIL (47
  listed for 0.166.0, 0.167.0-alpha.1 and 1.0.0).
- Old codex_prompt.md and Prompt everywhere: TestBundledIsCodexOwn,
  TestThirdPartyModelsTakeCodexOwnInstructions (all 7 slugs started "You
  are Codex, based on GPT-5"), TestThirdPartyModelsTakeCachedEntry,
  TestOwnEntryInstructions and TestCodexCatalogKeepsOwnEntries FAIL.
- The same real Codex run on origin/main's codexcat: both models' first
  developer message is the 7.5K GPT-5 prompt, differing from the official
  text at byte 15 (astra) and 8 (deepseek).

Not tried:
- GOOS=darwin go vet (needs mote, full).
- Reading the bundled catalog from the user's installed Codex binary;
  the snapshot is 0.166's, and a Codex release with new templates needs
  testdata and codex_instructions.json refreshed.
- An Antigravity account with Codex's unknown-model prompt ("You are a
  coding agent running in the Codex CLI"): the cloak breaks only the
  GPT-5 identity lines tried before.
- A remote Codex below 0.166 with many models through a gateway key: it
  lists fewer than before; the used ones FitOwn moves into the first 100
  can fall past the 48 that fit.
- A real ChatGPT account's models_cache.json entries (tested with a
  fixture cache).
2026-11-01 22:30:51 +08:00
yetone d3898ca8d3 provider: ChatGPT account calls go with Codex's headers, and saved accounts are listed once a day
Two follow-ups of 6e55914b6's audit of what magpie sends OpenAI for
idle saved Codex accounts (owl, Discord #general: three ChatGPT accounts
deactivated). Product call made by the session the owner delegated
product calls to; mimicking the official client is allowed for every
vendor but Claude Code. Identity, base_instructions and prompts are not
touched.

- Headers. GET /backend-api/wham/usage, /wham/rate-limit-reset-credits,
  POST .../consume and POST auth.openai.com/oauth/token (live and saved
  sign-ins, and the sign-in's code exchange) went with Go's
  "Go-http-client/1.1" and no originator. They now carry Codex's
  originator and User-Agent through codexClientHeaders, the part of
  codexSign that /codex/models and /responses already used. No version
  header on them: codex-rs sends it with model requests only
  (login/src/auth/default_client.rs default_headers is originator +
  User-Agent; backend-client/src/client.rs adds auth headers).
- Refresh body. codex-rs (main f32b6cfd and rust-v0.165.0,
  login/src/oauth/client.rs refresh, auth/manager.rs
  request_chatgpt_token_refresh) sends JSON client_id, grant_type,
  refresh_token and refresh_reason, and no scope. magpie sent
  scope "openid profile email" and no reason. It now sends codex-rs's
  fields: proactive_expiry near expiry, unauthorized_recovery after a
  401 (stale token), scheduled from the 8-day keep-alive, forced for an
  import or a revoked-sign-in check. The code exchange's form already
  matched exchange_code; only its headers changed.
- Model lists. The active Codex account's /codex/models fetch (hourly
  KeepAccountsListed, FetchNew, Refresh) also fetched every switched-on
  saved account's list each time. codexFetchSaved now asks one with no
  list at once, and the others once a day, one per call, oldest asked
  first; a failed ask is remembered so a deactivated account doesn't go
  first every hour. The active account's list is unchanged.

Docs: providers-accounts.md says both.

Tests (codex_quiet_test.go), each red on the old behaviour (broken by
hand: wham/refresh/exchange headers removed, scope back, the age check
and the one-a-look cap removed, the keep-alive's reason dropped, and
separately the failed-ask memory skipped):
- TestCodexAccountCallsGoAsCodex counts the requests to a fake (usage 1,
  credits 1, consume 1, token 2) and checks User-Agent/originator on
  each and the refresh body's keys. Old: Go-http-client/1.1, "" and
  scope in the body.
- TestCodexRefreshSaysWhy: scheduled, forced, unauthorized_recovery.
  Old: no reason.
- TestSavedCodexListsOnceADay: 2 asks on the first look, 0 an hour on,
  1 then 1 a day on, 0 again, and 0 within the day while failing. Old:
  2 on every look; without the memory, a failing one asked again.

Run (mote-run, at origin/main 9b4d0bda8 plus this change, the tree
pushed unless the rebase below names a newer base):
- gofmt -l internal/provider: clean
- go vet ./internal/{provider,agent,cli,gateway} on darwin, GOOS=linux
  -tags nogui and GOOS=windows: ok
- go test -count=1 -timeout 45m ./internal/provider ./internal/agent
  ./internal/cli ./internal/gateway: all ok (118s, 199s, 44s, 562s)
Not tried: a real ChatGPT account (none touched, per the session's
rules), so OpenAI's answer to the new headers and the scope-less
refresh is known only from codex-rs doing the same. The Sign in with
ChatGPT API path (auth.openai.com/api/accounts/oauth/token, chatgpt_api.go)
is another client and is left as it was. Refresh in the GUI also lists
saved accounts by the once-a-day rule now.
2026-10-30 02:28:10 +08:00
yetone 8ef9fc578c provider: a message sent again to the ChatGPT backend goes without its status, as it goes without its id (Doby on Discord)
Doby on Discord: Pi 1.4.0 on Codex through magpie 0.1.1327 is turned
away on every continued conversation:

  400 {"code":"unknown_parameter","message":"Codex: Unknown parameter:
  'input[8].status'.","param":"input[8].status","type":"invalid_request_error"}

Pi (pi-ai's convertResponsesMessages) sends each earlier assistant
message as the output item it was, {type:"message", role:"assistant",
id, status:"completed", content:[output_text]}. codexInput drops every
item's id, since the backend keeps nothing (store false), but kept the
status. A message with no id is read as an input message, which has no
status field, so the backend refused it. Codex itself sends status only
on the items whose schema has one: codex-rs/protocol/src/models.rs gives
Message an optional status beside its id, Reasoning none at all, and the
tool calls (function_call, custom_tool_call, local_shell_call, whose
status is required) their own.

codexInput now drops status from messages (typed or not) and reasoning
items, the kinds whose ids it drops, and leaves it on tool calls as Codex
sends them. Checked for the same gap: the gateway's own Codex relay
(codex_backend.go) keeps ids, so status stays valid there; the only other
id stripping (chat_call_ids.go) is chat tool_calls; no plugin serves
Codex.

Tests: TestCodexInputDropsStatusWithID (provider) covers each item kind.
TestPiResponsesRelayedToChatGPT's fake backend now refuses an item with
status and no id the way the backend does (codexBackendRefuses).

Run at 34ad18ed8 with this change:
- gofmt -l clean; go vet ./... (darwin), GOOS=linux go vet -tags nogui
  ./..., GOOS=windows go vet ./... clean
- go test -tags nogui -timeout 45m -count=1 ./internal/provider/
  ./internal/gateway/ in a sandbox HOME: ok 121.0s, ok 421.8s
Rebased on 243594410 (redact escapes and the remote guide's wording,
nothing on this path); at 087ad3935: gofmt -l and go vet on provider and
gateway clean, go test -run 'Codex|Pi' on both packages ok.
Broken by hand: on the old codexInput both new tests are red.
TestCodexInputDropsStatusWithID keeps input[0..2]'s status, and
TestPiResponsesRelayedToChatGPT gets 400 {"error":{"code":
"unknown_parameter","message":"Codex: Unknown parameter:
'input[3].status'.",...}}, the reporter's words.
Not tried: the real ChatGPT backend (the live ~/.codex sign-in is off
limits to this session); the theory that status needs its id fits
OpenAI's item schemas and the reporter's error, nothing more. The full
suite was not run, because another session's full go test ./... was
running on this machine at the time.
2026-10-23 18:02:59 +08:00
yetone 049040283e codex: a searched conversation under Codex's web.run isn't sent the hosted web_search beside it (Savin on Discord)
Savin (#help, magpie 0.1.1296, Codex 0.163.0-alpha.10.2, signed in with
ChatGPT): the turn failed with the ChatGPT backend's "a single request
can't contain both a client-declared function web.run and the hosted tool
web_search".

Who adds which:
- web.run is Codex's own. codex-rs/ext/web-search (tool.rs) declares it
  as a function "run" in the "web" namespace, and spec_plan.rs's
  hosted_model_tool_specs leaves the hosted web_search out whenever
  web.run is registered: on a Responses Lite model (whose requests take
  no hosted tools at all), or with the standalone_web_search feature on.
  Codex never sends both itself.
- The hosted web_search was magpie's. provider.DeclareSearch (#1270)
  adds the cached-only {"type":"web_search","external_web_access":false}
  to any ChatGPT-bound request whose input replays a web_search_call
  without declaring search. declaresSearch looked only for a web_search*
  type, so a conversation that had searched with the hosted tool and
  went on under web.run (a Lite model, a newer Codex, or magpie's own
  searcher's web_search_call items) got web_search added beside web.run,
  in the additional_tools item for Lite or in the tools. The backend then
  refused the turn.

What changed: declaresSearch counts web.run as the conversation's search.
It matches the namespace "web" holding a function "run", and a function
named "web.run". DeclareSearch then leaves the body as Codex sent it.
This covers both routes that call it: codexBody (a ChatGPT account in
magpie) and codexUpstreamOn (Codex's own sign-in relayed). Nothing the
client declared is dropped. web.run is the tool the backend serves this
client (through /alpha/search), so magpie no longer adds the tool that
conflicts with it. A namespace other than "web" with a "run" function
still gets web_search declared.

Not verified: whether the ChatGPT backend accepts a replayed
web_search_call under web.run with no hosted tool. That is the request
the official Codex client sends to it directly. It was not probed on a
real account, and the test fake assumes it is accepted.

Tests:
- TestDeclareSearch: new cases cover web.run in Lite's additional_tools,
  web.run among the tools, the flat "web.run" function, and another
  namespace's run.
- TestSearchedConversationUnderWebRun: protectedSearch now refuses a
  request that carries both tools, with Savin's error. The test covers
  Lite on Codex's sign-in (relayed byte for byte) and two turns on a
  ChatGPT account (Lite and tools).
- On ba319a758 without the codex_request.go change, both tests fail.
  The gateway test gets the 400 with Savin's error. With the change,
  both pass, along with TestSearchedConversation* and
  TestUnsearchedConversationUnchanged.

docs/subsystems/gateway-routing.md says it next to #1270.

Run:
- gofmt -l: clean. go vet ./... passes on darwin, GOOS=linux -tags nogui
  and GOOS=windows -tags nogui.
- `set -o pipefail; go test -timeout 45m ./...` at base ba319a758: every
  package ok except internal/agent and internal/gateway. Both hit the 45m
  package timeout with no test failing. The tests in flight at the panic
  had run 5s and 0s, and four suites from other sessions were running on
  the machine.
- Rerun of those two at -timeout 90m: gateway ok (2057s), agent ok
  (2418s).
- Rebased onto c79400556, whose 4 new commits touch agent, library,
  redact and provider. Rerun there: gofmt, vet on all three OSes,
  ./internal/provider ok, ./internal/redact ok, and
  ./internal/gateway -run 'Search|Codex|WebRun|Protect' ok.
- Rebased again onto e68a0b1db (4 commits in internal/sessions only).
  go vet on sessions, provider and gateway passes there.
2026-10-21 18:40:51 +08:00
yetone 331c27703a gateway, provider: send no prompt_cache_options to Codex, and ask again without it when an upstream refuses it (#2154)
pi-ai sends {"prompt_cache_options":{"mode":"explicit"}} on the Responses
API. The ChatGPT backend behind a Codex subscription answers 400:

  {"error":{"message":"prompt_cache_options is not supported on this
  model","type":"invalid_request_error","param":"prompt_cache_options",
  "code":"invalid_parameter"}}

Probed on 2026-10-14 with a read-only use of the owner's Codex token
(never refreshed or written): gpt-5.5, gpt-6-sol, gpt-6-astra,
gpt-6-luna and gpt-5.6-sol all refuse it, and the same requests without
the field return 200.

- codexBody drops prompt_cache_options with the other fields the backend
  turns away. prompt_cache_key stays; the backend follows it (#1473).
- prompt_cache_options joins the gateway's optional fields. Its refusal
  names the field bare, at the start of the message, which none of the
  existing patterns read, so unsupportedOptionalField also takes
  "<field> is not supported/unsupported" when the message starts with
  it. Only at the start, so a field named inside an echo of the input is
  not taken for it. As for the other optional fields, the refusal is
  remembered per provider, though OpenAI's wording says "on this model";
  the cost of that is a cache hint left off, never a failed request.

Run: go test -tags nogui for internal/gateway (40m timeout; load ~380
from other sessions), provider, catalog, codexcat and agent; gofmt -l;
go vet darwin, GOOS=linux -tags nogui, GOOS=windows. With each fix taken
out by hand, TestRefusedOptionalNamesOnlyUnsupportedFields,
TestPromptCacheOptionsRefusedRetried and
TestCodexBodyDropsPromptCacheOptions go red.
Not tried: pi-ai itself against a Codex subscription.
2026-10-14 19:06:51 +08:00
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
yetone 3ffc99ef60 codex: a call id longer than 64 characters goes as one the backend takes on Codex's own ChatGPT sign-in too, and tool_search ids with it (#732, congee949) — #732 bounded them where magpie writes the request (codexBody: Chat and Anthropic clients on a Codex model, Codex App with spare accounts), but Codex on one ChatGPT account is relayed as it came (codexUpstream), so a conversation with a foreign provider's tool calls (two ids joined, 86 or 87 characters) still got 400 "input[7].call_id … maximum length 64" there: 30 in a week in the report, 29 of them thread_description on gpt-6-luna, on v0.1.869. The relay now gives every call_id over 64 characters as provider.BoundCallID has it (the sha256 of the trimmed id, so a call and its output, paired by the trimmed id, get the same one on every request), the rest of the request byte for byte; codexBody uses the same helper and covers tool_search_call / tool_search_output as well. TestCodexRelayBoundsLongCallIDs (single-account relay: function and tool_search ids bounded, paired and stable across requests, a 64-character id kept) fails on the old code. go vet, builds (darwin, GOOS=linux nogui, GOOS=windows) and go test -tags nogui -count=1 ./... under a temp HOME pass. 2026-10-05 00:31:36 +08:00
congee949 6a67774a99 fix(codex): bound foreign tool call IDs and preserve result pairing (#732) 2026-10-05 00:31:19 +08:00
yetone 9f7b6bd86c codex: a cached entry keeps the cache's own max when magpie's list has none, and Codex's models_cache.json is read under CODEX_HOME everywhere (follow-up to #674, from reviewing #679) — restoring a cached native entry (backend away) set max_context_window to max(MaxContext, Context) from magpie's live list, so a list saved without the max (before magpie kept it) wrote the window over the cache's own (872000 became 272000); now a list with no max leaves the cache's, and codexcat.Window still raises it to a window past it. codexcat.CacheEntries and catalog.Codex read ~/.codex/models_cache.json even with CODEX_HOME set, while codexVersion and codexInstructions followed it; all four now take catalog.CodexModelsCache() (CODEX_HOME, else ~/.codex), and provider's codexCLIHome and the copy in codexInstructions are gone. TestCodexReadsCacheUnderCodexHome, TestCodexCachedListUnderCodexHomeKeepsItsMax and TestCodexCatalogEntryFromCodexHome fail on the old code (the ~/.codex cache read, none listed from CODEX_HOME); TestCodexNativeModelsTakeSetWindows now wants a cached gpt-5.5 with no live max to keep the cache's 400000 (old code: 272000). go vet, builds (darwin, GOOS=linux, GOOS=windows) and go test -tags nogui -count=1 ./... under a temp HOME pass but TestProvidersAnswerWhileListsComeIn, a timing test that passes alone. 2026-10-03 21:39:13 +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 e8b3be572c windows: the desktop app no longer opens a console window for every command it runs (#54) — it is linked as a GUI program and has no console, so each console CLI it started (devin auth status and models list, devin acp for every Devin turn, claude, codex, cursor-agent and grok probes and runs, grok login) was given a new console by Windows, and a Windows Terminal window with it, some every few seconds while the app sat idle. Every command magpie runs is now made through internal/proc, which starts it with CREATE_NO_WINDOW when magpie has no console of its own: the child gets a console without a window, and its output, which magpie always pipes back, arrives as before. A magpie run in a terminal (magpie serve, the TUI, the desktop app started from one with a command) has one, and its children share it as they did, so Ctrl+C there still reaches them. The relaunch after an update keeps its DETACHED_PROCESS, added to rather than replacing the flags it was made with, and a test fails on any command made with os/exec directly, so a new one can't bring the windows back 2026-09-25 14:04:44 +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