Commit Graph
7 Commits
Author SHA1 Message Date
yetone a3ee00c05c 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.
2026-10-28 14:26:18 +08:00
yetone 32f7c4de14 provider: Usage only keeps the ChatGPT account's models out of Codex's own picker, spawn_agent and its list's ETag (#2530)
What changed: CodexNativePicked narrows the backend's own list to none of
the account's visible models when the codex provider is Usage only
(noModels, ServesNone), before the empty-picks fallback that left the list
whole. codexModels' existing filter then drops them from
/backend-api/codex/models; the hidden entries Codex runs jobs of its own on
(codex-auto-review, gpt-reserve) and other providers' models stay. A
provider switched off keeps the native list as before.

Ported from skygunner's a016fcee (on ggbdpq's diagnosis and proposed
ServesNone fix in #2530), with its test TestCodexUsageOnlyCatalog. Two
siblings that read the same narrowing were missing it, for picks too:
- spawnChoices (spawn_agent's list of the account's models, from
  models_cache.json) used Hidden and Unlisted but not the picks, so it
  still named every native model;
- buildCodexListTag (the list's ETag and each reply's X-Models-Etag) had
  no mark of the picks, so a running Codex never asked for the list again
  after Usage only or a new pick; it now carries ~picked and each slug.
The test covers both, and the docs row (providers-accounts.md Model picks)
says so. Not changed: codexNativeOff, so a request Codex still sends for a
native model is served as it is for an unpicked one today.

Run at this head (sandbox HOME, pinned caches):
- go test -tags nogui -count=1 ./internal/catalog ./internal/codexcat
  ./internal/provider ./internal/agent ./internal/gateway before the
  rebase onto 508911e43: catalog, codexcat, agent and gateway ok;
  provider crashed in TestUnreadLoginsWriteErrorsKeepCredentials with
  "close of synctest channel from outside bubble" in filememo.Forget,
  which is #3632 (open, not this change).
- After the rebase onto 508911e43 (it changed internal/agent): catalog,
  codexcat ok; agent whole, with TestWSLMoreAgentsPick, TestZooCode and
  TestZooCodeFresh red on "no space left on device" (the machine's disk
  was full), then those three and -run Codex ok; provider -run Codex ok;
  gateway -run Codex ok (its first link failed on the full disk).
- gofmt -l clean; go vet ./... (darwin), GOOS=linux go vet -tags nogui
  ./... and GOOS=windows go vet ./... clean.
- Not run: the full go test ./...; it was started and stopped when the
  disk filled (under 1GB free), and is to be run after the push.

Broken by hand, TestCodexUsageOnlyCatalog red each time:
- ServesNone narrowing removed: usage_only "models = [codex-auto-review
  fake/m1 gpt-5.5 gpt-6-sol gpt-reserve], want [codex-auto-review fake/m1
  gpt-reserve]";
- picks left out of the tag: "ETag kept across Usage only" (all four
  ETags +magpie-68fdb6e54074);
- picks left out of spawnChoices: usage_only "spawn_agent offers the
  account's [gpt-6-sol gpt-5.5], want []", picked_again "[gpt-6-sol
  gpt-5.5], want [gpt-6-sol]".

Not tried: a real ChatGPT account with Codex Desktop refreshing its list;
the backend reply is a synthetic catalog of the reported visible/hidden
shape.

