Followsc2c991a5b(cdredfox's two magpies each the other's remote). hanslin1666 (Discord) has the sibling: device B uses device A through a Remote magpie provider, and S3 sync carried that provider to A too, so A has a Remote magpie pointing at itself. Sync carries every provider (backup.Collect, provider.Mirror), a Remote magpie included. Two holesc2c991a5bleft: - A remote that is this magpie lists this magpie's own models through this one alone ([self]);c2c991a5bkept any via of only self, so rem/own/m1, rem/rem/own/m1, ... still grew a level a fetch until MaxVia. A via naming this magpie is now taken only when it is exactly [self]: the remote's own models, once (what the gateway's in-process remote tests need, and what hanslin1666 sees today). - Nothing stopped a request at request time: a list fetched from a magpie older than magpie_via, or one cached before the update, could still route round. Each request magpie passes to a Remote magpie now says how many magpies it went through (X-Magpie-Hops: the count it came with + 1, 1 for an agent's own); one that arrives having passed catalog.MaxVia (8) is answered 508 Loop Detected with what to turn off, before any vendor or remote is asked. The count is read only from a magpie's request (its User-Agent, which needs the key anyway), and taken off every request as it arrives, so no vendor is sent it. It goes on every path that already passes the caller on (passOnCaller: chat, decide, draw, embeddings, video). Run (mote, at this tree onc2c991a5b): - go test -timeout 45m ./internal/catalog ./internal/provider ./internal/gateway -count=1 on Linux (wsl-run, magpie-desktop): catalog ok, gateway ok (590s), provider red only in TestClaudeAccountServesModelsListedSinceItsFetch, #3174, which this doesn't touch. - go vet, GOOS=linux and GOOS=windows go vet of catalog and gateway (mote): ok. gofmt -l clean. - The full suite atc2c991a5b(mote, -timeout 45m ./...): 86 packages ok, internal/gui red only in TestMainWindowCorners (#3949). Broken by hand: - the via rule back to c2c991a5b's: TestFetchLeavesOutWhatCameFromHere red (rem/own/m2 through [self self] taken). - no hops set in passOnCaller and no check in withCaller: TestRemoteMagpieRequestLoopStops red (the remote told [ ] passes, 200 not 508 at 8, the vendor asked). Not tried: - hanslin1666's or cdredfox's own machines. - Paths to a remote that don't go through passOnCaller (the Codex socket and native passthrough) don't count hops; a loop through them is still cut by the lists. - Hiding a Remote magpie that is this magpie, or keeping it out of sync on the machine it names: not done here (a third machine that syncs may want it); it now costs one extra local pass per request to it, and its models show twice.
70 lines
2.3 KiB
Go
70 lines
2.3 KiB
Go
package catalog
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"slices"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
// Two magpies that are each other's remote (cdredfox on Discord) list
|
|
// each other's models back: a model that left this magpie through the
|
|
// other, and comes back, is not taken again, so neither list grows a
|
|
// level on every fetch. One only through others is kept, with the magpies
|
|
// it passes, and so is one through this magpie alone, once: a remote that
|
|
// is this magpie itself (hanslin1666 on Discord) has its own models once,
|
|
// not again one level deeper on each fetch.
|
|
func TestFetchLeavesOutWhatCameFromHere(t *testing.T) {
|
|
self := Self()
|
|
long := make([]string, MaxVia+1)
|
|
for i := range long {
|
|
long[i] = fmt.Sprintf("p%d", i)
|
|
}
|
|
q := func(via []string) string {
|
|
s := make([]string, len(via))
|
|
for i, v := range via {
|
|
s[i] = `"` + v + `"`
|
|
}
|
|
return "[" + strings.Join(s, ",") + "]"
|
|
}
|
|
srv := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
|
|
fmt.Fprintf(rw, `{"object":"list","data":[
|
|
{"id":"up/m1","magpie_via":["peer"]},
|
|
{"id":"back/own/m1","magpie_via":%s},
|
|
{"id":"own/m2","magpie_via":%s},
|
|
{"id":"rem/own/m2","magpie_via":%s},
|
|
{"id":"far/m3","magpie_via":%s},
|
|
{"id":"old/m4"}]}`, q([]string{self, "peer"}), q([]string{self}), q([]string{self, self}), q(long))
|
|
}))
|
|
defer srv.Close()
|
|
ms, _, err := FetchAt(context.Background(), srv.URL+"/v1", "k", false, nil)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
got := map[string][]string{}
|
|
for _, m := range ms {
|
|
got[m.ID] = m.Via
|
|
}
|
|
if _, ok := got["back/own/m1"]; ok {
|
|
t.Errorf("a model that went out of this magpie and came back was taken: %v", got)
|
|
}
|
|
if _, ok := got["rem/own/m2"]; ok {
|
|
t.Errorf("a model through this magpie twice (a remote that is this magpie) was taken: %v", got)
|
|
}
|
|
if _, ok := got["far/m3"]; ok {
|
|
t.Errorf("a model through more than %d magpies was taken: %v", MaxVia, got)
|
|
}
|
|
if v, ok := got["up/m1"]; !ok || !slices.Equal(v, []string{"peer"}) {
|
|
t.Errorf("up/m1 = %v, %v; want kept through [peer]", v, ok)
|
|
}
|
|
if v, ok := got["own/m2"]; !ok || !slices.Equal(v, []string{self}) {
|
|
t.Errorf("own/m2 = %v, %v; want kept through this magpie", v, ok)
|
|
}
|
|
if v, ok := got["old/m4"]; !ok || v != nil {
|
|
t.Errorf("an older magpie's model = %v, %v; want kept, through nothing said", v, ok)
|
|
}
|
|
}
|