From 3c9904f80456e70b2137ebfc337f4283fdfd403d Mon Sep 17 00:00:00 2001 From: Lxcardoza993 <265670745+Lxcardoza993@users.noreply.github.com> Date: Wed, 29 Jul 2026 21:57:22 +0800 Subject: [PATCH] fix(manager-server): drop priced models from sync feedback --- .../internal/service/modelprice/service.go | 27 ++++++++++ .../service/modelprice/service_test.go | 50 +++++++++++++++++++ 2 files changed, 77 insertions(+) diff --git a/apps/manager-server/internal/service/modelprice/service.go b/apps/manager-server/internal/service/modelprice/service.go index 43ae24b33..f1a4afbd8 100644 --- a/apps/manager-server/internal/service/modelprice/service.go +++ b/apps/manager-server/internal/service/modelprice/service.go @@ -147,6 +147,7 @@ func (s *Service) Sync(ctx context.Context, req SyncRequest) (SyncResult, error) if err != nil { return SyncResult{}, err } + selection = filterSelectionFeedback(selection, prices) return SyncResult{ Source: syncResultSource(sources), Sources: sources, @@ -824,3 +825,29 @@ func readString(entry map[string]any, key string) string { return "" } } + +// filterSelectionFeedback drops candidate and unmatched entries for models that +// already have a stored price. Sync feedback should only report models the user +// can still act on; the prices page intentionally hides priced rows from the +// pending-confirmation filter to protect manually configured prices, so reporting +// them here only produces misleading counts. +func filterSelectionFeedback(selection priceSelectionResult, prices map[string]store.ModelPrice) priceSelectionResult { + if len(selection.Candidates) == 0 && len(selection.Unmatched) == 0 { + return selection + } + candidates := make([]SyncCandidateSet, 0, len(selection.Candidates)) + for _, set := range selection.Candidates { + if _, priced := prices[set.Model]; !priced { + candidates = append(candidates, set) + } + } + unmatched := make([]string, 0, len(selection.Unmatched)) + for _, model := range selection.Unmatched { + if _, priced := prices[model]; !priced { + unmatched = append(unmatched, model) + } + } + selection.Candidates = candidates + selection.Unmatched = unmatched + return selection +} diff --git a/apps/manager-server/internal/service/modelprice/service_test.go b/apps/manager-server/internal/service/modelprice/service_test.go index 9930522b5..165508f80 100644 --- a/apps/manager-server/internal/service/modelprice/service_test.go +++ b/apps/manager-server/internal/service/modelprice/service_test.go @@ -209,3 +209,53 @@ func closePrice(left float64, right float64) bool { } return right-left < 0.0000001 } + +func TestFilterSelectionFeedbackDropsPricedModels(t *testing.T) { + selection := priceSelectionResult{ + Prices: map[string]store.ModelPrice{}, + Matched: map[string]store.ModelPrice{}, + Candidates: []SyncCandidateSet{ + { + Model: "priced-ambiguous", + Candidates: []SyncCandidate{ + {SourceModelID: "vendor/priced-ambiguous", Score: 0.9, Price: store.ModelPrice{Prompt: 1, Completion: 2}}, + }, + }, + { + Model: "unpriced-ambiguous", + Candidates: []SyncCandidate{ + {SourceModelID: "vendor/unpriced-ambiguous", Score: 0.9, Price: store.ModelPrice{Prompt: 3, Completion: 4}}, + }, + }, + }, + Unmatched: []string{"priced-unmatched", "unpriced-unmatched"}, + } + stored := map[string]store.ModelPrice{ + "priced-ambiguous": {Prompt: 5, Completion: 6}, + "priced-unmatched": {Prompt: 7, Completion: 8}, + } + + filtered := filterSelectionFeedback(selection, stored) + + if len(filtered.Candidates) != 1 || filtered.Candidates[0].Model != "unpriced-ambiguous" { + t.Fatalf("candidates = %#v", filtered.Candidates) + } + if len(filtered.Unmatched) != 1 || filtered.Unmatched[0] != "unpriced-unmatched" { + t.Fatalf("unmatched = %#v", filtered.Unmatched) + } +} + +func TestFilterSelectionFeedbackKeepsEverythingWithoutStoredPrices(t *testing.T) { + selection := priceSelectionResult{ + Candidates: []SyncCandidateSet{ + {Model: "unpriced-ambiguous", Candidates: []SyncCandidate{{SourceModelID: "vendor/x", Score: 0.9}}}, + }, + Unmatched: []string{"unpriced-unmatched"}, + } + + filtered := filterSelectionFeedback(selection, nil) + + if len(filtered.Candidates) != 1 || len(filtered.Unmatched) != 1 { + t.Fatalf("filtered = %#v", filtered) + } +}