diff --git a/internal/provider/google.go b/internal/provider/google.go index 067cf9731..cff4abf85 100644 --- a/internal/provider/google.go +++ b/internal/provider/google.go @@ -1190,7 +1190,7 @@ func (g googleAccount) pools(ctx context.Context, ws []QuotaWindow) []QuotaWindo if pool == "" { continue } - n := 0 + n, fiveHour := 0, false for _, b := range gr.Buckets { if b.Disabled { continue @@ -1220,9 +1220,10 @@ func (g googleAccount) pools(ctx context.Context, ws []QuotaWindow) []QuotaWindo } out = append(out, w) n++ + fiveHour = fiveHour || w.Span == modelSpan } - if n == 0 { - continue + if n == 0 || !fiveHour { + continue // without the group's 5 hours its models' own stand (#745) } // a model is in the group its name or description names its // family in ("Models within this group: Claude Opus, Claude @@ -1237,13 +1238,30 @@ func (g googleAccount) pools(ctx context.Context, ws []QuotaWindow) []QuotaWindo return out } +// modelSpan is the window fetchAvailableModels gives a model of +// Antigravity's, its 5 hours, which its window leaves without a Span. +const modelSpan = 5 * time.Hour + // PooledWindows are ws as a page of text shows them: a pool's own windows, // named with their pool ("Gemini · 7 days"), in place of the per-model -// windows drawing on it; ws as it is when it has no pool. +// windows drawing on it; ws as it is when it has no pool. A model's window +// goes only for a pool window of its span: one whose pool has only its +// 7 days stays, the 5 hours it reads being the only ones to be had (#745). func PooledWindows(ws []QuotaWindow) []QuotaWindow { if !slices.ContainsFunc(ws, func(w QuotaWindow) bool { return w.Pool != "" && w.Model == "" }) { return ws } + span := func(w QuotaWindow) time.Duration { + if w.Span == 0 && w.Model != "" { + return modelSpan + } + return w.Span + } + pooled := func(m QuotaWindow) bool { + return slices.ContainsFunc(ws, func(w QuotaWindow) bool { + return w.Pool == m.Pool && w.Model == "" && w.Span == span(m) + }) + } var out []QuotaWindow for _, w := range ws { switch { @@ -1252,6 +1270,8 @@ func PooledWindows(ws []QuotaWindow) []QuotaWindow { case w.Model == "": w.Name = w.Pool + " · " + w.Name out = append(out, w) + case !pooled(w): + out = append(out, w) } } return out diff --git a/internal/provider/google_test.go b/internal/provider/google_test.go index 37e1e912b..8688005ff 100644 --- a/internal/provider/google_test.go +++ b/internal/provider/google_test.go @@ -540,6 +540,63 @@ func TestAntigravityQuotaPools(t *testing.T) { if len(q.Windows) != 4 || q.Windows[0].Pool != "" || len(PooledWindows(q.Windows)) != 4 { t.Errorf("without a summary: %+v", q.Windows) } + + // a summary with a group's week and not its 5 hours (#745): the + // group's models aren't put in it, so their 5 hours stay beside its week + f.mu.Lock() + f.summary = `{"groups":[ + {"displayName":"Gemini Models","description":"Models within this group: Gemini Flash, Gemini Pro","buckets":[ + {"bucketId":"gemini-weekly","window":"weekly","remainingFraction":0.75,"resetTime":"2099-01-07T00:00:00Z"}, + {"bucketId":"gemini-5h","window":"5h","remainingFraction":1,"disabled":true}]}]}` + f.mu.Unlock() + q = googleLogins("antigravity")[0].acct.quota(context.Background(), "") + got = nil + for _, w := range PooledWindows(q.Windows) { + got = append(got, w.Name+"|"+w.Pool) + } + if strings.Join(got, ",") != "Claude Opus 4.6 (Thinking)|,Gemini 3 Flash|,Gemini 3.1 Pro (High)|,GPT-OSS 120B (Medium)|,Gemini · 7 days|Gemini" { + t.Errorf("week alone: pooled = %v", got) + } +} + +// #745 (werldl517-cyber): a pool's windows stand in for its models' only +// for the spans the pool has; with only its week, a model's 5 hours stay. +func TestPooledWindowsPartialAggregateKeepsModelFallback(t *testing.T) { + ws := []QuotaWindow{ + {Name: "Gemini 3 Flash", Model: "gemini-3-flash", Pool: "Gemini", Span: 5 * time.Hour, Used: 40}, + {Name: "7 days", Pool: "Gemini", Span: 7 * 24 * time.Hour, Aside: true, Used: 80}, + } + got := PooledWindows(ws) + for _, w := range got { + t.Logf("name=%q model=%q pool=%q span=%s used=%.0f aside=%v", w.Name, w.Model, w.Pool, w.Span, w.Used, w.Aside) + } + if len(got) != 2 { + t.Fatalf("got %d windows, want the 5h model fallback plus the 7d pool aggregate", len(got)) + } + + model := func(id string, span time.Duration) QuotaWindow { + return QuotaWindow{Name: id, Model: id, Pool: "Gemini", Span: span} + } + five := QuotaWindow{Name: "5 hours", Pool: "Gemini", Span: 5 * time.Hour, Aside: true} + week := QuotaWindow{Name: "7 days", Pool: "Gemini", Span: 7 * 24 * time.Hour, Aside: true} + for _, c := range []struct { + name string + ws []QuotaWindow + want string + }{ + {"5 hours and week", []QuotaWindow{model("a", 0), model("b", 0), week, five}, "Gemini · 7 days,Gemini · 5 hours"}, + {"week alone", []QuotaWindow{model("a", 0), model("b", 5*time.Hour), week}, "a,b,Gemini · 7 days"}, + {"5 hours alone", []QuotaWindow{model("a", 0), model("b", 0), five}, "Gemini · 5 hours"}, + {"no pool windows", []QuotaWindow{model("a", 0), model("b", 0)}, "a,b"}, + } { + var names []string + for _, w := range PooledWindows(c.ws) { + names = append(names, w.Name) + } + if strings.Join(names, ",") != c.want { + t.Errorf("%s: %v, want %s", c.name, names, c.want) + } + } } // Antigravity's list is taken as Antigravity gives it (0000FF on Discord: