Commit Graph
2 Commits
Author SHA1 Message Date
yetone 4e3078ee47 agents: a Codex thread started on any provider table goes through magpie when reopened, not only CC Switch's
A report the owner relayed from WeChat (10-26): in Codex, with apikeyfan's
gpt-6.1-sol on, an old thread failed every turn with "unexpected status 404
Not Found: Model "apikeyfan/gpt-6.1-sol" is not supported by any configured
account in this group, url: https://slb.apikey.fan/responses". A new thread
worked, and updating magpie didn't help. The url is Codex's own call: Codex
reopens a thread on the provider it was started on, and that thread's table
pointed straight at the relay (no /v1, so not a table magpie wrote), so the
magpie model id went to the relay. 6c5ed2acf pointed only CC Switch's
"custom"/"cc-switch-N" tables at magpie; a table of the user's own, or one
named after a CC Switch card, kept going to the relay.

Now any [model_providers.<id>] table a Codex thread was started on (the
state database's threads) goes through magpie while a magpie model is on,
the same way: base_url to magpie's /v1, the old URL kept in the stash and
given back with Codex's own model or a reset, the table's other keys as they
were. Left alone: tables no thread names, tables a profile names, magpie's,
Codex's built-ins and CC Switch's OpenAI mirror. The state database is read
only when a table outside CC Switch's ids has a base_url, once per check.

Run at this head (4a33cf0a9 + this):
- TestCodexTakesThreadTables (new) is red on the old codex.go: "thread's
  table not through magpie". TestCodexWritesTablesThreadsName, changed to
  expect the user's thread table through magpie, is red on the old code too.
- go test -tags nogui ./internal/agent -run Codex: ok.
- gofmt -l, go vet (darwin, GOOS=windows), go build (darwin, GOOS=linux): ok.

Not tried: the reporter's own config.toml (its table's id isn't known, so a
quoted header or a profile-named table would still be left alone), the full
suite, and a real Codex app reopening a thread.
2026-10-26 22:02:03 +08:00
yetone 9fbdd584ed codex: a thread started on a provider config.toml no longer has opens again, through magpie (#1372, obstrux: "ChatGPT 无法加载 config.toml … Model provider custom not found")
The Codex app resumes a thread on the provider it was started on, kept in
Codex's state database (app-server thread_processor.rs:
merge_persisted_resume_metadata), whatever config.toml's model_provider is
now, and loads no config for it when config.toml has no table of that id
(core config: "Model provider `{id}` not found"). CC Switch puts every
third-party thread on "custom" and rewrites config.toml whole when it
switches, so a switch to its official provider leaves those threads with no
table, and the app can't open them. magpie never removes [model_providers.custom],
but nothing put it back either.

While magpie is wired into Codex (takeTables: set, Join and Sync), each
provider a thread in state_*.sqlite names that config.toml has none of
(table, inline or dotted) gets a table pointed at magpie's gateway, as
CC Switch's own tables already are. Codex's built-in providers (openai,
ollama, lmstudio, amazon-bedrock[-runtime], ollama-chat) and magpie's own
are left out, and a provider the user has stays as it is. The table stays
when Codex steps off magpie, as magpie's own does, for the threads that
name it. Not wired, nothing is written. sessions.CodexThreadProviders reads
the distinct model_provider of the threads table, read-only.

Run:
- Real Codex 0.161 in a sandbox HOME: `codex exec` recorded a thread under
  a [model_providers.custom] pointed at a fake Responses server, the table
  was removed, and the app-server's thread/resume answered "failed to load
  configuration: Model provider `custom` not found" (the reporter's error).
  With this build's `magpie codex fakerelay/m1` (sandbox HOME, gateway on
  127.0.0.1:3546), [model_providers.custom] was written to the gateway, the
  same thread/resume succeeded, and a turn on it completed through magpie to
  the provider (its request reached the fake). The thread kept "custom".
- TestCodexWritesTablesThreadsName (signed in and not) fails without the
  call ("custom not written through magpie"), and its inline case fails
  without the parsed check ("edited TOML is invalid: key inl should be a
  table"); TestCodexThreadTablesOnlyWired.
- gofmt -l, go vet, GOOS=linux/windows go vet -tags nogui on agent and
  sessions, GOOS=linux go build -tags nogui, GOOS=windows go build, and
  go test -tags nogui ./... under a temp HOME. One full run failed
  TestSetAnswersWhileDevinAndProvidersHang (internal/gui, set took 1.6s
  against its 1.5s wall-clock bound; Claude only, Codex not wired, so this
  code isn't on its path); it passes alone 5/5 (0.19-0.42s) and in a rerun
  of gui, agent and sessions together.
2026-10-09 11:55:33 +08:00