Files
magpie/internal/gateway/codex_subagent_chat_test.go
T
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

161 lines
6.8 KiB
Go

package gateway
import (
"fmt"
"strings"
"testing"
"github.com/yetone/magpie/internal/provider"
)
// #1633 (laacmilan): Codex's lead on token/gpt-6.1-sol, a provider on Chat
// Completions, its subagents wanted on token too. The lead's spawn_agent
// task reaches the subagent as text (magpie served the lead), so a
// subagent the lead put on one of Codex's own models goes on the token
// model set for Codex's subagents, and ChatGPT isn't asked. The lead's
// own turn stays on the model it asked for.
func TestCodexSubagentPutOnAChatProviderUnderAChatLead(t *testing.T) {
up := codexSubagentSetup(t)
token := chatRecordedOn(t, "token", "gpt-6.1-sol")
if err := provider.SetCodexSubagentModel("token/gpt-6.1-sol"); err != nil {
t.Fatal(err)
}
s := New()
rec := codexAsks(s, "gpt-6-astra", "collab_spawn", plainTask)
if rec.Code != 200 || !strings.Contains(rec.Body.String(), "ok") {
t.Fatalf("subagent: %d %s", rec.Code, rec.Body.String())
}
if got := up.asked(); len(got) != 0 {
t.Fatalf("ChatGPT was asked for %v", got)
}
if got := token.requests(); len(got) != 1 || !strings.Contains(got[0], `"gpt-6.1-sol"`) || !strings.Contains(got[0], "read the README") {
t.Fatalf("token was asked %v", got)
}
r := lastRoute(s)
if r.Subagent == nil || *r.Subagent != (SubagentPick{Asked: "gpt-6-astra", To: "token/gpt-6.1-sol"}) || r.Provider != "token" {
t.Fatalf("trace: provider %q subagent %+v", r.Provider, r.Subagent)
}
// the lead on its own model, magpie's token one
if rec := codexAsks(s, "token/gpt-6.1-sol", "", leadAsk); rec.Code != 200 {
t.Fatalf("lead: %d %s", rec.Code, rec.Body.String())
}
if r := lastRoute(s); r.Subagent != nil {
t.Fatalf("lead traced %+v", r.Subagent)
}
}
// #1613's other side: the lead on one of Codex's own models, answered by
// the ChatGPT backend, which sealed the subagent's task. token can't open
// it, so the subagent stays on the model its lead asked for — answered by
// ChatGPT as with no model set, not turned away — and the trace says why.
// A subagent's request holding only a sealed message, not a task, still
// goes on token: that message is left out with a note (#1613).
func TestCodexSubagentSealedTaskStaysOffAChatProvider(t *testing.T) {
up := codexSubagentSetup(t)
token := chatRecordedOn(t, "token", "gpt-6.1-sol")
if err := provider.SetCodexSubagentModel("token/gpt-6.1-sol"); err != nil {
t.Fatal(err)
}
s := New()
rec := codexAsks(s, "gpt-5.5", "collab_spawn", sealedTaskFernet)
if rec.Code != 200 || !strings.Contains(rec.Body.String(), "on it") {
t.Fatalf("subagent: %d %s", rec.Code, rec.Body.String())
}
if got := up.asked(); len(got) != 1 || got[0] != "gpt-5.5" {
t.Fatalf("ChatGPT was asked for %v, not the model asked", got)
}
if n := len(token.requests()); n != 0 {
t.Fatalf("token was asked %d times", n)
}
if r := lastRoute(s); r.Subagent == nil || r.Subagent.To != "token/gpt-6.1-sol" || r.Subagent.Kept != sealedKept {
t.Fatalf("trace: %+v", r.Subagent)
}
rec = codexAsks(s, "gpt-5.5", "collab_spawn", plainTask+","+sealedWorkerMessage)
if rec.Code != 200 {
t.Fatalf("subagent with a sealed message: %d %s", rec.Code, rec.Body.String())
}
if got := token.requests(); len(got) != 1 || strings.Contains(got[0], "gAAAAATest_worker_message") {
t.Fatalf("token was asked %v", got)
}
if r := lastRoute(s); !r.Subagent.Moved() {
t.Fatalf("trace: %+v", r.Subagent)
}
}
// cleverpigo on X: Codex's lead on WorkBuddy's DeepSeek through magpie, the
// subagent model left at what read "Same as the lead", and the Routing
// page showed a subagent on gpt-5.6-sol through Codex's own sign-in: the
// lead named it in spawn_agent, where Codex lists its own models first.
// Set to the lead's model, every subagent goes on the model the lead's own
// turns go on, whatever the lead names, and ChatGPT isn't asked.
func TestCodexSubagentFollowsTheLeadWhenSet(t *testing.T) {
up := codexSubagentSetup(t)
token := chatRecordedOn(t, "token", "deepseek-v4.1-flash")
if err := provider.SetCodexSubagentModel(provider.CodexSubagentLead); err != nil {
t.Fatal(err)
}
s := New()
if rec := codexSubTurn(s, "token/deepseek-v4.1-flash", "lead-1", "", leadAsk); rec.Code != 200 {
t.Fatalf("lead: %d %s", rec.Code, rec.Body.String())
}
// a subagent the lead named one of Codex's own models for, and one it
// named another of magpie's for, each its own thread (a resumed one
// stays on the model it started on)
for i, asked := range []string{"gpt-5.6-sol", "third/gpt-6-astra"} {
rec := codexAsksIn(s, fmt.Sprintf("worker-%d", i+1), asked, "collab_spawn", plainTask)
if rec.Code != 200 || !strings.Contains(rec.Body.String(), "ok") {
t.Fatalf("%s: %d %s", asked, rec.Code, rec.Body.String())
}
if got := up.asked(); len(got) != 0 {
t.Fatalf("%s: ChatGPT was asked for %v", asked, got)
}
r := lastRoute(s)
if r.Subagent == nil || *r.Subagent != (SubagentPick{Asked: asked, To: "token/deepseek-v4.1-flash", Lead: true}) || r.Provider != "token" {
t.Fatalf("%s: trace: provider %q subagent %+v", asked, r.Provider, r.Subagent)
}
}
if got := token.requests(); len(got) != 3 || !strings.Contains(got[2], "read the README") {
t.Fatalf("token was asked %d times", len(got))
}
// the lead's own turn stays as asked
if rec := codexSubTurn(s, "token/deepseek-v4.1-flash", "lead-1", "", leadAsk); rec.Code != 200 {
t.Fatalf("lead: %d", rec.Code)
}
if r := lastRoute(s); r.Subagent != nil {
t.Fatalf("lead traced %+v", r.Subagent)
}
}
// Set to the lead's model with the lead on one of Codex's own: a subagent
// the lead named one of magpie's models for goes to the ChatGPT sign-in on
// the lead's model. With no lead turn seen, a subagent goes as asked.
func TestCodexSubagentFollowsALeadOnCodexsOwnModel(t *testing.T) {
up := codexSubagentSetup(t)
token := chatRecordedOn(t, "token", "deepseek-v4.1-flash")
if err := provider.SetCodexSubagentModel(provider.CodexSubagentLead); err != nil {
t.Fatal(err)
}
s := New()
if rec := codexAsks(s, "token/deepseek-v4.1-flash", "collab_spawn", plainTask); rec.Code != 200 {
t.Fatalf("no lead: %d %s", rec.Code, rec.Body.String())
}
if r := lastRoute(s); r.Subagent != nil || len(token.requests()) != 1 {
t.Fatalf("no lead: traced %+v, token asked %d times", r.Subagent, len(token.requests()))
}
if rec := codexSubTurn(s, "gpt-5.5", "lead-1", "", leadAsk); rec.Code != 200 {
t.Fatalf("lead: %d %s", rec.Code, rec.Body.String())
}
if rec := codexAsksIn(s, "worker-2", "token/deepseek-v4.1-flash", "collab_spawn", plainTask); rec.Code != 200 {
t.Fatalf("subagent: %d %s", rec.Code, rec.Body.String())
}
if got := up.asked(); len(got) != 2 || got[1] != "gpt-5.5" {
t.Fatalf("ChatGPT was asked for %v", got)
}
if n := len(token.requests()); n != 1 {
t.Fatalf("token was asked %d times", n)
}
if r := lastRoute(s); r.Subagent == nil || *r.Subagent != (SubagentPick{Asked: "token/deepseek-v4.1-flash", To: "gpt-5.5", Lead: true}) {
t.Fatalf("trace: %+v", r.Subagent)
}
}