From 21882a68dce527ca4bda9fbdd81c1c772ad91665 Mon Sep 17 00:00:00 2001 From: yetone Date: Sun, 1 Nov 2026 13:52:21 +0800 Subject: [PATCH] providers: a model's list price skips Grok's two name patterns unless it names grok- /api/providers prices every model of every provider on each poll, and pricedNames ran grokWindow and grokEffort over each id, lowercasing it twice. Both patterns need "grok-" in the lowercased id, so any other id now returns before them; what a Grok id is priced as is unchanged. pricedOnce's memo key is sized once instead of growing by doublings. Run (on mote unless named): - go test -count=1 -timeout 45m ./internal/provider ok (103.8s), ./internal/catalog ok; GOOS=linux and windows go vet of both ok; gofmt clean (here). - Broken by hand: the guard narrowed to "grokx-" turns TestGrokEffortListPrice, TestCursorGrokFastPrice and TestGrokWindowWithoutKListPrice red, so the Grok aliases are covered. - Here, 200 GET /api/providers on the sandbox with the real config copy (offline, proxy :9), against v0.1.2548's tree: pricedNames 0.28s -> 0.02s, ListPrice 0.63s -> 0.40s; process CPU 4.62s -> 4.24s, median 20.4ms -> 19.0ms. pricedOnce stayed ~0.20s: its cost is the key's bytes, not the growth. Not run: the full ./... suite; GUI tests (the JSON is the same). --- internal/catalog/pricememo.go | 5 +++++ internal/provider/models.go | 10 ++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/internal/catalog/pricememo.go b/internal/catalog/pricememo.go index ec904d132..56a820630 100644 --- a/internal/catalog/pricememo.go +++ b/internal/catalog/pricememo.go @@ -35,6 +35,11 @@ var pricedRuns atomic.Uint64 // PricedBy calls itself for a renamed id. func pricedOnce(at int, kind byte, providers []string, id string, find func() (Price, bool)) (Price, bool) { var k strings.Builder + n := 2 + len(id) + for _, p := range providers { + n += len(p) + 1 + } + k.Grow(n) // one allocation, not one a doubling: it is made for every price asked k.WriteByte(kind) for _, p := range providers { k.WriteString(p) diff --git a/internal/provider/models.go b/internal/provider/models.go index e9c8b2ec2..65013366c 100644 --- a/internal/provider/models.go +++ b/internal/provider/models.go @@ -2608,10 +2608,16 @@ func pricedNames(model string) []string { if model == "codex-auto-review" { out = append(out, "gpt-5.6-luna") } - if m := grokWindow.FindStringSubmatch(strings.ToLower(strings.TrimSpace(model))); m != nil { + // both patterns name grok-: every other model of every provider's list + // went through two regexps on each Providers poll + l := strings.ToLower(strings.TrimSpace(model)) + if !strings.Contains(l, "grok-") { + return out + } + if m := grokWindow.FindStringSubmatch(l); m != nil { out = append(out, m[1]) } - if m := grokEffort.FindStringSubmatch(strings.ToLower(strings.TrimSpace(model))); m != nil { + if m := grokEffort.FindStringSubmatch(l); m != nil { out = append(out, m[1]) } return out