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.
83 lines
3.3 KiB
Go
83 lines
3.3 KiB
Go
package gateway
|
|
|
|
import (
|
|
"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)
|
|
}
|
|
}
|