Commit Graph
4 Commits
Author SHA1 Message Date
yetone 1e1068c86c codex: "Same as the lead" holds every subagent to the lead's model (cleverpigo on X)
cleverpigo (Windows, Codex App 26.1027.6604.0) had Codex's lead on
WorkBuddy's DeepSeek-V4.1-Flash, the subagent model on what the GUI called
"Same as the lead", and the Routing page still showed a subagent on
gpt-5.6-sol through Codex's own sign-in.

Cause: that setting, unset, never held a subagent to anything. Since
67c8f562c (mengxiao) a subagent keeps the model its lead names in
spawn_agent (codexFollowTo leaves subagents alone; codexSubagentPick
returns nil with nothing set), and Codex lists its own models first under
spawn_agent's model overrides, so the DeepSeek lead named gpt-5.6-sol.
Codex's side calls use luna, terra or codex-auto-review, not sol, so it
was the subagent, not a side call.

Now:
- "lead" (settings.CodexSubagentLead / provider.CodexSubagentLead) is a
  value of CodexSubagentModel: every Codex subagent goes on the model the
  lead's own turns last went on (codexLeads.lookup), whatever it names.
  The trace says so (SubagentPick.Lead) and Routing tells it as "the
  model its lead is on".
- A lead on one of Codex's own models is followed on the ChatGPT backend
  route only; in serve such a lead leaves the request as asked. With no
  lead turn seen, a subagent goes as asked.
- The GUI's picker offers "Lead's pick" (unset, mengxiao's case, as
  before) and "Same as the lead" (the new value); the texts say which one
  holds the subagents. en, zh, zh-TW, ja and de.
- No prompt text sent to a vendor changes.

Users who had it unset stay on Lead's pick; the label now says what it
does, and they pick Same as the lead to hold their subagents.

Docs: agent-wiring.md (subagent model field), gateway-routing.md
(CodexSubagentModel paragraph).

Ran, on mote through mote-run at this tree (base origin/main 50265256b):
- go test -tags nogui ./internal/gateway (whole package, -timeout 45m): ok
- go test -tags nogui ./internal/provider ./internal/settings
  ./internal/settingsapi: ok; -run Codex ./internal/agent ./internal/gui:
  ok; -run Budget ./internal/gui (TestCoreScriptBudget): ok
- go vet ./..., GOOS=windows go vet ./..., GOOS=linux go vet -tags nogui
  ./... (and -tags nogui darwin/windows): clean; gofmt -l: nothing
- node --test, both engines: codex-subagent-model (now picks Same as the
  lead and back, sheet row, Routing story of a lead-moved subagent, five
  languages), codex-subagents-lead, i18n-keys, routing-request-model,
  routing-sealed-task: pass. routing-story-shrinks is red in WebKit (4
  subtests, "held while under way"), the same alone at origin/main
  50265256b: #3954.

