From 3783bbf2bfad572616711e327953c0fd421c59eb Mon Sep 17 00:00:00 2001 From: tin-berri Date: Fri, 14 Aug 2026 16:25:58 -0700 Subject: [PATCH] fix(ui): show zeroed auto-router usage stats when a window has no sessions (#36868) * fix(ui): show zeroed auto-router usage stats when a window has no sessions * test(ui): assert the muted track on the empty share-of-turns bar --- .../AutoRouterBenchmarksTab.test.tsx | 53 +++++++++++++++++-- .../_components/AutoRouterBenchmarksTab.tsx | 5 +- 2 files changed, 51 insertions(+), 7 deletions(-) diff --git a/ui/litellm-dashboard/src/app/(dashboard)/cost-optimization/_components/AutoRouterBenchmarksTab.test.tsx b/ui/litellm-dashboard/src/app/(dashboard)/cost-optimization/_components/AutoRouterBenchmarksTab.test.tsx index 482901dfd14..8d628a264f2 100644 --- a/ui/litellm-dashboard/src/app/(dashboard)/cost-optimization/_components/AutoRouterBenchmarksTab.test.tsx +++ b/ui/litellm-dashboard/src/app/(dashboard)/cost-optimization/_components/AutoRouterBenchmarksTab.test.tsx @@ -66,6 +66,36 @@ const totals = (overrides: Partial = {}): Totals => ({ ...overrides, }); +const zeroBucket = { turns: 0, hits: 0, hit_rate_pct: 0 }; + +const zeroCache: AutoRouterCacheStats = { + coverage_pct: 0, + hit_rate_pct: 0, + same_model: zeroBucket, + first_visit: zeroBucket, + return_to_tier: zeroBucket, + unordered_turns: 0, + return_misses_expired: 0, + return_misses_within_ttl: 0, + return_misses_unknown: 0, + ttl_5m_turns: 0, + ttl_1h_turns: 0, +}; + +const zeroTotals: Totals = { + sessions: 0, + turns: 0, + avg_turns_per_session: 0, + avg_session_seconds: 0, + avg_tokens_per_session: 0, + spend: 0, + saved_spend: 0, + baseline_spend: 0, + saved_pct: 0, + saved_per_session: 0, + cache: zeroCache, +}; + const group = (overrides: Partial = {}): AutoRouterBenchmarkGroup => ({ router_name: "claude-auto", router_type: "complexity", @@ -162,6 +192,7 @@ describe("AutoRouterBenchmarksTab", () => { expect(screen.getByText("97.7%")).toBeInTheDocument(); expect(screen.getByText("24.3%")).toBeInTheDocument(); expect(screen.getByText("81.6%")).toBeInTheDocument(); + expect(screen.getByRole("img", { name: "Share of turns by bucket" })).not.toHaveClass("bg-muted"); }); it("summarizes the cache column from the bucketed turns, not the session turns", () => { @@ -252,11 +283,25 @@ describe("AutoRouterBenchmarksTab", () => { expect(screen.getByText("Auto-router usage is unavailable right now")).toBeInTheDocument(); }); - it("says so when there are no auto-router sessions at all", () => { - mockHook({ data: response([]) }); + it("renders the full dashboard with zeroed stats when the window has no sessions", () => { + mockHook({ data: response([], zeroTotals) }); renderTab(); - expect(screen.getByText("No auto-router sessions in this window yet")).toBeInTheDocument(); + expect(screen.getByText("Total estimated savings")).toBeInTheDocument(); + expect(screen.getAllByText("$0.00")).toHaveLength(4); + expect(screen.getByText("across 0 sessions")).toBeInTheDocument(); + expect(screen.getByText("0s")).toBeInTheDocument(); + expect(screen.getByText(/turns measured/)).toBeInTheDocument(); + expect(screen.getAllByText("0.0%").length).toBeGreaterThan(0); + expect(screen.getByRole("img", { name: "Share of turns by bucket" })).toHaveClass("bg-muted"); + }); + + it("shows the savings delta as an unsigned zero when nothing was saved", () => { + mockHook({ data: response([], zeroTotals) }); + renderTab(); + + expect(screen.getByText("0%")).toBeInTheDocument(); + expect(screen.queryByText("-0%")).not.toBeInTheDocument(); }); it("requests the default thirty day window and widens or narrows it from the picker", () => { @@ -303,7 +348,7 @@ describe("AutoRouterBenchmarksTab", () => { }); it("keeps the window picker reachable while a window has no sessions", () => { - mockHook({ data: response([]) }); + mockHook({ data: response([], zeroTotals) }); renderTab(); expect(screen.getByRole("tab", { name: "30d" })).toBeInTheDocument(); diff --git a/ui/litellm-dashboard/src/app/(dashboard)/cost-optimization/_components/AutoRouterBenchmarksTab.tsx b/ui/litellm-dashboard/src/app/(dashboard)/cost-optimization/_components/AutoRouterBenchmarksTab.tsx index 80ddef29c9d..f0ca536da39 100644 --- a/ui/litellm-dashboard/src/app/(dashboard)/cost-optimization/_components/AutoRouterBenchmarksTab.tsx +++ b/ui/litellm-dashboard/src/app/(dashboard)/cost-optimization/_components/AutoRouterBenchmarksTab.tsx @@ -64,7 +64,7 @@ const HeroCard: React.FC<{ view: BenchmarkView }> = ({ view }) => { variant="secondary" className={cheaper ? "bg-emerald-50 text-emerald-700" : "bg-red-50 text-destructive"} > - {cheaper ? "-" : "+"} + {stats.saved_spend !== 0 && (cheaper ? "-" : "+")} {Math.abs(stats.saved_pct).toFixed(0)}% @@ -95,7 +95,7 @@ const StackedTurnBar: React.FC<{ buckets: BucketRow[] }> = ({ buckets }) => { return (
@@ -230,7 +230,6 @@ const BenchmarksBody: React.FC = ({ isPending, error, data, return Auto-router usage is visible to proxy admin roles only; } if (error || !data) return Auto-router usage is unavailable right now; - if (data.groups.length === 0) return No auto-router sessions in this window yet; const view = viewFor(data, selectedKey); const stats = view.stats;