From d67ccbd3c7adde67e655e6c95e356d3e8f95110a Mon Sep 17 00:00:00 2001 From: yetone Date: Tue, 17 Nov 2026 20:38:54 +0800 Subject: [PATCH] agent: a provider named magpie at another machine's address is not this magpie's Alma wiring Alex on Discord: any provider named magpie in Alma, one pointing at a magpie on a VPS included, was taken as this magpie's own, and the Agents page said "Alma no longer goes through magpie, its config was changed". almaMagpie now takes a provider by the name magpie only when its base URL is on this machine (onAnotherMachine, as ZCode's check does). One at another machine's address is the user's own provider and left alone; the second match, an OpenAI-shaped provider at this gateway, is unchanged. Run (mote), at base f1a4de736; rebased onto 4f94b8a82, which changes two internal/agent files, and the Alma tests run again there: ok. - go test -count=1 ./internal/agent/: ok (225.9s) - GOOS=linux and GOOS=windows go vet ./internal/agent/: ok; gofmt -l clean. Broken by hand: without the onAnotherMachine check, TestAlmaMagpieOnAServer FAILs ("a magpie on a server taken for this one"). Not tried: a real Alma with a remote magpie provider; the test uses the reporter's shape (id vps, name magpie, https URL, set as default). --- internal/agent/alma.go | 6 ++++-- internal/agent/alma_test.go | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/internal/agent/alma.go b/internal/agent/alma.go index 69011f963..84defc13b 100644 --- a/internal/agent/alma.go +++ b/internal/agent/alma.go @@ -286,10 +286,12 @@ var almaSeen struct { } // almaMagpie is magpie's provider among Alma's: the one named magpie, or -// an OpenAI-shaped one at the gateway. Nil if there is none. +// an OpenAI-shaped one at the gateway. Nil if there is none. One named +// magpie at another machine's address is the user's own, a magpie on a +// server say (Alex on Discord), and never this magpie's. func almaMagpie(ps []almaProvider) *almaProvider { for i := range ps { - if ps[i].Name == magpieID && (ps[i].Type == "openai" || ps[i].Type == "custom") { + if ps[i].Name == magpieID && (ps[i].Type == "openai" || ps[i].Type == "custom") && !onAnotherMachine(ps[i].BaseURL) { return &ps[i] } } diff --git a/internal/agent/alma_test.go b/internal/agent/alma_test.go index 3e565d71d..d895df664 100644 --- a/internal/agent/alma_test.go +++ b/internal/agent/alma_test.go @@ -880,3 +880,37 @@ func TestAlmaOneMagpie(t *testing.T) { } }) } + +// A provider the user named magpie in Alma, at a magpie on a server, is +// theirs (Alex on Discord): this magpie neither takes it for its own nor +// tells drift when Alma's model is on it. +func TestAlmaMagpieOnAServer(t *testing.T) { + syncHome(t) + f := startAlma(t) + a := alma() + if err := os.MkdirAll(a.Dir, 0o755); err != nil { + t.Fatal(err) + } + vps := map[string]any{"id": "vps", "name": magpieID, "type": "openai", "apiKey": "sk-vps", + "baseURL": "https://magpie.example.com/v1", "enabled": true, "models": []any{"m"}} + f.mu.Lock() + f.providers = append(f.providers, vps) + f.settings["chat"].(map[string]any)["defaultModel"] = "vps:m" + f.mu.Unlock() + if p := almaMagpie([]almaProvider{{ID: "vps", Name: magpieID, Type: "openai", BaseURL: "https://magpie.example.com/v1"}}); p != nil { + t.Fatalf("a magpie on a server taken for this one: %+v", p) + } + if c := a.Check(); c != "" { + t.Fatalf("Alma on the user's server magpie told as drift: %q", c) + } + if a.Wired() { + t.Fatal("Alma on the user's server magpie reads as on this magpie") + } + // this magpie's own, named magpie at the gateway, is still found + if p := almaMagpie([]almaProvider{{ID: "x", Name: magpieID, Type: "openai", BaseURL: gatewayV1()}}); p == nil { + t.Fatal("magpie's own provider not found") + } + if p := almaMagpie([]almaProvider{{ID: "x", Name: magpieID, Type: "openai", BaseURL: "http://127.0.0.1:1/v1"}}); p == nil { + t.Fatal("magpie's own provider at an old local port not found, to be pointed back") + } +}