gateway: Codex on magpie as its provider has its approvals auto-reviewed again (shihao H on X: 自动审批未执行 … 404: magpie knows no model "codex-auto-review") — Codex asks for its guardian review by OpenAI's reviewer model, codex-auto-review, whatever the provider ("independent of current login"), and magpie, knowing no such model, answered 404, which Codex reports as the review service failing. A model Codex names that magpie does not serve now goes to the model Codex is set to (config.toml model), when magpie is its provider, as Codex itself reviews with the turn's model when its catalog lacks the reviewer; the Routing view shows it as the Approval check. Signed in, Codex's own names go on to OpenAI as before. TestCodexStandIn fails without the change; TestCodexAutoReviewStandIn has the Codex request go to the stand-in. go vet, go build -tags nogui (darwin, GOOS=linux), GOOS=windows go build, go test -tags nogui ./... pass.

This commit is contained in:
yetone
2026-09-30 16:55:50 +08:00
parent 771506cf05
commit e31384b1f9
4 changed files with 85 additions and 4 deletions
+6 -3
View File
@@ -294,16 +294,19 @@ var claudeManaged = func() string {
// StandIn is the model Claude Code is set to use in place of one it named
// that magpie doesn't serve: claude-haiku-4-5-… for a title or a small
// task goes to its haiku tier's model, and a name of no tier to its main
// model. "" when Claude Code isn't routed through magpie or asked for
// isn't Claude Code. For gateway.StandIn.
// model. For Codex, the model it is set to (codexStandIn). "" when the
// agent isn't routed through magpie or is neither. For gateway.StandIn.
func StandIn(agent, model string) string {
if agent != "claude" {
if agent != "claude" && agent != "codex" {
return ""
}
home, err := os.UserHomeDir()
if err != nil {
return ""
}
if agent == "codex" {
return codexStandIn(filepath.Join(home, ".codex", "config.toml"))
}
if m := claudeStandIn(filepath.Join(home, ".claude", "settings.json"), model); m != "" || runtime.GOOS != "windows" {
return m
}
+16
View File
@@ -38,6 +38,22 @@ import (
// again without the table ("Model provider `magpie` not found"), whichever
// way Codex is routed now.
// codexStandIn is the model Codex is set to use, when magpie is its
// provider, for a model it names that magpie doesn't serve. Codex asks for
// some by a name of OpenAI's whatever its provider: auto-review of an
// approval goes out as "codex-auto-review" (the guardian's reviewer model,
// "independent of current login"), which magpie answered 404 "magpie knows
// no model", and Codex reported the review as failed. Codex itself reviews
// with the turn's model when its catalog lacks the reviewer; so does magpie.
// Signed in, Codex's own names go on to OpenAI (codexUpstream) instead.
func codexStandIn(path string) string {
if p, _ := edit.GetTOMLTop(path, "model_provider"); p != magpieID {
return ""
}
m, _ := edit.GetTOMLTop(path, "model")
return m
}
func codex(home string) *Agent { return codexIn(here(home)) }
// codexIn is Codex as it lives at a place: this machine's home, or a WSL
+39 -1
View File
@@ -6,6 +6,7 @@ import (
"testing"
"github.com/yetone/magpie/internal/gateway"
"github.com/yetone/magpie/internal/usage"
)
func TestClaudeStandIn(t *testing.T) {
@@ -31,7 +32,44 @@ func TestClaudeStandIn(t *testing.T) {
if got := claudeStandIn(path, "claude-haiku-4-5"); got != "" {
t.Errorf("not routed: %q", got)
}
if got := StandIn("codex", "claude-haiku-4-5"); got != "" {
if got := StandIn("gemini", "claude-haiku-4-5"); got != "" {
t.Errorf("another agent: %q", got)
}
}
// Codex on magpie as its provider asks for its auto-review by OpenAI's
// name, codex-auto-review (shihao H on X: 404 magpie knows no model
// "codex-auto-review"); it goes to the model Codex is set to. Signed in
// (routed by openai_base_url) or not routed, nothing stands in.
func TestCodexStandIn(t *testing.T) {
home := t.TempDir()
t.Setenv("HOME", home)
t.Setenv("USERPROFILE", home)
dir := filepath.Join(home, ".codex")
if err := os.MkdirAll(dir, 0o755); err != nil {
t.Fatal(err)
}
write := func(s string) {
if err := os.WriteFile(filepath.Join(dir, "config.toml"), []byte(s), 0o644); err != nil {
t.Fatal(err)
}
}
write("model = \"deepseek/deepseek-v4\"\nmodel_provider = \"magpie\"\n\n[model_providers.magpie]\nname = \"magpie\"\n")
if got := StandIn("codex", "codex-auto-review"); got != "deepseek/deepseek-v4" {
t.Errorf("magpie as provider: %q", got)
}
// the gateway knows the request as Codex's by its User-Agent
for _, ua := range []string{"codex_cli_rs/0.160.0 (Mac OS 26.6.0; arm64) Apple_Terminal/455", "Codex Desktop/0.160.0"} {
if got := usage.AgentOf(ua); got != "codex" {
t.Errorf("%s: agent %q", ua, got)
}
}
write("model = \"gpt-5.5\"\nopenai_base_url = \"" + gateway.URL() + gateway.CodexPath + "\"\n")
if got := StandIn("codex", "codex-auto-review"); got != "" {
t.Errorf("signed in: %q", got)
}
write("model = \"gpt-5.5\"\n")
if got := StandIn("codex", "codex-auto-review"); got != "" {
t.Errorf("not routed: %q", got)
}
}
+24
View File
@@ -1,6 +1,7 @@
package gateway
import (
"net/http/httptest"
"strings"
"testing"
@@ -33,3 +34,26 @@ func TestStandIn(t *testing.T) {
t.Fatalf("without a stand-in: %d", code)
}
}
// Codex's auto-review asks magpie, its provider, for "codex-auto-review":
// the review goes to the model that stands in (Codex's, TestCodexStandIn).
func TestCodexAutoReviewStandIn(t *testing.T) {
t.Setenv("HOME", t.TempDir())
f := &fake{t: t, ctype: "application/json", reply: `{"id":"c1","choices":[{"message":{"role":"assistant","content":"OK"},"finish_reason":"stop"}]}`}
setup(t, provider.Chat, f)
StandIn = func(agent, model string) string {
if model == "codex-auto-review" {
return "fake/m1"
}
return ""
}
t.Cleanup(func() { StandIn = nil })
rec := httptest.NewRecorder()
req := httptest.NewRequest("POST", "/v1/responses", strings.NewReader(`{"model":"codex-auto-review","input":"review this","stream":false}`))
req.Header.Set("User-Agent", "codex_cli_rs/0.160.0 (Mac OS 26.6.0; arm64) Apple_Terminal/455")
req.Header.Set("x-openai-subagent", "guardian")
New().Handler().ServeHTTP(rec, req)
if rec.Code == 404 || modelOf(f.got) != "m1" {
t.Fatalf("auto-review: %d %s, upstream %s", rec.Code, rec.Body.String(), f.got)
}
}