Refs #2530 (left open for the reporter)
Co-authored-by: vincent <webmaster@palmit.com.au>
Co-authored-by: ggbdpq <ggbdpq@gmail.com>
2026-10-27 14:28:01 +08:00
yetone b97e0aa2a2 gateway: spawn_agent is widened without writing the whole Codex body again (#3394)
Codex sends spawn_agent with every request, so spawnAgentModels ran on
each one: it decoded the whole body into a map, decoded every input
item into a map, and encoded the body again, so a long conversation
was walked three times a request, and went upstream with its keys
sorted. It now takes tools (and input, only when it holds a
tool_search_output) with topMember, widens them as before, and puts
the new values back in place (withMembers); every other byte goes on
as Codex sent it. Only a tool_search_output item is decoded and
written again (moreSpawnItem); an input with an item that isn't an
object no longer stops the others being widened.

Run:
- A 1.6MB body (Codex 0.162.0's tools from testdata, 300 tool outputs),
  30 calls in a scratch test not committed: 16.4ms a call before, 2.3ms
  after.
- Real DeepSeek account in a sandbox HOME, magpie serve on 3482, 12
  streamed /v1/responses requests of a synthetic 1.5MB conversation with
  Codex 0.162.0's real tools and a codex_cli_rs/0.162.1 User-Agent (so
  the spawn path runs), CPU time from ps, two rounds each: d792e7ce4
  0.90s and 0.92s, this 0.78s and 0.78s, about 75ms -> 65ms a request.
  All 48 answered 200. Without the Codex User-Agent the two are the
  same (0.67s and 0.65s), as they should be.
- New TestSpawnAgentModelsLeavesTheRestAsSent: red on the old code
  (the body came back with its keys sorted), green now.
  TestSpawnAgentNamesEveryModel and ...AfterToolSearch green.
- go test ./internal/gateway -run 'Spawn|ToolSearch|Codex': ok. The
  whole gateway package passed at d792e7ce4 (398s), not at this commit.
- gofmt -l clean; GOOS=linux and windows go vet -tags nogui ./internal/gateway ok.
2026-10-25 00:47:16 +08:00
yetone 125dad5cbb gateway: a codex provider used only through routing groups keeps the ChatGPT account's own models out of Codex's list (#1602)
With Codex signed in to ChatGPT, Codex asks magpie's /backend-api/codex/models
for its list, and codexModels passes the backend's own models through,
narrowed only by the codex provider's picks (CodexNativePicked) and the
Agents page's hides (CodexNativeHidden, built from Catalog()). A provider
set to "Only through routing groups" (Provider.Unlisted) has none of its
models in Catalog(), so neither filter saw them: all of the account's
models stayed in Codex's picker, and the Agents page had no Codex group to
hide. Every other agent's list is Catalog-based and already left them out.

provider.CodexNativeUnlisted says which of the account's models are kept
out of agents' lists: every one when the codex provider is Unlisted, and by
slug those a group with Unlists names. codexModels drops them (hidden
entries such as codex-auto-review stay, as with picks; a Codex reached for
failover alone keeps them, as it is handed no groups), spawnChoices drops
the same ones from spawn_agent's list, and CodexListTag carries them so
Codex refetches. gateway-routing.md says so.

Test: TestCodexModelListUnlistedForGroups (a group unlisting gpt-5.5 takes
gpt-5.5 alone; the provider Unlisted takes gpt-6-sol and gpt-5.5 and keeps
codex-auto-review; ETag changes; spawn_agent offers neither; own-only keeps
them). With codex_backend.go and codex_spawn_models.go reverted it fails on
all three checks. Not tried with a real ChatGPT sign-in and Codex app.

Run (sandbox HOME, private GOCACHE, worktree at origin/main 97dfed0f3):
gofmt -l; go vet ./... (darwin), GOOS=linux -tags nogui, GOOS=windows;
go build for all three; go test -tags nogui ./internal/gateway
./internal/provider ./internal/catalog ./internal/codexcat: all ok.
2026-10-13 05:05:23 +08:00
yetone 403f3845e2 gateway: Codex's spawn_agent names every model also when Codex hands it to the lead through a tool search, as it does on 0.162 (Gearclickist on Discord)
Gearclickist, after v0.1.1214: the lead still saw only five models for
its subagents. v0.1.1214 (5d33f060b) widened spawn_agent in the request's
tools only. Codex 0.162 doesn't put it there for a model that can search
tools: with supports_search_tool the multi-agent V1 tools are Deferred
(codex-rs rust-v0.162.1 core/src/tools/spec_plan.rs:1475-1479), the lead
calls tool_search, and spawn_agent, with Codex's five
(core/src/agent/child_config.rs:20 MAX_SPAWN_AGENT_MODEL_OVERRIDES = 5,
used in core/src/tools/handlers/multi_agents_spec.rs:830), arrives in a
tool_search_output item in the conversation. Codex resends that item on
every later turn. magpie's /models entries and Codex's own say
supports_search_tool, so this is the usual case, and the fix never fired.

The limit is only in what Codex writes. find_spawn_agent_model_name
(child_config.rs:318) takes any model of the catalog Codex loaded; the
five also appear in its error text (child_config.rs:335).

spawnAgentModels now widens the spawn_agent in each tool_search_output
in input as well as in tools (moreSpawnTools, shared by both). The added
text is unchanged and stays neutral; base_instructions are untouched.
The same output is widened the same way on each turn, so the history
Codex resends stays byte-stable.

Run:
- Real Codex 0.162.1 in a sandbox HOME/CODEX_HOME, wired by a sandbox
  magpie (`magpie codex fake/m1`, gateway on 127.0.0.1:3593) to a fake
  Responses upstream with 40 models that calls tool_search, then
  spawn_agent with model fake/m12.
  - Before: the lead's searched spawn_agent named fake/m1..m5 only.
  - After: it names all 40, Codex's five then the other 35 under the
    added header.
  - Both times Codex accepted fake/m12 and the child's request reached
    the upstream on m12.
  - The same Codex pointed straight at the fake (no magpie) gave the raw
    request saved as testdata/workdir/codex-0.162.1-tool-search.json
    (sandbox paths replaced).
- TestSpawnAgentNamesEveryModelAfterToolSearch (/v1, CodexPath with a
  magpie lead, CodexPath with a ChatGPT lead and V1) fails on the old
  codex_spawn_models.go in all 3 subtests ("doesn't name fake/m6") and
  passes now.
- go test ./internal/gateway -count=1 under a sandbox HOME: ok.
- gofmt -l clean; go vet ./internal/gateway on darwin, GOOS=linux -tags
  nogui, GOOS=windows.

Not run: a real ChatGPT-account lead at CodexPath (covered by the stub
backend test only), the Codex App, and a V2 lead (V2 keeps spawn_agent in
tools, which v0.1.1214 already covers).
2026-10-13 02:32:23 +08:00
yetone 3c4f8f9aed gateway: the models added to Codex's spawn_agent are headed neutrally, naming neither magpie nor Codex's limit (Gearclickist on Discord)
5d33f060b added the rest of the catalog to spawn_agent's description
under "More models that may be set as `model` (Codex names only five
above; magpie serves these too):". That text goes upstream with the
prompt, to OpenAI too when the lead is a ChatGPT account, and the
project keeps Codex's prompts and identity unrewritten (ban risk). The
header is now "More models that may be set as `model`:". The check that
a description already has it (spawnMore) is unchanged, so a request is
still widened once.

TestSpawnAgentNamesEveryModel now fails when the added text names
magpie, Codex or "five".

Run: TestSpawnAgentNamesEveryModel (4 subtests) and the gateway's Codex
tests pass. With the old header restored by hand, the three subtests
that add models fail ("the added text names \"magpie\""); V2 adds
nothing and passes. gofmt -l clean; go vet ./internal/gateway on
darwin, linux (-tags nogui) and windows.
Not run: the full gateway package, a real Codex lead.
2026-10-12 23:33:14 +08:00
yetone 5d33f060b7 gateway: Codex's spawn_agent names every model a subagent may be put on, not only the first five (Gearclickist on Discord)
Gearclickist turned on "Codex subagents on any model", but when Codex
dispatched subagents only a few models could be picked. Codex itself caps
the list: spawn_agent's description names only the first five
show_in_picker models of its catalog (codex-rs child_config.rs
MAX_SPAWN_AGENT_MODEL_OVERRIDES, multi_agents_spec.rs
spawn_agent_models_description), Codex's own ahead of magpie's. Yet it
takes any catalog model by name (find_spawn_agent_model_name). So the lead
saw none of magpie's models.

spawnAgentModels (codex_spawn_models.go) adds the rest of the catalog
Codex was handed after Codex's own list, under a line of its own, at most
200. It covers spawn_agent at the top level and in Codex's multi_agent_v1
namespace, at CodexPath (codexBackend) and at /v1/responses for Codex
(handle).
- At CodexPath the list is Codex's own listed models less those hidden on
  the Agents page, then CodexListed unless Codex is held to its own.
- At /v1 it is CodexCatalog under the key's allowance.
- A lead the ChatGPT backend answers in multi-agent V2 seals its
  subagents' tasks for a ChatGPT account (#619), so it is offered Codex's
  own only.
Only the tool's description changes, never base_instructions. With V1 on,
it does change in requests to the ChatGPT backend too.

Not covered: the model_catalog_in_context feature (under development, off
by default) puts a five-model catalog in context, and it is not widened.

Run:
- go test ./internal/gateway ./internal/agent -count=1 under a sandbox
  HOME: ok.
- TestSpawnAgentNamesEveryModel uses 40 models on a real Codex 0.162.0
  request (testdata/workdir/codex-0.162.0.json). Its 4 subtests are
  CodexPath, /v1, a sealed V2 lead and a V1 lead, and all pass.
  - With spawnAgentModels returning body by hand: CodexPath, /v1 and V1
    go red.
  - With the sealed rule taken out: V2 goes red.
- go vet on darwin, GOOS=linux -tags nogui, and GOOS=windows; gofmt -l
  is clean.

Not verified: a real Codex lead picking one of magpie's models past the
fifth from the longer list.
2026-10-12 23:30:08 +08:00