1EFLOPS runs Claude Code through magpie on Codex's gpt-6.1-sol. In auto mode, Claude Code 2.1.296 says "this session isn't eligible because your requests go through 127.0.0.1:3425 ... ask your gateway to implement https://code.claude.com/docs/en/auto-mode-classifier-billing". What the page asks of a gateway: pass the anthropic-beta header (dangerous-tool-use-2026-09-03), the request's `safeguards` field, and `safeguard_results` in the reply through unchanged, and leave tool-use ids alone. The results are verdicts from Anthropic's own safety classifier. For a gateway that can't provide them, the page's remedy is CLAUDE_CODE_AUTO_MODE_SERVER=0. Pro, Max and Team plans never see the notice. In the bundle, Claude Code falls back on server_unsupported, server_unavailable_disabled or server_no_result, and the notice shows whenever there's no real verdict. Only that variable removes it. Per route: - Claude subscription bridge, Anthropic API key, relays in front of Anthropic, Bedrock and Vertex: already pass the beta, `safeguards` and `safeguard_results` through (e8cd4bac8,8c21a4184). This commit doesn't change them. serverReview now uses the shared AutoModeReviewed rule (adding the subscription account, which never reaches serverReview). - Codex/OpenAI and every other non-Claude model: magpie can't answer honestly. A verdict would be made up, and "unsupported" still shows the notice. So magpie answers nothing on Anthropic's behalf. Instead the Claude Code wiring writes env.CLAUDE_CODE_AUTO_MODE_SERVER="0" to settings.json. It does this only while Claude Code is routed through magpie and no model it can reach there is reviewed. That means checking the models shown to Claude Code (and Claude Desktop's while Desktop is on magpie), a shown group's members, those providers' fallbacks, and the models it is set to (claudeReviewed). If any one is reviewed, the variable stays unset, because /model can move the session onto it (the reason8c21a4184didn't write it at all). The value is rewritten on every model set and Sync, so adding a Claude provider turns the review back on. It is stash-tracked (claude.auto_mode_server): a user's own value is left alone, and magpie's goes on Disconnect, reset or a move off magpie. - T3 Code (sibling): its magpie instance runs Claude Code on the gateway through its own environment, so it gets the same "0" by the models it lists. Not covered: Claude Desktop's Code tab while Claude Code itself isn't routed through magpie. Desktop users are on Pro/Max/Team, which never see the notice. Tests (each fails with its part of the change broken by hand): - TestClaudeAutoModeReview: off on a non-Claude model; on with a Claude model shown, in a group or as a fallback; the user's "1" and "0" kept; dropped on reset and on a move to Claude Code's own model. A group that keeps its models out of the lists (#1783, Unlists) still routes to them, so its Claude member counts: members come from what is served, not from the catalog. - TestT3CodeAutoModeReview. - TestAutoModeReviewedRoutes: subscription, api.anthropic.com, relay, Bedrock and Vertex spellings yes; Codex, DeepSeek's Anthropic API, openai/gpt-6 and claudette no. Mutations that went red: skipping group members, skipping fallbacks, skipping an unlisting group, overwriting the user's value, not dropping it off magpie, always writing it, the T3 env always or never, and the subscription not counted. Real Claude Code 2.1.296, sandbox HOME/CLAUDE_CONFIG_DIR, magpie serve on 127.0.0.1:3591 under a scratch HOME, fake upstreams on 3593 (OpenAI Chat) and 3594 (Anthropic): - Before, on fakeai/fake-gpt, -p --permission-mode auto: the notice is on stderr (2 of 2 fresh config dirs). With the env in settings: none. - With this build, `magpie claude fakeai/fake-gpt` wrote the "0", and a fresh run shows no notice. The same settings without it show the notice. - `magpie provider add fakeanth anthropic=... models=claude-sonnet-5`: Sync took the "0" out. `magpie claude fakeanth/claude-sonnet-5` and a run in auto mode: the upstream got the dangerous-tool-use beta and `safeguards` on both turns, answered not_flagged in message_delta, and there was no notice. Not tried: the Claude subscription bridge with a real account (its plans don't see the notice), and a real Codex account (a fake Chat upstream stood in for it). Run: gofmt -l; go vet -tags nogui ./... for darwin, linux and windows; go test -tags nogui ./... in a scratch HOME with the Go caches pinned. The only red was TestOTelWaterfallIncludesUnbilledFallback, whose first export was cut before the root span under load. That is #1794, filed earlier today; this run is noted there. This change doesn't touch OTel. internal/agent was timed against the unchanged base under the same load and ran at the same pace. Re-run after rebasing on origin/main94aa15397(load ~100, so not the whole suite): gofmt -l on the touched files; go vet -tags nogui ./internal/agent ./internal/gateway for darwin, linux and windows; go test -tags nogui -count=1 ./internal/agent (1381s) and ./internal/gateway (939s), green. Breaking writeReview to never write the "0" turned TestClaudeAutoModeReview red, and dropping the subscription from AutoModeReviewed turned TestAutoModeReviewedRoutes red.
208 lines
6.7 KiB
Go
208 lines
6.7 KiB
Go
package agent
|
|
|
|
import (
|
|
"encoding/json"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/yetone/magpie/internal/edit"
|
|
"github.com/yetone/magpie/internal/provider"
|
|
)
|
|
|
|
// TestClaudeAutoModeReview: Claude Code in auto mode behind magpie on a
|
|
// model Anthropic doesn't review (1EFLOPS on X, on Codex's gpt-6.1-sol)
|
|
// said "this session isn't eligible because your requests go through
|
|
// 127.0.0.1:3425…". Anthropic's page says to turn the review off
|
|
// (CLAUDE_CODE_AUTO_MODE_SERVER=0) for a gateway that can't run it: magpie
|
|
// does while no model Claude Code can reach through it is reviewed, and
|
|
// leaves it on while one is, shown or behind a group or a fallback. A
|
|
// value of the user's is theirs, and magpie's goes when Claude Code is
|
|
// taken off magpie.
|
|
func TestClaudeAutoModeReview(t *testing.T) {
|
|
home := t.TempDir()
|
|
t.Setenv("HOME", home)
|
|
t.Setenv("USERPROFILE", home)
|
|
t.Setenv("APPDATA", filepath.Join(home, "AppData", "Roaming"))
|
|
t.Setenv("LOCALAPPDATA", filepath.Join(home, "AppData", "Local"))
|
|
t.Setenv("XDG_CONFIG_HOME", filepath.Join(home, ".config"))
|
|
t.Setenv("XDG_CACHE_HOME", filepath.Join(home, ".cache"))
|
|
if err := provider.Save(provider.Provider{ID: "v", Name: "V", Chat: "http://127.0.0.1:1/v1", Key: "k", Models: []string{"gpt-x"}}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
path := filepath.Join(home, ".claude", "settings.json")
|
|
writeFile(t, path, `{"theme":"dark"}`)
|
|
a := claude(home)
|
|
review := func() string { v, _ := edit.GetJSON(path, "env."+claudeReviewEnv); return v }
|
|
set := func(key, v string) {
|
|
t.Helper()
|
|
if err := a.Field(key).Set(v); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
sync := func() {
|
|
t.Helper()
|
|
if err := a.Sync(); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
// only a model no one reviews: off
|
|
set("model", "v/gpt-x")
|
|
if review() != "0" {
|
|
t.Fatalf("on v/gpt-x alone: %q, want 0", review())
|
|
}
|
|
sync()
|
|
if review() != "0" {
|
|
t.Fatalf("Sync: %q", review())
|
|
}
|
|
|
|
// a Claude model on an Anthropic endpoint joins: on, as /model can take
|
|
// the session there
|
|
if err := provider.Save(provider.Provider{ID: "a", Name: "A", Anthropic: "http://127.0.0.1:1", Key: "k", Models: []string{"claude-sonnet-5"}}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
sync()
|
|
if review() != "" {
|
|
t.Fatalf("with a/claude-sonnet-5 shown: %q, want unset", review())
|
|
}
|
|
|
|
// hidden from Claude Code: off again; reachable through a group shown
|
|
// to it, or a provider's fallback, on
|
|
if err := provider.SetHiddenModels("claude", []string{"a/claude-sonnet-5"}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
sync()
|
|
if review() != "0" {
|
|
t.Fatalf("Claude hidden: %q, want 0", review())
|
|
}
|
|
if err := provider.SaveGroup(provider.Group{Name: "mix", Members: []string{"v/gpt-x", "a/claude-sonnet-5"}}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
sync()
|
|
if review() != "" {
|
|
t.Fatalf("a group with a Claude member: %q, want unset", review())
|
|
}
|
|
// a group that keeps its models out of the lists (#1783) still routes
|
|
// to them, so its Claude member counts
|
|
if err := provider.SetHiddenModels("claude", nil); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := provider.SaveGroup(provider.Group{Name: "mix", Members: []string{"v/gpt-x", "a/claude-sonnet-5"}, Unlists: true}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
sync()
|
|
if review() != "" {
|
|
t.Fatalf("a group unlisting its Claude member: %q, want unset", review())
|
|
}
|
|
if err := provider.SetHiddenModels("claude", []string{"a/claude-sonnet-5"}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := provider.DeleteGroup("mix"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
sync()
|
|
if review() != "0" {
|
|
t.Fatalf("group deleted: %q, want 0", review())
|
|
}
|
|
if err := provider.Save(provider.Provider{ID: "v", Name: "V", Chat: "http://127.0.0.1:1/v1", Key: "k", Models: []string{"gpt-x"}, Fallback: []string{"a/claude-sonnet-5"}}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
sync()
|
|
if review() != "" {
|
|
t.Fatalf("falling back to Claude: %q, want unset", review())
|
|
}
|
|
if err := provider.Save(provider.Provider{ID: "v", Name: "V", Chat: "http://127.0.0.1:1/v1", Key: "k", Models: []string{"gpt-x"}}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
sync()
|
|
if review() != "0" {
|
|
t.Fatalf("fallback gone: %q, want 0", review())
|
|
}
|
|
|
|
// off magpie, onto Claude Code's own model, and reset: magpie's goes
|
|
set("model", "claude-opus-4-8")
|
|
if review() != "" {
|
|
t.Fatalf("Claude's own model kept magpie's value: %q", review())
|
|
}
|
|
set("model", "v/gpt-x")
|
|
if review() != "0" {
|
|
t.Fatalf("back on v/gpt-x: %q", review())
|
|
}
|
|
set("model", "")
|
|
if review() != "" {
|
|
t.Fatalf("reset kept magpie's value: %q", review())
|
|
}
|
|
|
|
// the user's own value is theirs, through a switch, Sync and reset
|
|
for _, mine := range []string{"1", "0"} {
|
|
if err := edit.SetJSON(path, edit.KV{Path: "env." + claudeReviewEnv, Value: mine}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
set("model", "v/gpt-x")
|
|
sync()
|
|
if err := provider.Save(provider.Provider{ID: "a", Name: "A", Anthropic: "http://127.0.0.1:1", Key: "k", Models: []string{"claude-sonnet-5"}}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := provider.SetHiddenModels("claude", nil); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
sync()
|
|
if review() != mine {
|
|
t.Fatalf("the user's %q became %q", mine, review())
|
|
}
|
|
set("model", "")
|
|
if review() != mine {
|
|
t.Fatalf("reset took the user's %q away: %q", mine, review())
|
|
}
|
|
if err := edit.DelJSON(path, "env."+claudeReviewEnv); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := provider.SetHiddenModels("claude", []string{"a/claude-sonnet-5"}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
if v, _ := edit.GetJSON(path, "theme"); v != "dark" {
|
|
t.Fatal("theme lost")
|
|
}
|
|
}
|
|
|
|
// TestT3CodeAutoModeReview: T3 Code's magpie instance runs Claude Code on
|
|
// the gateway through its own environment, so it is told the same: the
|
|
// review off while none of the models it lists is reviewed, and on (not
|
|
// set) once one is.
|
|
func TestT3CodeAutoModeReview(t *testing.T) {
|
|
home := syncHome(t)
|
|
t.Setenv("T3CODE_HOME", "")
|
|
path := filepath.Join(home, ".t3", "userdata", "settings.json")
|
|
writeFile(t, path, `{}`)
|
|
a := t3code(home)
|
|
if err := a.Field("provider").Set(magpieID); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
review := func() (string, bool) {
|
|
t.Helper()
|
|
var file map[string]map[string]json.RawMessage
|
|
if err := json.Unmarshal([]byte(readFile(path)), &file); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
for _, v := range t3Format(t, file["providerInstances"][magpieID]).Environment {
|
|
if v.Name == claudeReviewEnv {
|
|
return v.Value, true
|
|
}
|
|
}
|
|
return "", false
|
|
}
|
|
if v, ok := review(); v != "0" || !ok {
|
|
t.Fatalf("relay/glm-4.6 alone: %q %v, want 0", v, ok)
|
|
}
|
|
if err := provider.Save(provider.Provider{ID: "a", Name: "A", Anthropic: "http://127.0.0.1:1", Key: "k", Models: []string{"claude-sonnet-5"}}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := a.Sync(); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if v, ok := review(); ok {
|
|
t.Fatalf("with a/claude-sonnet-5 listed: %q, want none", v)
|
|
}
|
|
}
|