codex: its own GPT models stay in Codex's list when kept for routing groups

士奇 (Discord, 10-28): with a routing group on, the Agents page's Codex
list lost its Codex provider section and models, the model dropdown still
offered GPT, but the Codex app had none; with the group off they came back.

Cause: the codex provider's "Only through routing groups" (Provider.Unlisted,
只通过路由分组使用), or a group that lists itself alone (Group.Unlists), took
the ChatGPT account's own models out of Catalog(), so out of Codex's own
list too. With no Codex section, the own options were not magpie's, so the
own-models switch showed and the picker kept offering GPT; meanwhile #1602
(125dad5cb, CodexNativeUnlisted) dropped every one of them from the list
handed to Codex (backend /models, the model_catalog_json desk file,
spawn_agent). The picker and the app disagreed.

Why the earlier fixes missed it: aa766289b only stopped the GUI folding a
provider, and 508911e43 (TestCodexOwnModelsStayWithGroupOn) only kept
Served own options in the picker. Both covered a plain group; neither
touched Catalog's unlisting for Codex or the desk list's #1602 filter, and
neither test set Unlisted or Unlists.

Fix: Codex's lists start from catalogOf("codex"), which keeps CodexOwn
entries (ListedFor/CatalogFor, CodexNativeHidden, CodexOrder), and
CodexNativeUnlisted is removed with its filters in codexMerged,
spawnChoices and the list tag. Other agents and /v1/models still don't
see unlisted GPT models (checked for Claude Code in both tests).

Behaviour change for #1602: an unlisted codex provider no longer hides GPT
from Codex. The way to hide them from Codex is Codex's own list (its Codex
section's hide / only-picked), which CodexNativeHidden still applies; the
rewritten gateway test checks that and the ETag change.

Tests:
- gateway TestCodexModelListKeepsOwnForGroups (rewrites
  TestCodexModelListUnlistedForGroups): group Unlists and provider Unlisted
  keep gpt-6-sol/gpt-5.5 in Codex's /models and spawn_agent; Claude Code
  doesn't list them; hidden in Codex's list it goes and the ETag changes.
- gui TestCodexOwnModelsListedOnlyThroughGroups: agentModelList has the
  Codex section (Own) for every model, OwnModels is false, the picker has
  them, Claude Code doesn't list the unlisted ones.

Run (mote-run, -tags nogui): go build ./...; go vet for darwin, GOOS=linux
and GOOS=windows on provider/gateway/gui/agent; gofmt -l clean; go test
./internal/provider ./internal/gateway ./internal/gui ./internal/agent: ok.
Broken by hand: the five source files reverted to f20118304 with the new
tests in place: both tests red (gateway: gpt-5.5 and every own slug gone,
spawn offers only group/mine; gui: no Codex section, own switch shown).
Real codex 0.162.1 in a sandbox CODEX_HOME: `codex debug models` with
model_catalog_json pointed at the desk file CodexDesktopCatalog wrote with
the provider Unlisted and an Unlists group lists gpt-6-sol, gpt-5.6-sol and
group/mine (the old code dropped both GPT slugs).

