diff --git a/internal/provider/antigravity_models.go b/internal/provider/antigravity_models.go index 08f49dbf1..13d1e3c0e 100644 --- a/internal/provider/antigravity_models.go +++ b/internal/provider/antigravity_models.go @@ -39,6 +39,14 @@ func splitAntigravityID(id string) (family, effort string) { return id, "" } +// EffortFamily is the model an id with an effort word after it is a level +// of ("gemini-3.8-flash-medium" is gemini-3.8-flash), and the id itself +// when it has none. +func EffortFamily(id string) string { + f, _ := splitAntigravityID(id) + return f +} + // antigravityNameEffort is the level a name's last words in brackets say // ("Gemini 3.7 Flash (High)" is high), and the name without them. func antigravityNameEffort(name string) (string, string) { diff --git a/internal/usage/ledger_test.go b/internal/usage/ledger_test.go index 2ca3bd240..b18d8222d 100644 --- a/internal/usage/ledger_test.go +++ b/internal/usage/ledger_test.go @@ -605,3 +605,53 @@ func TestLedgerJudgesAnAntigravityCallByTheVariantItWentOutUnder(t *testing.T) { } } } + +// Antigravity answers a call that went out as a level of a model with the +// model's own name in modelVersion (#462: gemini-3.8-flash at medium went +// out as gemini-3.8-flash-medium and the reply named gemini-3.8-flash), +// which is the model asked for at the level asked for, not another one +// swapped in; a reply naming another level still is. +func TestLedgerAntigravityReplyNamingTheFamilyIsNoSwap(t *testing.T) { + home := t.TempDir() + t.Setenv("HOME", home) + t.Setenv("USERPROFILE", home) + t.Setenv("XDG_CONFIG_HOME", filepath.Join(home, ".config")) + t.Setenv("XDG_CACHE_HOME", filepath.Join(home, ".cache")) + var raw []catalog.Model + for _, id := range []string{"flash-9-low", "flash-9-medium", "flash-9-high", "flash-9-extra-low"} { + raw = append(raw, catalog.Model{ID: id}) + } + if err := catalog.SaveLive("antigravity", "", raw); err != nil { + t.Fatal(err) + } + catalog.Reset() + t.Cleanup(catalog.Reset) + os.MkdirAll(filepath.Dir(Path()), 0o755) + now := time.Now() + for i, c := range []struct{ effort, served string }{ + {"medium", "flash-9"}, {"minimal", "flash-9"}, {"", "models/flash-9"}, {"low", "flash-9-low"}, + {"medium", "flash-9-high"}, // another level answered: a swap + } { + Append(Record{Time: now.Add(time.Duration(i) * time.Minute), Provider: "antigravity", + Host: "antigravity.example", Model: "flash-9", Effort: c.effort, + Served: c.served, Input: 10, Output: 1, Status: 200}) + } + rows, _, _ := Ledger(All, Filter{}) + page := QueryPage(All, Filter{}, 0, 100) + for _, got := range [][]Row{rows, page.Rows} { + if len(got) != 5 { + t.Fatalf("rows %d: %+v", len(got), got) + } + if !got[0].Swapped { + t.Errorf("another level answering is a swap: %+v", got[0]) + } + for _, row := range got[1:] { + if row.Swapped { + t.Errorf("flash-9 at %q answered as %q is the model asked for: %+v", row.Effort, row.Served, row) + } + } + } + if !Swapped("flash-9-medium", "flash-8") || !Swapped("flash-9-medium", "flash-9-high") { + t.Error("another model or level is still a swap") + } +} diff --git a/internal/usage/served.go b/internal/usage/served.go index 6b591f791..aeab1e377 100644 --- a/internal/usage/served.go +++ b/internal/usage/served.go @@ -42,12 +42,16 @@ func bareModel(m string) string { } // Swapped reports whether served is another model than sent: not the same -// name, however dated, pinned or prefixed. A vendor's "auto" (Copilot's, +// name, however dated, pinned or prefixed. A call that went out as one level +// of a model (an Antigravity account's gemini-3.8-flash-medium) answered +// under the model's own name is that model at that level: Antigravity's +// reply names the family, not the variant (#462). Another level is another +// model, as AntigravitySentID has it. A vendor's "auto" (Copilot's, // Cursor's) asked it to pick, so whichever answers wasn't swapped in, nor // is the member another magpie's routing group sent it to (GroupRouted). func Swapped(sent, served string) bool { a, b := bareModel(sent), bareModel(served) - return a != "" && b != "" && a != b && a != "auto" && !GroupRouted(sent, served) + return a != "" && b != "" && a != b && a != "auto" && bareModel(provider.EffortFamily(a)) != b && !GroupRouted(sent, served) } // GroupRouted reports whether sent is a routing group of another magpie