Skip to content

Every agent's model. One place. Codex on DeepSeek, Claude Code on Kimi, from the menu bar.

codexcat: Codex's own GPT models stay in the Codex app's first 100 whatever the user's order (maiya on Discord)

yetone87a983423edc
diff --git a/docs/subsystems/gateway-routing.md b/docs/subsystems/gateway-routing.md
index bb43072bf..6a74703d4 100644
--- a/docs/subsystems/gateway-routing.md
+++ b/docs/subsystems/gateway-routing.md
@@ -229,7 +229,7 @@ recorded as a prediction failure (`noPrediction`).
- 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 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).
+- 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.FitOwn` ranks the list last of all: hidden entries after every listed one, and, with more than 100 listed (`codexcat.AppList`), Codex's own listed models (the backend's entries in `codexMerged`; a ChatGPT account's `codex/…` ones, `codexcat.ChatGPTOwn`, on the other two routes) and then 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, so an order that names only magpie's models (set while Codex's list had no Codex section, or before OpenAI added a model) no longer puts every GPT model past the 100th (maiya on Discord); the user takes one out of the app by hiding it in Codex's list. 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`, `TestCodexUsed`, `TestCodexModelListKeepsOwnModelsInTheAppsHundred`, `TestFitOwnKeepsCodexsOwnInTheAppsHundred` and `TestCatalogUsedKeepsChatGPTOwn` 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`.
- A translated Responses reply gives Codex the reasoning items a Responses upstream sent, as it sent them; any other upstream's reasoning becomes items magpie made: an `rs_` id and a summary, nothing sealed. Codex hands them back on every turn. A request relayed as is to OpenAI's API or Azure OpenAI goes without them (`withoutBareReasoning`) unless `store` is true, because both look the id up among stored items and answer 400 "Item with id 'rs_…' not found" (#1008). Any other Responses upstream gets them, because a DeepSeek model wants its reasoning back (#388). When one answers 400 naming the input (`refusesInput`: `param` is `input`, or the error names an item by id), as a relay in front of OpenAI does with a message of its own, `passthrough` asks once more without them and, once that works, leaves them out for that provider and model from then on (`bareReasoningRefused`, #1044). Codex's compaction offers no tools, so it is relayed even when its turns were translated. The summary request magpie makes offers none either: `codexInputAs` sends `tools: []` and leaves out the `additional_tools` input item, where Codex's Responses Lite (the entry of a ChatGPT account's gpt-6 model, copied from Codex's own) puts every tool; left in, the model may call one in place of the summary (the likely cause of WuSix's codex/gpt-6-astra "the model wrote no summary" on Discord, not confirmed on a real reply), and a reply with no summary says what it held instead (`answeredWith`). A reply that called a tool instead (`calledTool`) is asked once more with the conversation as text (`plainCompact`), and compacted locally when that writes no summary either: a model deep in an exchange of calls goes on with it whatever it is offered (Lucy on Discord: DeepSeek through group/auto-deepseek-v4-1-flash answered reasoning and an `exec_command` call 3 times in a row; `TestCodexCompactToolCallAsksAgainAsText`, `TestCodexCompactToolCallEveryTimeCompactsLocally`, over Chat, Responses and Messages, a group and a single model). When a provider answers its summary request 404, 405 or 501 (`lacksEndpoint`), or 400 for an item it didn't find (`itemNotFound`, a relay in front of either), `codexCompact` asks once more with the conversation as text (`plainCompact`), then compacts locally (#866, #1008). Any other failure goes back with its status, said as the compaction's with who answered it (`compactFailed`: "compaction: <provider> (<model>, <base URL>) answered the summary request 502 Bad Gateway: …"), the vendor's code, param and Retry-After kept. A compaction relayed to OpenAI (`/responses/compact` on Codex's own model, as a `/responses` turn) that OpenAI answers with an error status and an empty body, which Codex shows as "unexpected status 502 Bad Gateway: Unknown error", or with a web page, is said in words naming the model, the status, and the account it went to (`codexSaidNothing`, outrageous_piglet on Discord); an error OpenAI says in JSON goes as it came. `TestCodexOwnCompactFailureIsSaid`, `TestCodexCompactFailureSaysCompaction`, `TestCodexCompactNoEndpointCompactsLocally`. So does the ChatGPT backend's 502 "response protection is unavailable" (`protectionRefused`): a long history refused so was answered as text. Codex also compacts remotely, a `compaction_trigger` on `/responses` that wants exactly one compaction item back, on any provider table named "OpenAI", as CC Switch names its relay tables. magpie points those at `/v1` while a magpie model is on, so `handle` makes the summary there too (`codexInput`, `codexCompact`), and magpie's summaries go back to the model as text (#1301). A summary is wanted only whole (`askWhole`, `holdWriter.wantWhole`): its stream is held to its end, not let through at its first words, so a reply cut short (`errEndedShort`), failed halfway (a 429 "Individual quota reached" after some of it) or ended `incomplete` (`endedIncomplete`, `incompleteReply`) fails over to the next candidate like a failure before any of it, and rests the account as that failure would; one that reached its output limit rests nobody. With nobody left, `codexCompact` answers 502 and never hands Codex the words before the cut as the summary (#2274, huangzuomin: Antigravity cutting each summary short). Codex with context_management's experimental mode compacts in the background at every step while the conversation is over its threshold and drops a failed compaction without a word, so a conversation whose summaries keep failing is asked again every few seconds, each paying for the whole history (1169 compactions in 6 hours there). After `compactFailsMost` (3) failed summaries in a row of one conversation (`prompt_cache_key`) on one model, each within `compactHeldFor` (5 minutes) of the last, the next is answered at once with a 400 naming the last failure, which Codex doesn't ask again, and no model is asked until 5 minutes have passed (`compactFails` in [`codex_compact_guard.go`](../../internal/gateway/codex_compact_guard.go)); a summary that comes clears the count, and a sign-in's 401 or 403 isn't counted. `TestCodexCompactCutSummaryFailsOver`, `TestCodexCompactCutSummaryIsNoSummary`, `TestCodexCompactKeepsFailingIsHeld`.
diff --git a/internal/codexcat/codexcat.go b/internal/codexcat/codexcat.go
index bef0e7c52..978334a51 100644
--- a/internal/codexcat/codexcat.go
+++ b/internal/codexcat/codexcat.go
@@ -99,10 +99,11 @@ func Catalog(ms []catalog.Model) []byte { return CatalogAt(ms, NewSessionEffort(
func CatalogAt(ms []catalog.Model, effort string) []byte { return CatalogUsed(ms, effort, nil) }
// CatalogUsed is CatalogAt with the models Codex used, most recent first,
-// kept where the Codex app reads them (Fit).
+// and a ChatGPT account's own (ChatGPTOwn), kept where the Codex app reads
+// them (FitOwn).
func CatalogUsed(ms []catalog.Model, effort string, used []string) []byte {
entries := entriesAt(ms, 0, effort)
- Fit(entries, used)
+ FitOwn(entries, used, ChatGPTOwn)
out := struct {
Models []any `json:"models"`
}{Models: entries}
@@ -113,6 +114,12 @@ func CatalogUsed(ms []catalog.Model, effort string, used []string) []byte {
return b
}
+// ChatGPTOwn reports whether slug is a ChatGPT account's own model in
+// magpie's list for Codex (codex/<slug>): Codex's own GPT models, for a
+// Codex that reaches them through magpie, which FitOwn keeps in the first
+// AppList.
+func ChatGPTOwn(slug string) bool { return strings.HasPrefix(slug, "codex/") }
+
// level, tier and model are an entry of models.json as Entries writes it.
type level struct {
Effort string `json:"effort"`
@@ -561,7 +568,15 @@ const AppList = 100
// order they stood, in place of the last of the others there. The order
// is otherwise kept, and the priorities numbered 1 to n in it. The slice
// is put in that order too.
-func Fit(entries []any, used []string) {
+func Fit(entries []any, used []string) { FitOwn(entries, used, nil) }
+
+// FitOwn is Fit with Codex's own models (own reports them by slug) kept
+// in the first AppList ahead of the ones used, wherever the user's order
+// (Order) put them: Codex lists them itself, so a user who didn't take
+// them out of its list expects them in the app. An order set while the
+// list had none of them names only magpie's, and put every one past the
+// 100th (maiya on Discord). A hidden one still goes last.
+func FitOwn(entries []any, used []string, own func(slug string) bool) {
type ranked struct {
e any
slug string
@@ -603,7 +618,17 @@ func Fit(entries []any, used []string) {
listed++
}
}
- if listed > AppList && len(used) > 0 {
+ if listed > AppList && (len(used) > 0 || own != nil) {
+ n := 0
+ // Codex's own first, then the used ones, as room allows
+ if own != nil {
+ for i := range rs[:listed] {
+ if n < AppList && own(rs[i].slug) {
+ rs[i].promoted = true
+ n++
+ }
+ }
+ }
at := map[string]int{}
for i, r := range rs[:listed] {
at[r.slug] = i
@@ -613,7 +638,6 @@ func Fit(entries []any, used []string) {
at["codex/"+r.slug] = i
}
}
- n := 0
for _, u := range used {
if i, ok := at[u]; ok && !rs[i].promoted && n < AppList {
rs[i].promoted = true
diff --git a/internal/codexcat/fit_test.go b/internal/codexcat/fit_test.go
index 19def923f..e29b8826d 100644
--- a/internal/codexcat/fit_test.go
+++ b/internal/codexcat/fit_test.go
@@ -107,3 +107,67 @@ func TestUsedTagIsTheSet(t *testing.T) {
t.Error("the tag didn't change with the set")
}
}
+
+// Codex's own models are kept in the first AppList wherever an order put
+// them, ahead of the used ones; a hidden one of them still goes last
+// (maiya on Discord: an order naming only magpie's put every GPT model
+// past the 100 the Codex app reads).
+func TestFitOwnKeepsCodexsOwnInTheAppsHundred(t *testing.T) {
+ var entries []any
+ for i := range 130 {
+ entries = append(entries, map[string]any{"slug": fmt.Sprintf("many/model-%03d", i), "priority": i + 1, "visibility": "list"})
+ }
+ for i, s := range []string{"gpt-6-sol", "gpt-5.5", "codex-auto-review"} {
+ v := "list"
+ if s == "codex-auto-review" {
+ v = "hide"
+ }
+ entries = append(entries, map[string]any{"slug": s, "priority": 131 + i, "visibility": v})
+ }
+ own := map[string]bool{"gpt-6-sol": true, "gpt-5.5": true, "codex-auto-review": true}
+ FitOwn(entries, []string{"many/model-120"}, func(s string) bool { return own[s] })
+ var order []string
+ for _, e := range entries {
+ order = append(order, e.(map[string]any)["slug"].(string))
+ }
+ first := order[:AppList]
+ for _, s := range []string{"gpt-6-sol", "gpt-5.5", "many/model-120"} {
+ if !slices.Contains(first, s) {
+ t.Errorf("%s is at %d, past the first %d", s, slices.Index(order, s)+1, AppList)
+ }
+ }
+ if order[len(order)-1] != "codex-auto-review" {
+ t.Errorf("the hidden codex-auto-review is at %d", slices.Index(order, "codex-auto-review")+1)
+ }
+ // the rest in the order they stood: 97 of magpie's from the top
+ if order[0] != "many/model-000" || order[96] != "many/model-096" || order[100] != "many/model-097" {
+ t.Errorf("the first 101: %v", order[:101])
+ }
+}
+
+// The model_catalog_json magpie writes keeps a ChatGPT account's own
+// (codex/…) models in the first AppList the same way.
+func TestCatalogUsedKeepsChatGPTOwn(t *testing.T) {
+ t.Setenv("HOME", t.TempDir())
+ t.Setenv("USERPROFILE", os.Getenv("HOME"))
+ var ms []catalog.Model
+ for i := range 130 {
+ ms = append(ms, catalog.Model{ID: fmt.Sprintf("many/model-%03d", i)})
+ }
+ ms = append(ms, catalog.Model{ID: "codex/gpt-5.5"})
+ var got struct {
+ Models []map[string]any `json:"models"`
+ }
+ if err := json.Unmarshal(CatalogUsed(ms, "", nil), &got); err != nil {
+ t.Fatal(err)
+ }
+ for _, m := range got.Models {
+ if m["slug"] == "codex/gpt-5.5" {
+ if p := m["priority"].(float64); p > AppList {
+ t.Fatalf("codex/gpt-5.5's priority is %v", p)
+ }
+ return
+ }
+ }
+ t.Fatal("codex/gpt-5.5 is not in the catalog")
+}
diff --git a/internal/gateway/codex_app_list_test.go b/internal/gateway/codex_app_list_test.go
index 9f3bcc0a5..f187c457d 100644
--- a/internal/gateway/codex_app_list_test.go
+++ b/internal/gateway/codex_app_list_test.go
@@ -118,3 +118,67 @@ func TestCodexCatalogKeepsTheKeysUsedModelsFirst(t *testing.T) {
t.Errorf("another key's many/model-111 was brought up, to %v", p)
}
}
+
+// maiya (Discord): after an update the Codex app showed magpie's models
+// and none of Codex's own GPT ones. With an order of Codex's models set on
+// the Agents page while its list had no Codex section (the codex provider
+// kept for routing groups before a3ee00c05, Codex not signed in yet, or a
+// GPT model OpenAI added since), the order names 100 or more of magpie's
+// and none of the account's, so Order put every own one after them, past
+// the 100 the Codex app reads. The account's own listed models are kept
+// in the first 100, wherever the order put them; a hidden one stays last.
+func TestCodexModelListKeepsOwnModelsInTheAppsHundred(t *testing.T) {
+ codexSignedIn(t)
+ var ms, order []string
+ for i := range 130 {
+ ms = append(ms, fmt.Sprintf("model-%03d", i))
+ order = append(order, fmt.Sprintf("many/model-%03d", i))
+ }
+ if err := provider.Save(provider.Provider{ID: "many", Name: "Many", Key: "k", Chat: "http://127.0.0.1:9/v1", Models: ms}); err != nil {
+ t.Fatal(err)
+ }
+ if err := provider.SetModelOrder("codex", order); err != nil {
+ t.Fatal(err)
+ }
+ up := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ w.Header().Set("ETag", `"v1"`)
+ io.WriteString(w, `{"models":[{"slug":"codex-auto-review","priority":0,"visibility":"hide"},{"slug":"gpt-6-sol","priority":1,"visibility":"list"},{"slug":"gpt-5.5","priority":2,"visibility":"list"}]}`)
+ }))
+ defer up.Close()
+ was := provider.CodexBase
+ provider.CodexBase = up.URL + "/backend-api/codex"
+ defer func() { provider.CodexBase = was }()
+ rec := httptest.NewRecorder()
+ req := httptest.NewRequest("GET", CodexPath+"/models", nil)
+ req.Header.Set("Authorization", "Bearer chatgpt-token")
+ New().Handler().ServeHTTP(rec, req)
+ var got struct {
+ Models []map[string]any `json:"models"`
+ }
+ if err := json.Unmarshal(rec.Body.Bytes(), &got); err != nil {
+ t.Fatal(err)
+ }
+ slices.SortStableFunc(got.Models, func(a, b map[string]any) int {
+ return int(a["priority"].(float64) - b["priority"].(float64))
+ })
+ var order2 []string
+ for _, m := range got.Models {
+ order2 = append(order2, m["slug"].(string))
+ }
+ if len(order2) != 133 {
+ t.Fatalf("%d models", len(order2))
+ }
+ first := order2[:codexcat.AppList]
+ for _, s := range []string{"gpt-6-sol", "gpt-5.5"} {
+ if !slices.Contains(first, s) {
+ t.Errorf("Codex's own %s is at %d, past the %d the Codex app reads", s, slices.Index(order2, s)+1, codexcat.AppList)
+ }
+ }
+ if order2[len(order2)-1] != "codex-auto-review" {
+ t.Errorf("the hidden codex-auto-review is at %d of %d", slices.Index(order2, "codex-auto-review")+1, len(order2))
+ }
+ // the user's order holds for the rest: magpie's first 98 as they put them
+ if !slices.Equal(first[:98], order[:98]) {
+ t.Errorf("the first 98: %v", first[:98])
+ }
+}
diff --git a/internal/gateway/codex_backend.go b/internal/gateway/codex_backend.go
index da56f5a9b..4f80cb16e 100644
--- a/internal/gateway/codex_backend.go
+++ b/internal/gateway/codex_backend.go
@@ -2024,13 +2024,23 @@ func codexMerged(own []any, cached bool) []any {
if !codexOwnOnly() {
ms = provider.CodexListed()
}
+ // Codex's own, as the user left them in its list
+ mine := make(map[string]bool, len(own))
+ for _, m := range own {
+ if o, ok := m.(map[string]any); ok {
+ if slug, _ := o["slug"].(string); slug != "" {
+ mine[slug] = true
+ }
+ }
+ }
all := append(own, codexcat.Entries(ms, len(own)+100)...)
if at, ok := provider.CodexOrder(); ok {
codexcat.Order(all, at)
}
// the Codex app and its VS Code extension read the first 100 alone:
- // hidden ones go last, and the ones the user uses are among the 100
- codexcat.Fit(all, usage.CodexUsed())
+ // hidden ones go last, and Codex's own and the ones the user uses are
+ // among the 100, wherever the user's order put them (maiya on Discord)
+ codexcat.FitOwn(all, usage.CodexUsed(), func(slug string) bool { return mine[slug] })
return all
}
diff --git a/internal/gateway/codex_catalog.go b/internal/gateway/codex_catalog.go
index f000fc449..40ae629ef 100644
--- a/internal/gateway/codex_catalog.go
+++ b/internal/gateway/codex_catalog.go
@@ -42,10 +42,11 @@ func (s *Server) codexCatalog(w http.ResponseWriter, r *http.Request) {
var b bytes.Buffer
b.Write(head)
n, out := 0, 0
- // the Codex app reads the first 100 alone (codexcat.AppList): the ones
- // this key's Codex used are among them, and kept when the end is cut
+ // the Codex app reads the first 100 alone (codexcat.AppList): a ChatGPT
+ // account's own models and the ones this key's Codex used are among
+ // them, and kept when the end is cut
entries := codexcat.Entries(ms, 0)
- codexcat.Fit(entries, usage.CodexUsedBy(access.Caller(r.Context()).KeyID))
+ codexcat.FitOwn(entries, usage.CodexUsedBy(access.Caller(r.Context()).KeyID), codexcat.ChatGPTOwn)
for _, e := range entries {
var one bytes.Buffer
enc := json.NewEncoder(&one)