Not run: full suite. Not tried: GUI Playwright files (no page changed), a
live ChatGPT sign-in or the Codex desktop app itself.
This commit is contained in:
yetone
2026-10-28 14:26:18 +08:00
parent 7323255b4e
commit a3ee00c05c
8 changed files with 171 additions and 117 deletions
+1 -1
View File
@@ -228,7 +228,7 @@ recorded as a prediction failure (`noPrediction`).
- A relayed Chat stream's tool call fragment with no `index` (none, or null) is given its call's (`streamCallIndexes` in [`chattidy.go`](../../internal/gateway/chattidy.go), #3386). Gemini's OpenAI-compatible API sends its calls with none, where the OpenAI contract has one on every fragment: the AI SDK's OpenAI provider (Cursor's Private Inference) turned the chunk away ("expected number, received undefined" at `tool_calls[0].index`), and OpenAI's node SDK's stream helper kept no call at all. A fragment with an id other than the open call's, or after the first in its delta, is the next call; any other goes on with the open one. So two calls in chunks of their own are 0 and 1, never both 0, which that helper merges into one call. A fragment with an index keeps it. `TestChatTidyGivesCallsAnIndex` in [`chattidy_test.go`](../../internal/gateway/chattidy_test.go), `TestGeminiCompatRelayedCallsHaveAnIndex` in [`gemini_compat_cut_test.go`](../../internal/gateway/gemini_compat_cut_test.go).
- A translated Chat stream's tool calls are read by `index`, not as one after another (`chatDecoder.toolCall` in [`chat.go`](../../internal/gateway/chat.go)). An upstream may send several calls' fragments by turns (index 0, 1, 0, 1…), the first of each with its id and name; read as a new call at each change of index, two calls reached Codex as six `function_call` items, the first two with `{}` and four with no name (mysterious_dove on Discord). The open call streams as it comes; a call that starts while the open one's arguments aren't yet whole JSON is held by its index and given whole, in index order, at `finish_reason` or `[DONE]`. Every translation from Chat (Responses, Messages, Gemini, a whole reply) reads the stream through it. `TestInterleavedToolCallsToResponses`, `TestInterleavedToolCallsToAnthropic`, `TestInterleavedToolCallsWhole`, `TestToolCallsNamedFirstThenArgued` in [`translate_stream_test.go`](../../internal/gateway/translate_stream_test.go).
- A relayed Chat reply whose choice made calls and ended `stop` ends `tool_calls`, streamed (`chatTidy`) and whole (`chatWhole`), as the translations' collector already ends it (`collector.finish`): told it stopped, a client that reads `finish_reason` ends its turn with the calls not run (喜欢一个人 on Discord, a relay in front of deepseek-v4.1-flash). Any other reason stays as it came. `TestChatCallsEndToolCalls` in [`chattidy_finish_test.go`](../../internal/gateway/chattidy_finish_test.go).
- Codex's model list from the backend path (`codexModels`) is the ChatGPT backend's for its sign-in and then magpie's (`provider.CodexListed`), its ETag and every reply's `X-Models-Etag` tagged with `provider.CodexListTag` so a change has Codex ask again. A Codex there only for account failover, not connected (`CodexOwnOnly`, `agent.CodexOwnOnly`; #1385), gets the backend's alone, tagged with `provider.CodexOwnListTag`; neither tag contains the other, so connecting or disconnecting has Codex fetch the list again. The user's picks on the codex provider (`provider.CodexNativePicked`) narrow the backend's listed models. They keep its hidden ones (`visibility: "hide"`), which no picker shows. One of those is `codex-auto-review`: when the list lacks it and no reviewer is set, Codex's auto-review runs on the conversation's model at low effort (#1460, `TestCodexModelListPicksKeepHidden`). The account's own models kept out of agents' lists for routing groups (`provider.CodexNativeUnlisted`) are dropped from it too, hidden ones kept: every one when the codex provider is "Only through routing groups" (`Provider.Unlisted`), and those a group that unlists its members names (`Group.Unlists`). A Codex there only for failover keeps them, as it is handed no groups; `spawnChoices` drops the same ones (#1602, `TestCodexModelListUnlistedForGroups`).
- Codex's model list from the backend path (`codexModels`) is the ChatGPT backend's for its sign-in and then magpie's (`provider.CodexListed`), its ETag and every reply's `X-Models-Etag` tagged with `provider.CodexListTag` so a change has Codex ask again. A Codex there only for account failover, not connected (`CodexOwnOnly`, `agent.CodexOwnOnly`; #1385), gets the backend's alone, tagged with `provider.CodexOwnListTag`; neither tag contains the other, so connecting or disconnecting has Codex fetch the list again. The user's picks on the codex provider (`provider.CodexNativePicked`) narrow the backend's listed models. They keep its hidden ones (`visibility: "hide"`), which no picker shows. One of those is `codex-auto-review`: when the list lacks it and no reviewer is set, Codex's auto-review runs on the conversation's model at low effort (#1460, `TestCodexModelListPicksKeepHidden`). The account's own models stay in it when they are kept out of other agents' lists for routing groups, by the codex provider "Only through routing groups" (`Provider.Unlisted`) or a group that unlists its members (`Group.Unlists`): Codex's own catalog (`catalogOf("codex")`, behind `ListedFor`/`CatalogFor`) keeps `CodexOwn` entries, so the Agents page shows its Codex section, its picker offers them as magpie's, and the desk file and `spawnChoices` list them. #1602 dropped them here, and the picker then still offered them through the own-models switch while the Codex app had none (士奇 on Discord, 10-28). They are hidden from Codex through Codex's list (`provider.CodexNativeHidden`, `TestCodexModelListKeepsOwnForGroups`, `TestCodexOwnModelsListedOnlyThroughGroups`).
- The Codex app and its VS Code extension read only the first 100 of that list by priority, hidden entries counted: each asks its app-server for `model/list` with `limit: 100` and never for the next page (ChatGPT.app 26.1013, openai.chatgpt 26.51021; the CLI's `/model` lists every one). So `codexcat.Fit` ranks the list last of all: hidden entries after every listed one, and, with more than 100 listed (`codexcat.AppList`), the models Codex used in the last 30 days (`usage.CodexUsed`, most recent first, at most 100) brought into the first 100 in the order they stood, the rest kept in theirs. The user's own order (`codexcat.Order`, #855) goes first. The same holds for `/v1/codex/models` (with the models that key's Codex used alone, `usage.CodexUsedBy`, before the 1 MiB cut) and the `model_catalog_json` magpie writes (`codexcat.CatalogUsed`). `codexListTag` carries a tag of the used set (`codexcat.UsedTag`), so the ETag and `X-Models-Etag` change when Codex uses a model it hadn't; `usage.CodexUsed` is read again a minute on, or at once when `Append` writes a Codex call to a model it doesn't hold (`codexUsedNew`). `TestCodexModelListKeepsUsedModelsInTheAppsHundred`, `TestCodexCatalogKeepsTheKeysUsedModelsFirst`, `TestFitKeepsUsedModelsWhereTheCodexAppReads` and `TestCodexUsed` cover it (@ZhenLuoTTAWDTT on X).
- Reasoning state goes through magpie's translation as the vendor wrote it when the agent and the upstream speak the same API (#1445, XYenon): a non-streaming Messages request to a stream-only account, web search on the agent's own API, a plugin, failover. The IR carries it sealed (`Part.Sealed`, `SealedBy`; events `KThinkStart`, `KSealed`, `KTextSig` in [`ir.go`](../../internal/gateway/ir.go)), so each thinking block or reasoning item stays apart, whole or streamed, and a seal is written only for its own API (`sealedBy`). Anthropic's `redacted_thinking` goes back raw (to DeepSeek as a thinking block, below), and a thinking block signed with no text keeps its signature (`aBlock` still writes `"thinking": ""`, #1447), on Claude's subscription too. A Responses reasoning item keeps its id, summary and `encrypted_content`, and goes back to a Responses upstream as it came when it has no reasoning text (`sealedReasoning`; text, another vendor's, is still left out for OpenAI, #1411). Gemini's `thoughtSignature` stays on the call it signed and on text; a later call of a signed step goes without one, and only an unsigned step or Claude on Antigravity gets `skip_thought_signature_validator`. Another API's agent gets the call's signature in its id, as on chat (#687), with its length in the mark (`__ts<n>__`), so an id a client shortened carries no signature and the call goes as unsigned (#1536); it gets no one else's seal. The signature itself is kept in magpie's folder, `gemini-signatures/<key>`, named by its hash (`keepSignature` in [`gemini_sigstore.go`](../../internal/gateway/gemini_sigstore.go)), and the id carries only the key (`__tsk16__<key>`), so an id stays under 64 characters however long the step's signature (#2411: LobeHub's PostgreSQL index turned away a 3KB id). A key magpie no longer has, or whose file doesn't hash to it, reads as no signature; one not read for 90 days is removed. Where the folder can't be written, the id carries the signature as before. Across APIs, only Claude's reasoning is carried to a Responses client, below.
- Claude's reasoning goes to a Responses client (Codex) in an envelope and comes back as Claude wrote it (mysterious_dove_96933 on Discord). Anthropic wants a tool loop's next request to have the turn's thinking blocks, signed, and its `redacted_thinking` whole, or answers 400; Codex with `store: false` keeps only a reply's items, and of a reasoning item only `encrypted_content` is opaque. So the Anthropic decoders name a signature as Claude's (`KSig` with `sealAnthropic`, `Part.SignedBy`), and the Responses encoder and `renderResponses` give each thinking block a reasoning item whose `encrypted_content` is `magpie-claude1:` and the block's JSON in base64 (`claudeThinking`, [`internal/claudeseal`](../../internal/claudeseal/claudeseal.go)): its summary with it, an empty summary for a block signed with no text, and a `redacted_thinking` block as an item of its own. `parseResponses` reads such an item back into the block (`claudePart`), in order, so `anthropicBody` sends it as it was; an envelope that can't be read is its summary, as before. A Gemini thought's signature isn't named, and isn't sealed. The envelope goes to no Responses API: `passthrough` and `forwardOnce` take it out (`withoutClaudeSeals`: the item keeps its summary, one with none goes), `codexInputAs` leaves such an item out for Codex's own models as it does one with nothing sealed, and `codexUpstreamOn` takes it out before the ChatGPT backend; OpenAI's own `encrypted_content` is untouched. `redact.MaskJSON` keeps it whole (a reasoning item's seal), so the placeholders Claude was sent stay in what its signature covers. Claude's subscription names its signatures too, so Codex gets the same items, though its tool loop goes on inside Claude Code's own run, which keeps the thinking itself. `TestCodexToolLoopGivesClaudeItsThinkingBack`, `TestClaudeBlocksNeverGoToAResponsesAPI`, `TestGeminiSignatureIsNotSealedAsClaudes`, `TestMaskJSONKeepsClaudeBlocks`.
-16
View File
@@ -1987,22 +1987,6 @@ func codexMerged(own []any, cached bool) []any {
}
own = kept
}
// and the ones kept for routing groups, every one when the codex
// provider serves only through them (#1602): a hidden one stays, as it
// does through the picks. A Codex here for account failover alone is
// handed no groups, so it keeps its own.
if all, off := provider.CodexNativeUnlisted(); (all || len(off) > 0) && !codexOwnOnly() {
kept := own[:0]
for _, m := range own {
o, _ := m.(map[string]any)
slug, _ := o["slug"].(string)
if v, _ := o["visibility"].(string); v != "hide" && (all || off[slug]) {
continue
}
kept = append(kept, m)
}
own = kept
}
// and the ones the user disabled (#1867), which are refused (codexNativeOff)
if len(provider.DisabledModels()) > 0 {
kept := own[:0]
+39 -30
View File
@@ -746,14 +746,15 @@ func TestCodexModelListHidesOnAgentsPage(t *testing.T) {
}
}
// The codex provider set to "Only through routing groups" keeps the
// ChatGPT account's own models out of Codex's list, as it keeps them out of
// every other agent's: Codex was handed all seven the backend listed, and
// with none of them in magpie's lists, the Agents page had no Codex group
// to hide (#1602). Its hidden ones (codex-auto-review) stay, and the ETag
// changes so Codex asks again. A group that keeps its members out of the
// lists (Group.Unlists) takes just those.
func TestCodexModelListUnlistedForGroups(t *testing.T) {
// The codex provider set to "Only through routing groups", or a group that
// keeps its members out of the lists (Group.Unlists), keeps the ChatGPT
// account's own models out of other agents' lists, never out of Codex's own:
// they are Codex's models, and the Agents page offers them in Codex's
// picker. #1602 dropped them, and 士奇 (Discord, 10-28) turned a group on
// to find GPT in the picker and gone from the Codex app. Codex's list, its
// "Codex" section on the Agents page, is where they are hidden from Codex,
// and that still holds.
func TestCodexModelListKeepsOwnForGroups(t *testing.T) {
codexSignedIn(t)
if err := provider.Save(provider.Provider{ID: "codex", Models: []string{"gpt-6-sol", "gpt-5.5"}}); err != nil {
t.Fatal(err)
@@ -799,40 +800,48 @@ func TestCodexModelListUnlistedForGroups(t *testing.T) {
t.Fatal("no catalog entry for the account's gpt-5.5")
}
// a group keeping its members out of the lists takes gpt-5.5 alone
// a group keeping its members out of the lists leaves them in Codex's
if err := provider.SaveGroup(provider.Group{ID: "mine", Name: "Mine", Members: []string{id}, Unlists: true}); err != nil {
t.Fatal(err)
}
got, grouped := list()
if !got["gpt-6-sol"] || got["gpt-5.5"] || !got["codex-auto-review"] || grouped == before {
t.Errorf("group unlisting gpt-5.5: %v, ETag %q then %q", got, before, grouped)
if got, _ := list(); !got["gpt-6-sol"] || !got["gpt-5.5"] || !got["codex-auto-review"] {
t.Errorf("group unlisting gpt-5.5: %v", got)
}
// the provider only through routing groups takes every one
// and so does the provider only through routing groups
if err := provider.Save(provider.Provider{ID: "codex", Models: []string{"gpt-6-sol", "gpt-5.5"}, Unlisted: true}); err != nil {
t.Fatal(err)
}
got, after := list()
if got["gpt-6-sol"] || got["gpt-5.5"] || !got["codex-auto-review"] || after == grouped {
t.Errorf("only through routing groups: %v (want codex-auto-review alone of the account's), ETag %q then %q", got, grouped, after)
got, unlisted := list()
if !got["gpt-6-sol"] || !got["gpt-5.5"] || !got["codex-auto-review"] {
t.Errorf("only through routing groups: %v", got)
}
// and spawn_agent names none of them to a lead, as Codex's list
// doesn't: from models_cache.json, which Codex wrote from a list before
os.WriteFile(filepath.Join(os.Getenv("HOME"), ".codex", "models_cache.json"), []byte(`{"etag":"\"v1\"","models":[{"slug":"gpt-6-sol","visibility":"list","priority":1},{"slug":"gpt-5.5","visibility":"list","priority":2}]}`), 0o600)
for _, c := range spawnChoices(httptest.NewRequest("POST", CodexPath+"/responses", nil), "group/mine", true) {
if c.slug == "gpt-6-sol" || c.slug == "gpt-5.5" {
t.Errorf("spawn_agent offers %s", c.slug)
// other agents still don't see them
claude, _ := provider.ListedFor("claude")
for _, e := range claude {
if provider.CodexOwn(e) {
t.Errorf("claude lists %s", e.ID)
}
}
// a Codex here for account failover alone is handed no groups, and
// keeps its own
was2 := CodexOwnOnly
CodexOwnOnly = func() bool { return true }
defer func() { CodexOwnOnly = was2 }()
if got, _ := list(); !got["gpt-6-sol"] || !got["gpt-5.5"] {
t.Errorf("own only: %v", got)
// spawn_agent names them to a lead, as Codex's list does: from
// models_cache.json, which Codex wrote from a list before
os.WriteFile(filepath.Join(os.Getenv("HOME"), ".codex", "models_cache.json"), []byte(`{"etag":"\"v1\"","models":[{"slug":"gpt-6-sol","visibility":"list","priority":1},{"slug":"gpt-5.5","visibility":"list","priority":2}]}`), 0o600)
offered := map[string]bool{}
for _, c := range spawnChoices(httptest.NewRequest("POST", CodexPath+"/responses", nil), "group/mine", true) {
offered[c.slug] = true
}
if !offered["gpt-6-sol"] || !offered["gpt-5.5"] {
t.Errorf("spawn_agent offers %v", offered)
}
// hidden in Codex's list, gpt-5.5 goes from the app, and the ETag says so
if err := provider.SetHiddenModels("codex", []string{id}); err != nil {
t.Fatal(err)
}
got, hidden := list()
if !got["gpt-6-sol"] || got["gpt-5.5"] || !got["codex-auto-review"] || hidden == unlisted || hidden == before {
t.Errorf("hidden in Codex's list: %v, ETag %q, %q then %q", got, before, unlisted, hidden)
}
}
+1 -6
View File
@@ -264,18 +264,13 @@ func spawnChoices(r *http.Request, lead string, codexPath bool) []spawnChoice {
// and those the codex provider's picks leave out, every one under
// Usage only (#2530), as codexModels leaves them out of its list
keep, narrowed := provider.CodexNativePicked()
// and the ones kept for routing groups (#1602)
all, unlisted := provider.CodexNativeUnlisted()
if codexOwnOnly() {
all, unlisted = false, nil
}
type own struct {
spawnChoice
at int
}
var owns []own
for slug, e := range codexcat.CacheEntries() {
if v, _ := e["visibility"].(string); v != "list" || hidden[slug] || narrowed && !keep[slug] || all || unlisted[slug] {
if v, _ := e["visibility"].(string); v != "list" || hidden[slug] || narrowed && !keep[slug] {
continue
}
name, _ := e["display_name"].(string)
+105 -29
View File
@@ -23,35 +23,7 @@ import (
// magpie's models, which is what the switch waits for: the picker was the
// group alone, and with the group off every model was back.
func TestCodexOwnModelsStayWithGroupOn(t *testing.T) {
home := sandboxHome(t)
codexHome := filepath.Join(home, ".codex")
t.Setenv("CODEX_HOME", codexHome)
os.MkdirAll(codexHome, 0o700)
jwt := func(c any) string {
b, _ := json.Marshal(c)
return "e30." + base64.RawURLEncoding.EncodeToString(b) + ".sig"
}
auth, _ := json.Marshal(map[string]any{"auth_mode": "chatgpt", "tokens": map[string]any{
"id_token": jwt(map[string]any{"email": "a@x.y", "https://api.openai.com/auth": map[string]any{"chatgpt_plan_type": "plus", "chatgpt_account_id": "acc"}}),
"access_token": jwt(map[string]any{"exp": time.Now().Add(24 * time.Hour).Unix()}), "refresh_token": "r", "account_id": "acc"}})
os.WriteFile(filepath.Join(codexHome, "auth.json"), auth, 0o600)
os.WriteFile(filepath.Join(codexHome, "config.toml"), []byte("model = \"gpt-5.5\"\n"), 0o600)
ids := []string{"gpt-5.5", "gpt-5.4", "gpt-5.4-mini", "gpt-5.3-codex", "gpt-5.2"}
var cache []map[string]any
var live []catalog.Model
for i, id := range ids {
cache = append(cache, map[string]any{"slug": id, "display_name": id, "visibility": "list", "priority": i, "context_window": 400000})
live = append(live, catalog.Model{ID: id, Context: 400000})
}
b, _ := json.Marshal(map[string]any{"etag": "x", "models": cache})
os.WriteFile(filepath.Join(codexHome, "models_cache.json"), b, 0o600)
provider.ForgetAccounts()
t.Cleanup(provider.ForgetAccounts)
catalog.Reset()
t.Cleanup(catalog.Reset)
if err := catalog.SaveLive("codex", provider.CodexBase, live); err != nil {
t.Fatal(err)
}
ids := codexSignedInSandbox(t)
if err := provider.SetOwnModelsHidden("codex", true); err != nil {
t.Fatal(err)
}
@@ -98,3 +70,107 @@ func TestCodexOwnModelsStayWithGroupOn(t *testing.T) {
t.Fatalf("gpt-5.4 taken out of the list, own models off: picker %v", got)
}
}
// codexSignedInSandbox signs a ChatGPT account in to a sandbox Codex, with
// the models its backend lists, and returns their ids.
func codexSignedInSandbox(t *testing.T) []string {
t.Helper()
home := sandboxHome(t)
codexHome := filepath.Join(home, ".codex")
t.Setenv("CODEX_HOME", codexHome)
os.MkdirAll(codexHome, 0o700)
jwt := func(c any) string {
b, _ := json.Marshal(c)
return "e30." + base64.RawURLEncoding.EncodeToString(b) + ".sig"
}
auth, _ := json.Marshal(map[string]any{"auth_mode": "chatgpt", "tokens": map[string]any{
"id_token": jwt(map[string]any{"email": "a@x.y", "https://api.openai.com/auth": map[string]any{"chatgpt_plan_type": "plus", "chatgpt_account_id": "acc"}}),
"access_token": jwt(map[string]any{"exp": time.Now().Add(24 * time.Hour).Unix()}), "refresh_token": "r", "account_id": "acc"}})
os.WriteFile(filepath.Join(codexHome, "auth.json"), auth, 0o600)
os.WriteFile(filepath.Join(codexHome, "config.toml"), []byte("model = \"gpt-5.5\"\n"), 0o600)
ids := []string{"gpt-5.5", "gpt-5.4", "gpt-5.4-mini", "gpt-5.3-codex", "gpt-5.2"}
var cache []map[string]any
var live []catalog.Model
for i, id := range ids {
cache = append(cache, map[string]any{"slug": id, "display_name": id, "visibility": "list", "priority": i, "context_window": 400000})
live = append(live, catalog.Model{ID: id, Context: 400000})
}
b, _ := json.Marshal(map[string]any{"etag": "x", "models": cache})
os.WriteFile(filepath.Join(codexHome, "models_cache.json"), b, 0o600)
provider.ForgetAccounts()
t.Cleanup(provider.ForgetAccounts)
catalog.Reset()
t.Cleanup(catalog.Reset)
if err := catalog.SaveLive("codex", provider.CodexBase, live); err != nil {
t.Fatal(err)
}
return ids
}
// The codex provider "Only through routing groups" (只通过路由分组使用), or a
// group that lists itself alone, keeps the ChatGPT account's models out of
// other agents' lists but in Codex's own (士奇 on Discord, 10-28: "开启路由组
// 以后,agent 设置页面,模型列表里就是丢失 codex 供应商和对应模型,在下拉
// 选项中虽然能显示 codex 模型但是实际codex 应用中是没有的"). Codex's list
// has its Codex section, so its picker offers them as magpie's and there is
// no own-models switch to show them by.
func TestCodexOwnModelsListedOnlyThroughGroups(t *testing.T) {
ids := codexSignedInSandbox(t)
codex, err := agent.Find("codex")
if err != nil {
t.Fatal(err)
}
check := func(when string, unlisted ...string) {
t.Helper()
own := map[string]bool{}
for _, m := range agentModelList(codex) {
if m.Own {
own[m.ID] = true
}
}
for _, id := range ids {
if !own["codex/"+id] {
t.Errorf("%s: codex/%s not in Codex's list %v", when, id, own)
}
}
if codex.OwnModels(codex.Values()) {
t.Errorf("%s: Codex's list offers a switch for its own models", when)
}
var picks []string
for _, f := range agentFields(codex, codex.Values()) {
if f.Key == "model" {
for _, o := range f.Options {
picks = append(picks, o.Value)
}
}
}
for _, id := range ids {
if !slices.Contains(picks, id) {
t.Errorf("%s: %s not in Codex's picker %v", when, id, picks)
}
}
for _, e := range func() []provider.Entry { l, _ := provider.ListedFor("claude"); return l }() {
if provider.CodexOwn(e) && slices.Contains(unlisted, e.ID) {
t.Errorf("%s: Claude Code lists %s", when, e.ID)
}
}
}
if err := provider.SaveGroup(provider.Group{ID: "mygpt", Name: "MyGPT", Members: []string{"codex/gpt-5.5", "codex/gpt-5.4"}, Unlists: true}); err != nil {
t.Fatal(err)
}
check("group lists itself alone", "codex/gpt-5.5", "codex/gpt-5.4")
p, err := provider.Find("codex")
if err != nil {
t.Fatal(err)
}
q := *p
q.Unlisted = true
if err := provider.Save(q); err != nil {
t.Fatal(err)
}
var all []string
for _, id := range ids {
all = append(all, "codex/"+id)
}
check("only through routing groups", all...)
}
+2 -32
View File
@@ -474,7 +474,7 @@ func CodexNativeHidden() map[string]bool {
}
off := ModelOff("codex")
out := map[string]bool{}
for _, e := range Catalog() {
for _, e := range catalogOf("codex") {
if CodexOwn(e) && off(e.ID) {
out[e.Model] = true
}
@@ -482,28 +482,6 @@ func CodexNativeHidden() map[string]bool {
return out
}
// CodexNativeUnlisted is the ChatGPT account's own models kept out of the
// lists agents see, which the backend lists to Codex all the same: every
// one (all) when the codex provider serves only through routing groups
// (Provider.Unlisted), and by slug those a routing group keeps out of the
// lists (Group.Unlists). The gateway drops them from its /models answer as
// it does the ones hidden; Codex then reaches them only through its groups
// (#1602). A provider switched off keeps none out: it serves nothing, and
// its setting is kept for when it is switched on again.
func CodexNativeUnlisted() (all bool, slugs map[string]bool) {
p, ok := find(All(), "codex")
all = ok && !p.Off && p.Unlisted
for _, e := range Unlisted() {
if CodexOwn(e) {
if slugs == nil {
slugs = map[string]bool{}
}
slugs[e.Model] = true
}
}
return all, slugs
}
// CodexOrder is where each model of Codex's list goes when the user put
// them in an order of their own on the Agents page (#855), by the slug
// Codex knows it by — a ChatGPT account's own by its bare one, as the
@@ -519,7 +497,7 @@ func CodexOrder() (map[string]int, bool) {
at[id] = i
}
out := map[string]int{}
for _, e := range Catalog() {
for _, e := range catalogOf("codex") {
i, ok := at[e.ID]
if !ok {
continue
@@ -563,14 +541,6 @@ func buildCodexListTag(kind string) string {
ms = append(ms, catalog.Model{ID: "~picked:" + slug})
}
}
// and those kept out of the lists for routing groups (#1602)
all, unlisted := CodexNativeUnlisted()
if all {
ms = append(ms, catalog.Model{ID: "~unlisted"})
}
for _, slug := range slices.Sorted(maps.Keys(unlisted)) {
ms = append(ms, catalog.Model{ID: "~unlisted:" + slug})
}
// and the models the user disabled (#1867)
for _, pat := range DisabledModels() {
ms = append(ms, catalog.Model{ID: "!" + pat})
+22 -2
View File
@@ -2447,12 +2447,32 @@ type Entry struct {
// Catalog lists the routing groups, then every exposed model of every ready
// provider not kept unlisted. A provider switched off has none in it.
func Catalog() []Entry {
func Catalog() []Entry { return catalogKeeping(nil) }
// catalogOf is the catalog agent's lists start from: Catalog, and for
// Codex the ChatGPT accounts' own models as well when they are kept out
// of the lists, the codex provider used only through routing groups
// (Provider.Unlisted) or a group listing alone (Group.Unlists). Codex
// reaches those on its own sign-in, its app lists them from the ChatGPT
// backend, and keeping them for routing groups is about magpie's offer to
// the other agents and /v1/models: Codex's list kept no Codex section, so
// the app lost GPT while Codex's picker still offered it (士奇 on
// Discord). The user takes them out of Codex's list there (HiddenModels,
// PickedModels), which the gateway follows (CodexNativeHidden).
func catalogOf(agent string) []Entry {
if !strings.EqualFold(agent, "codex") {
return Catalog()
}
return catalogKeeping(CodexOwn)
}
// catalogKeeping is Catalog with the unlisted models keep says, too.
func catalogKeeping(keep func(Entry) bool) []Entry {
entries := providerEntries()
out := slices.Clone(groupEntries(entries)) // held: the caller's to change
kept := unlistedByGroups(entries)
for _, e := range entries {
if !e.Provider.Unlisted && !kept[e.ID] {
if !e.Provider.Unlisted && !kept[e.ID] || keep != nil && keep(e) {
out = append(out, e)
}
}
+1 -1
View File
@@ -80,7 +80,7 @@ func CatalogFor(agent string) (shown, hidden []Entry) {
// ListedFor is the catalog agent's visibility gives it, the models it may
// pick to show or not among, and what the visibility keeps from it.
func ListedFor(agent string) (listed, kept []Entry) {
all := Catalog()
all := catalogOf(agent)
names, ok := VisibleTo(agent)
if !ok {
return InOrder(agent, all), nil