Broken by hand (in mote's copy only):
- lead lookup turned off in codexSubagentPick: both new tests red
  (TestCodexSubagentFollowsTheLeadWhenSet: "ChatGPT was asked for
  [gpt-5.6-sol]", the reporter's case).
- codexBackend's gate back to bare models only:
  TestCodexSubagentFollowsALeadOnCodexsOwnModel red.
- On the old code the tests don't build (no "lead" value), and
  SetCodexSubagentModel refused "lead".

Not tried: a real Codex App/CLI with a DeepSeek lead spawning a subagent,
and nothing on Windows (the change has no OS-specific path). The whole GUI
suite wasn't run: mote had two other sessions' full GUI suites going.
2026-11-03 23:12:33 +08:00
yetone ef63ef4a22 provider: Codex's subagent models are kept while the catalog is held
Codex's Agents row asked CodexSubagentModels each poll, and each time it
took a copy of Codex's whole catalog (CatalogFor) and made a list from
it: 21.8 MB of forty polls of the Agents, Providers and Drift answers
with real accounts. The list is now kept as the catalog is (keptOf, per
provider.StampNow and keptFor), read from the catalog's own kept lists
(catalogKept) without a copy, and clipped so a caller appending makes
a list of its own. Its one caller, codex.go, only ranges over it.

TestCodexSubagentModelsKept: 200 models of a relay under Hold; asking
again allocates a quarter or less of what building them does.

Run on mote at c1457f2ee plus this change:
- gofmt; go vet darwin, windows, linux: ok
- TestCodexSubagentModelsKept alone 3/3 ok
- broken by hand (CodexSubagentModels builds each time): red, "allocated
  1089523 bytes, building them 1089513"
- go test ./internal/provider ./internal/agent -timeout 45m: agent ok
  (231.7s); provider ok but for this test's first version, whose
  allocation-count bar failed (StampNow's stats count too); the test now
  compares bytes and was run alone and broken again as above, not in the
  whole package again
- real accounts, sandbox HOME, network blocked, 40 polls, against
  c1457f2ee: CodexSubagentModels 21.8 MB -> not in the profile;
  codexIn.func84 22.3 MB -> gone; Picks 135 -> 92 MB; state and drift
  answers byte for byte the same, providers the same but for its
  fetched times; footprint peak 135 MB, RSS at end 178 MB

Not run: the GUI suite (no GUI file changed), Windows and Linux test runs.

Rebased onto e4384fc3c (gateway, redact and GUI commits, none in internal/provider or internal/agent); not run again there.
2026-11-01 06:46:50 +08:00
yetone 221e24a3c7 agents, gateway: Codex's subagent model offers every provider's models, not only ChatGPT's (#1633, laacmilan)
The Agents page's Codex "subagent model" field (settings.CodexSubagentModel,
which the gateway puts x-openai-subagent collab_spawn requests on) listed
only the ChatGPT accounts' models, and its setter refused any other
provider's. A user whose lead runs on a chat provider (Token中心, 智谱Plan)
couldn't put its subagents there.

- provider: CodexSubagentModels is Codex's shown catalog
  (CatalogFor("codex"), so hidden or unpicked models stay out), ChatGPT
  accounts first, routing groups included. SetCodexSubagentModel takes any
  provider/model or group id, refuses a bare Codex name.
  CodexSubagentUnserved says "magpie doesn't serve it now" for a non-ChatGPT
  id that isn't served. CodexAccountModel exported.
- gateway: codexSubagentPick gets the body. When the lead ran on the
  ChatGPT backend the task arrives sealed (encrypted_content), and only a
  ChatGPT account can open it: set to another provider, such a subagent
  stays on the model asked for, with Kept = sealedKept in the route trace
  (#1613's constraint; the reverse, a chat lead with a subagent on ChatGPT,
  was already handled by 149ab950e). A plain task moves, and sealed
  MESSAGE items are stripped as before.
- gui: i18n for both new reasons (zh, zh-TW, ja, de); the GUI test lists a
  chat provider's model and shows the sealed reason in every language.
- docs: agent-wiring and gateway-routing say the same.

Run:
- go test ./internal/gateway/ ./internal/agent/ ./internal/provider/
  ./internal/gui/ (ok), gofmt -l clean, GOOS=linux and windows go vet
  -tags nogui on the four packages.
- GUI node tests (codex-subagent-model, routing-kind, i18n-keys,
  codex-start-model-field, gui-ja, gui-de, gui-zh-tw) in Chromium and
  WebKit: 38/38.
- Broken by hand: without the sealed check,
  TestCodexSubagentSealedTaskStaysOffAChatProvider fails with a 400;
  options limited to ChatGPT entries, TestCodexSubagentModelTakesAnyProvider
  fails; options from Served() instead of Codex's shown catalog,
  TestAgentModelLineAllHidden and TestAgentModelsOnlyPicked fail.
- Sandbox HOME e2e with the built binary and a fake chat upstream:
  `magpie codex subagent_model token/gpt-6.1-sol` set, a bare gpt-5.5
  refused; a collab_spawn plain-task request on gpt-6-astra to
  /backend-api/codex/responses was answered by token/gpt-6.1-sol and the
  upstream got the task text.

Not tried: a real Codex CLI or ChatGPT account; the sealed case only in
unit tests.
2026-10-11 23:43:37 +08:00
yetone 189586612e agents, gateway: Codex's subagents go on a model set in its row, a ChatGPT account's (willz on Discord)
Codex's lead names each subagent's model itself in spawn_agent, and
Codex's [agents] config can't overrule it. The Agents page's Codex row
now has a "subagent model" square (the app's model picker, Default
first). Its options are only models a ChatGPT account in magpie serves,
because a subagent's task is sealed for ChatGPT accounts.

- settings.CodexSubagentModel holds it. It is an agent Field
  (subagent_model), so the TUI/CLI, profiles, davsync's "agents" part
  and WSL twins carry it too. The setter refuses another provider's
  model. It keeps a ChatGPT account's model that isn't served now, so a
  backup restored on another computer still applies (ApplyFields stops
  at the first failed Set). POST /api/settings keeps it.
- The gateway (codexSubagentPick) moves a collab_spawn request onto it.
  codexBackend does this for Codex's own bare models; serve() does it
  for any other model. When no ChatGPT account on in magpie serves it,
  or a held gateway key may not use it, the request stays on the model
  asked for. Route.Subagent records asked/to/kept. The lead's turns,
  titles, guardian and the rest are never moved. Off (the default)
  changes nothing.
- Routing page: kindWhy says the subagent was put on the model set, or
  stayed on its own and why. "only account on for" names the model it
  went on. Strings added in zh, zh-TW, ja and de.
- docs/subsystems: gateway-routing.md and agent-wiring.md describe it.

Run (darwin, rebased on origin/main):
- gofmt -l internal/: clean.
- go vet -tags nogui on gateway, provider, agent, gui and settings:
  darwin, GOOS=linux and GOOS=windows.
- go build ./...
- HOME=<temp> go test -tags nogui ./...: all ok.
  TestSettingsSaveKeepsWhatItDoesNotSend flagged the new field; it is
  now set there.
- GUI tests, Chromium + WebKit:
  - codex-subagent-model.test.cjs: 20/20 (en, zh, zh-TW, ja, de at
    1100 and 560 px).
  - Also green: routing-kind, subagent-effort, codex-memories,
    codex-memories-settings, i18n-keys, gui-ja, gui-de, gui-zh-tw and
    click-scroll.

Failing without the change (codexSubagentPick returning nil):
- TestCodexSubagentPutOnTheModelSet
- TestCodexSubagentOnAnotherProviderPutOnTheModelSet
- TestCodexSubagentModelNotServedKeepsTheAsked
- TestCodexSubagentModelHeldKeyKeepsTheAsked
TestCodexSubagentModelLeavesOtherRequests guards the other side: the
lead's turns, titles and guardian stay untouched.

Not tried with a real Codex CLI and ChatGPT account. A subagent spawn
needs a signed-in Codex home, and this session may not touch the live
~/.codex. The fake ChatGPT backend tests cover both routes.
2026-10-09 23:38:50 +08:00