Commit Graph
2 Commits
Author SHA1 Message Date
yetone 87a983423e codexcat: Codex's own GPT models stay in the Codex app's first 100 whatever the user's order (maiya on Discord)
maiya (Discord): after updating, the Codex app lists magpie's models and
none of Codex's own GPT ones.

Cause: the Codex app and its VS Code extension read the first 100 of the
list by priority (codexcat.AppList). codexMerged ranks the list by the
user's order from the Agents page (codexcat.Order, #855), where a model
the order doesn't name goes after every one it does, and codexcat.Fit
only brought the models Codex used back into the 100. The GUI saves the
whole shown list as the order, so an order saved while Codex's list had
no Codex section (the codex provider kept for routing groups before
a3ee00c05, Codex not yet signed in, or a GPT model OpenAI added since)
names 100+ of magpie's models and none of the account's: every unused
GPT model then landed at 101+ and was in no picker of the app. Since
add927e60 the app's desk list (CodexDesktopCatalog) is codexMerged's
too, so this reaches the app beside the ChatGPT sign-in, not only the
backend list.

Fix: codexcat.FitOwn keeps Codex's own listed models in the first 100
ahead of the used ones, in the order they stood; hidden entries still go
last, and a model the user hid in Codex's list was already taken out
before (CodexNativeHidden/CodexNativePicked). codexMerged passes the
backend's slugs; the siblings, /v1/codex/models (codexCatalog) and the
model_catalog_json file (CatalogUsed), pass a ChatGPT account's codex/...
entries (codexcat.ChatGPTOwn). Fit is FitOwn with none. Documented in
docs/subsystems/gateway-routing.md.

Tests:
- gateway TestCodexModelListKeepsOwnModelsInTheAppsHundred: the exact
  setup (ChatGPT sign-in, 130 magpie models, a Codex order naming all 130
  and no GPT model, the backend listing gpt-6-sol, gpt-5.5 and the hidden
  codex-auto-review): on 298bfce59 gpt-6-sol and gpt-5.5 were at 131 and
  132; now in the first 100, auto-review last, magpie's first 98 in the
  user's order.
- codexcat TestFitOwnKeepsCodexsOwnInTheAppsHundred and
  TestCatalogUsedKeepsChatGPTOwn.

Broken by hand: FitOwn with own forced to nil: all three red (131/132,
priority 131); restored, green.

Checked and not real (no change): CodexNativeHidden hiding an own model
while another ChatGPT entry for it is picked. There is one ChatGPT
provider ("codex"), one entry per slug however many accounts are saved,
and catalogOf adds an unlisted own entry once. A probe test (two
accounts, only-picked with both picked, a group that Unlists gpt-5.5, a
plain group, the provider Unlisted, back to hide mode) kept both slugs
out of CodexNativeHidden and in /backend-api/codex/models at every step
on 298bfce59.

Run (mote-run, this tree on 298bfce59): gofmt -l clean; go vet,
GOOS=linux go vet -tags nogui and GOOS=windows go vet on codexcat and
gateway: ok; go test -tags nogui -count=1 -timeout 45m ./internal/codexcat
./internal/gateway ./internal/provider ./internal/agent: all ok
(gateway 633s). Rebased onto b119f8777 (it changed codex_backend.go
elsewhere): gofmt, the three vets and go test ./internal/codexcat
./internal/gateway again: ok (gateway 627s).
Rebased again onto b5d2858f4 (internal/usage), then 40f206dff (vertex): gofmt, vets, codexcat and
usage ok, gateway -run Codex ok (54s); the whole gateway package not rerun.
Not run: the full suite (another session's full run was on mote).
Not tried: a real Codex app or VS Code extension, or maiya's own
settings (her order and provider setup are inferred, not seen).
2026-10-29 00:37:44 +08:00
yetone 28f3c4d7fd codex: the Codex app's first 100 models hold the ones used, hidden ones last
@ZhenLuoTTAWDTT on X: with Codex on magpie the model list stops short,
and the models past it can't be chosen.

Cause, from the clients' own code: the Codex app (ChatGPT.app
26.1013.40934, app-initial-90eb42395b7d.js) and the VS Code extension
(openai.chatgpt 26.51021.22027, model-queries-667cf4bd657d.js) both ask
their app-server for model/list with includeHidden, cursor null and
limit 100 (e?.limit??100) and never ask for nextCursor. codex-rs's
list_models pages the list sorted by priority, hidden entries counted,
so anything past the 100th is in no picker there. The CLI's /model
(tui model_popups.rs) lists every preset in a scrolling popup and has no
cap. magpie truncated nothing; its models are numbered after the
account's own, so a user with many models lost everything past ~100 in
the app, while hidden entries (codex-auto-review and the like) took
slots at the top.

