Commit Graph
2 Commits
Author SHA1 Message Date
yetone 12a9970d6e gateway: a resumed Codex subagent leaves a spawn model magpie no longer serves
jockyer on X: after removing a provider and switching Codex to another
model, requests kept naming the removed provider's model. Codex's
resume_agent asks for the lead's current model, and codexResumeTo put
the subagent back on the model its thread was spawned on
(codex-subagents.json, kept 30 days and across restarts) without asking
whether that model was still served. Every resume answered 404 "magpie
knows no model a/x". A spawn model of magpie's that is now unserved
(provider removed or switched off, as standIn judges it) is no longer
gone back to. The request goes on as asked, and that model is noted as
the thread's model from then on.

Other state checked after an in-process provider.Delete (the GUI's and
CLI's path inside agent.Reseat), each with a probe test. None of these
sent a request to the removed provider:
- chat completions on its own ids and on bare shared ids, with and
  without session affinity;
- /v1/responses with Codex headers, and /v1/messages with Claude Code
  headers, on the new model and on the old one;
- the old one with StandIn wired, including claude-haiku-*;
- a routing group with a member on it, with the catalog held or not;
- a delete written by another process with no request in flight.
Server-instance state was read: codexLeads, codexTurns and
codexSubagentPick validate with Resolve or CodexSubagentUnserved.
While one request holds the catalog without a break, another process's
removal is routed past for up to about 1s (heldFor). That is filed as
#5541 and not changed here.

Run on mote (mote-run), at 6f5d48ea0 and again after the rebase on
25b201eb6:
- go test ./internal/gateway -count=1 -timeout 45m: ok (776s, at
  6f5d48ea0);
- after the rebase: go test ./internal/gateway -run TestCodex: ok
  (49s);
- go vet ./internal/gateway for darwin, linux and windows: ok;
- gofmt -l: clean.
Broken by hand: with codex_resume.go at the old code,
TestCodexResumedSubagentLeavesARemovedProvider is red (404 on the
first resume).

Not tried: a real Codex app resuming a subagent after a real provider
removal. The reporter's "until the gateway restarted" was not
reproduced. A restart doesn't clear codex-subagents.json, so this
fix may not be their whole case. Settings' own model picks
(CodexTitles, CodexDescriptions and the like) that name a removed
provider were not checked.
2026-11-06 22:36:23 +08:00
yetone 25bf394a72 gateway: a resumed Codex subagent goes back on the model it was spawned on
HoGee_xxl on X: a Codex subagent brought back with resume_agent ran on
the lead's model, not the one the lead spawned it on.

Codex's multi-agent V1 (the one magpie's own models ask for) builds the
resumed subagent's config from the lead's current turn:
codex-rs core/src/agent/child_config.rs build_agent_resume_config ->
build_agent_shared_config sets config.model to turn.model_info().slug,
and core/src/agent/control/spawn.rs resume_single_agent_from_rollout
starts the thread on that config without reading back the thread's
stored model. Neither the spawn_agent model nor [agents]
default_subagent_model is asked again. V2's ensure_v2_agent_loaded does
put a thread back on its stored model, so this follows Codex's own rule.

The gateway now notes the model each Codex subagent thread (thread_id in
x-codex-turn-metadata / client_metadata; session_id only on a Codex old
enough not to share it) first asked for, and puts a later request of
that thread asking for another back on it. Kept in codex-subagents.json
beside providers.json (0600, temp file and rename, the 512 latest, 30
days), so a resume after a restart is known. A model set for every
subagent (codexSubagentPick) still wins. No prompt or base_instructions
is touched.

Run (mote-run): go test ./internal/gateway -run 'TestCodexResumed|
TestCodexSubagentThreadOf|TestCodexSubagent|TestCodexFollow|
SessionMetadata|TestCodexSide' -count=1: ok.
Broken by hand: skipping the restore in codex_backend.go turns
TestCodexResumedSubagentKeepsItsSpawnModel red ("worker-1 asking gpt-5.5
went on gpt-5.5, want gpt-6-astra"); skipping the save turns its
after-restart step red.
Not tried: a real Codex resume_agent run against a real ChatGPT account.
2026-10-29 03:45:57 +08:00