diff --git a/internal/agent/alma.go b/internal/agent/alma.go index b3ad57e83..df7cd6dc5 100644 --- a/internal/agent/alma.go +++ b/internal/agent/alma.go @@ -227,7 +227,10 @@ func almaProvidersSeen() ([]almaProvider, error) { } almaSeen.Lock() defer almaSeen.Unlock() - if len(b) > 0 && len(b) == len(almaSeen.body) && &b[0] == &almaSeen.body[0] { + // the same bytes asked again (past almaReadFor, each poll of the + // Agents page) are the same providers: 4 MB a minute decoded again on + // a live magpie with Alma's 227 KB answer + if len(b) > 0 && len(b) == len(almaSeen.body) && (&b[0] == &almaSeen.body[0] || bytes.Equal(b, almaSeen.body)) { return almaSeen.ps, nil } var ps []almaProvider diff --git a/internal/agent/alma_seen_test.go b/internal/agent/alma_seen_test.go index e47036731..a351ff0f5 100644 --- a/internal/agent/alma_seen_test.go +++ b/internal/agent/alma_seen_test.go @@ -56,6 +56,23 @@ func TestAlmaProvidersSeenDecodeOnce(t *testing.T) { if g := asked(); g != 1 { t.Fatalf("looks asked Alma %d times", g) } + // the same answer asked for again, past the time one is kept, is not + // decoded again either + almaReadFor = 0 + if n := testing.AllocsPerRun(5, func() { + if ps, err := almaProvidersSeen(); err != nil || len(ps) != 1 { + t.Fatal(err, ps) + } + }); n > 400 { + t.Errorf("a look at the same answer asked again allocates %v times", n) + } + if g := asked(); g < 6 { + t.Fatalf("Alma asked %d times with nothing kept", g) + } + almaReadFor = time.Minute + mu.Lock() + gets = 1 + mu.Unlock() mu.Lock() model = "gpt-5.5" mu.Unlock()