Files
magpie/internal/agent/codex_side_test.go
T
yetone 67c8f562cd codex: a subagent named a model goes on it with "Same as the lead" (mengxiao on Discord)
mengxiao left Codex's subagent model at "Same as the lead" in magpie,
asked the lead for a subagent on GPT-6.1 Terra, and magpie put the
subagent on the lead's model anyway. The cause was codexFollowTo
(internal/gateway/codex_follow.go): on the ChatGPT-sign-in path, a
collab_spawn request asking for one of Codex's bare models, with nothing
set in magpie or [agents] default_subagent_model, was moved onto the
model the conversation's own turns go on (a1174674d, cybercaius).

Codex starts a spawn that names no model on its lead's model (codex-rs
core/src/agent/child_config.rs: build_agent_spawn_config sets the
child's model to the step's slug; apply_requested_spawn_agent_model_
overrides takes spawn_agent's model, else default_subagent_model; a
role's config can set one too). So under a lead on a magpie model, a
bare model in a subagent's request was always named by the lead, the
config or a role: the user's or the lead's pick. The GUI already says
"Same as the lead" means "the lead's model, or another the lead picks".

- codexFollowTo now handles memory calls only; a subagent is moved only
  by the model set for Codex's subagents in magpie (codexSubagentPick,
  unchanged). codex_backend.go no longer builds a pick from it.
- Dead code out: codexSessionOf, codexLeads.of, and CodexSideSet's
  "subagent" case (its doc moved onto servedSession).
- docs/subsystems/gateway-routing.md says a subagent never follows.
- Sibling checked: Claude Code writes no CLAUDE_CODE_SUBAGENT_MODEL
  while following the main model, and Claude Code takes the Agent call's
  model first; Claude Desktop's pick acts only when a model is set.
  Neither overrides a named model under "same as lead".
- Who relied on a1174674d (a lead's own pick of a Codex model following
  the session): pick the session's model as Codex's subagent model in
  magpie, which puts every subagent on it.

Ran (mote, -tags nogui -count=1, this change on 7fd77a944; rebased after onto a57c95513, which adds only docs, LESSONS and GUI test files):
- TestCodexSubagentKeepsTheModelItWasNamed on the old code (b01193ef9
  with only the new test): FAIL, "ChatGPT was asked for []".
- go test -run 'TestCodex(Subagent|Side|Memor|AppSide|Title|Prediction)'
  ./internal/gateway ./internal/agent: ok.
- go vet (darwin nogui, GOOS=linux, GOOS=windows) on internal/gateway
  and internal/agent: ok. gofmt -l: clean.
Not run: the full go test ./... suite (started on mote, not waited on);
staticcheck (not installed on mote); a real Codex spawn_agent with a
ChatGPT sign-in and a lead on a magpie model.
2026-10-28 16:16:02 +08:00

65 lines
2.2 KiB
Go

package agent
import (
"os"
"path/filepath"
"testing"
)
// SideModel is the model of magpie's Codex is on beside its ChatGPT
// sign-in, which the gateway answers the Codex app's titles, descriptions
// and summaries on (atom_Ray on X): none on one of Codex's own models, and
// none with magpie Codex's provider, where those requests reach magpie's
// own API on the model Codex asks for.
func TestCodexSideModel(t *testing.T) {
home, _ := codexHome(t, `{"tokens":{"access_token":"x","id_token":"x.e30.x"}}`, "model = \"gpt-a\"\n")
os.WriteFile(filepath.Join(home, ".codex", "models_cache.json"),
[]byte(`{"models":[{"slug":"gpt-a","display_name":"A","priority":1}]}`), 0o644)
cx := codex(home)
if got := cx.SideModel(); got != "" {
t.Fatalf("not connected: %q", got)
}
if ok, err := cx.Join(); err != nil || !ok {
t.Fatalf("join: %v %v", ok, err)
}
if got := cx.SideModel(); got != "" {
t.Fatalf("joined on Codex's own model: %q", got)
}
if err := cx.Fields[0].Set("fake/m1"); err != nil {
t.Fatal(err)
}
if got := cx.SideModel(); got != "fake/m1" {
t.Fatalf("a magpie model beside the sign-in: %q", got)
}
if err := cx.Field("login").Set("api"); err != nil {
t.Fatal(err)
}
if got := cx.SideModel(); got != "" {
t.Fatalf("magpie Codex's provider: %q", got)
}
}
// CodexSideSet says whether Codex's config names the model for its
// memories itself, the gateway then leaving those calls as Codex sent
// them; a config it can't read counts as naming one. Its subagents' model
// isn't asked: the gateway leaves a subagent on the model it was named.
func TestCodexSideSet(t *testing.T) {
home, _ := codexHome(t, `{}`, "model = \"gpt-a\"\n")
if CodexSideSet("memories") {
t.Fatal("nothing set")
}
config := filepath.Join(home, ".codex", "config.toml")
os.WriteFile(config, []byte("[agents]\ndefault_subagent_model = \"gpt-b\"\n[memories]\nextract_model = \"gpt-c\"\n"), 0o644)
if !CodexSideSet("memories") {
t.Fatal("set")
}
os.WriteFile(config, []byte("[agents]\ndefault_subagent_model = \"gpt-b\"\n"), 0o644)
if CodexSideSet("memories") {
t.Fatal("the subagents' alone")
}
os.WriteFile(config, []byte("[agents\n"), 0o644)
if !CodexSideSet("memories") {
t.Fatal("an unreadable config counts as set")
}
}