Fix: codexcat.Fit ranks the list last of all, on every route magpie
hands Codex a list (/backend-api/codex/models after the user's own
order, /v1/codex/models before its 1 MiB cut, and the
model_catalog_json file via CatalogUsed): hidden entries go after every
listed one, and with more than 100 listed, the models Codex used in the
last 30 days (usage.CodexUsed, most recent first, at most 100; on
/v1/codex/models only the asking key's, CodexUsedBy) are brought into
the first 100 in the order they stood. The rest keep their order. The
list's ETag and X-Models-Etag carry a tag of the used set
(codexcat.UsedTag), so Codex asks again when it uses a model it hadn't;
CodexUsed is read at most once a minute, or at once when Append writes a
Codex call to a model it doesn't hold. Documented in
docs/subsystems/gateway-routing.md.

Tests (each red on the old code, broken by hand: Fit a no-op, the gateway
calls and the used tag removed, Append's codexUsedNew removed):
TestFitKeepsUsedModelsWhereTheCodexAppReads, TestFitLeavesAShortListsOrder,
TestCatalogUsedFits, TestUsedTagIsTheSet (codexcat), TestCodexUsed
(usage), TestCodexModelListKeepsUsedModelsInTheAppsHundred and
TestCodexCatalogKeepsTheKeysUsedModelsFirst (gateway).

Real run: codex-cli 0.162.1's app-server in a sandbox CODEX_HOME (never
~/.codex) with a model_catalog_json of 3 hidden entries at priority 1-3
and 150 listed models, driven over stdio with the app's own request
(model/list includeHidden, limit 100). Before: page 1 held 100 of 153,
3 of them hidden, the last many/model-096, nextCursor "100". The same
catalog put through Fit with many/model-140 used: page 1 has no hidden
entry and ends with many/model-140. The TUI's /model scrolled to all
150 (tmux).

Run with this change on e4ca47b0f: gofmt -l clean; go vet
-tags nogui with GOOS=linux and GOOS=windows on codexcat, usage, gateway
and agent clean. go test -count=1 -timeout 45m: codexcat ok, usage ok;
-run 'Codex|Fit|Used|ModelList|Catalog' on gateway, usage and agent ok
(122s, 11s, 80s). The whole gateway and agent packages ran too, but the
machine's disk was full under other sessions' runs (209M to 2.5G free),
and 959 lines of that log are "no space left on device". Of the reds,
three are not that: TestFolderVarsAreListed is #3884 (CARGO_HOME, red on
main since e4552cca9); TestHistoryKeepsDaysAndDropsOld (gateway) and
TestSuffixModesReachAgentFiles (agent) failed beside half-written
settings files and pass alone 3 of 3 at this commit. Not run: the full
./... suite (no room on the disk); the Codex app and VS Code extension
themselves against a magpie with this change (their request was read
from their bundles and replayed against a real app-server).

Rebased on ca8a6f346 (agent rename and Codex app route, claude_runs in
gateway) and run again: GOOS=windows go vet on agent
and gateway clean; -run 'Codex|Fit|Used|ModelList|Catalog' ok on
codexcat, usage and gateway (75s), and with |Rename ok on agent (68s).
Then rebased on 94c2aaecb (usage rename) and usage run whole again: ok
(88s).
2026-10-27 18:37:16 +08:00