From 7126f7de3e2efa109003d4e9723998fc3c05901f Mon Sep 17 00:00:00 2001 From: yetone Date: Sun, 1 Nov 2026 22:17:34 +0800 Subject: [PATCH] gateway: only the user's "it sees" lifts the small models' shape guess, and a group's ID stays out (#4359) Review of ggbdpq's aa378a4f6 (the commit before). Its comment says a group's, auto's or a subscription's agent-written ID stays out whatever the user said of it, but the code put those guards inside the same "user said nothing" branch, so a group/ or auto/ ID with a modelImages entry entered the pool. And any answer lifted the guess, a "takes no images" too: that says nothing of whether the ID is a vendor's model, yet let a colon or *-embed/-tts/-free ID into the searcher's small model pool, which has no image keep to hold it back. Now the structural guards stand for every model, and only a modelImages true lifts the colon/word guess. Run (mote, -tags nogui): - TestSmallCandsLiftOnlyWhatTheUserSaidSees, new: red on aa378a4f6 ("pool [cn:text-only cn:sees group/g auto/a], want only cn:sees"), green here. - TestAutoVisionPicksANamespacedIDTheUserSaidSees (ggbdpq's): red with search.go at origin/main 85e37162e (AutoVision = ""), green here. - -run 'TestAutoVision|TestRankSmall|Small|Searcher' ./internal/gateway: ok. --- internal/gateway/search.go | 14 +++++++++----- internal/gateway/small_kept_test.go | 28 ++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/internal/gateway/search.go b/internal/gateway/search.go index 6cc15961b..993192387 100644 --- a/internal/gateway/search.go +++ b/internal/gateway/search.go @@ -565,7 +565,9 @@ type smallCand struct { // the vendor's own, not one of the shapes guessed at below: their model // stays in the pool though its ID carries a namespace colon (a relay's // cn:deepseek-v4.1-flash, #4359) or one of the words, and keep has said -// whether it sees. An ID that starts a group, a found group or, on a +// whether it sees. Only their "it sees" lifts the guess: a "takes no +// images" says nothing of whether the ID is a vendor's model, and keeps +// the guess as it was. An ID that starts a group, a found group or, on a // subscription, what magpie wrote into its agent, is magpie's own shape // whatever the user said of it, and stays out. func smallCands(p provider.Provider, keep func(catalog.Model) bool) []smallCand { @@ -575,11 +577,13 @@ func smallCands(p provider.Provider, keep func(catalog.Model) bool) []smallCand if keep != nil && !keep(m) { continue } - if _, said := provider.ImageOverrideIn(s, p.ID, m.ID); !said { + // a subscription's list can have what magpie wrote into its agent + if strings.HasPrefix(m.ID, provider.GroupPrefix) || strings.HasPrefix(m.ID, provider.AutoPrefix) || (p.Account != nil && strings.Contains(m.ID, "/")) { + continue + } + if sees, said := provider.ImageOverrideIn(s, p.ID, m.ID); !said || !sees { l := strings.ToLower(m.ID) - // a subscription's list can have what magpie wrote into its agent - if strings.HasPrefix(m.ID, provider.GroupPrefix) || strings.HasPrefix(m.ID, provider.AutoPrefix) || (p.Account != nil && strings.Contains(m.ID, "/")) || - strings.ContainsAny(l, ":~") || slices.ContainsFunc([]string{"nano", "lite", "image", "audio", "tts", "embed", "free"}, func(w string) bool { return strings.Contains(l, w) }) { + if strings.ContainsAny(l, ":~") || slices.ContainsFunc([]string{"nano", "lite", "image", "audio", "tts", "embed", "free"}, func(w string) bool { return strings.Contains(l, w) }) { continue } } diff --git a/internal/gateway/small_kept_test.go b/internal/gateway/small_kept_test.go index fdc7a957a..7b065ec10 100644 --- a/internal/gateway/small_kept_test.go +++ b/internal/gateway/small_kept_test.go @@ -224,6 +224,34 @@ func TestAutoVisionPicksANamespacedIDTheUserSaidSees(t *testing.T) { } } +// Only the user's "it sees" lifts the shape guess in the small models' +// pool (#4359): their "takes no images" says nothing of the ID, so a +// colon ID they marked so stays out of the searcher's pool too, and an ID +// of magpie's own shape (a group's, auto's) stays out whatever they said. +func TestSmallCandsLiftOnlyWhatTheUserSaidSees(t *testing.T) { + fresh(t) + p := provider.Provider{ID: "relay", Name: "Relay", Chat: "http://relay.invalid/v1", Key: "k", + Models: []string{provider.GroupPrefix + "g", provider.AutoPrefix + "a", "cn:text-only", "cn:sees", "cn:unsaid"}} + if err := provider.Save(p); err != nil { + t.Fatal(err) + } + st := settings.Load() + st.ModelImages = map[string]bool{ + "relay/" + provider.GroupPrefix + "g": true, "relay/" + provider.AutoPrefix + "a": true, + "relay/cn:text-only": false, "relay/cn:sees": true, + } + if err := settings.Save(st); err != nil { + t.Fatal(err) + } + var ids []string + for _, c := range smallCands(p, nil) { + ids = append(ids, c.id) + } + if len(ids) != 1 || ids[0] != "cn:sees" { + t.Fatalf("pool %v, want only cn:sees", ids) + } +} + // rankSmall's order is pickSmall's pick of every subset, as pickSmall // was before the ranking: the first of a subset is its pick. func TestRankSmallIsPickSmall(t *testing.T) {