Skip to content

fix(admin): use 4h default on model detail - #1854

Merged
steebchen merged 3 commits into
mainfrom
ariana/thompson-75f3
Mar 19, 2026
Merged

steebchen merged 3 commits into
mainfrom
ariana/thompson-75f3

Conversation

@steebchen

@steebchen steebchen commented Mar 19, 2026

Copy link
Copy Markdown
Member

Summary

  • fix the admin model detail API fallback so it actually defaults to 4h instead of 24h
  • make the admin model detail page honor ?window= during SSR and default to 4h when absent
  • skip the redundant first client-side model detail refetch when the server already rendered the active window

Root cause

The model detail page had inconsistent defaults across the stack:

  • the /admin/models/{modelId} OpenAPI schema said the default window was 4h
  • the route handler actually fell back to 24h
  • the admin page SSR request omitted window, so it inherited that wider 24h query
  • the client page also defaulted to 24h, then immediately re-fetched the same wider window on mount

That meant production was doing a larger-than-expected aggregation scan and duplicate initial requests before the page even settled.

Verification

  • pnpm --filter api build
  • pnpm --filter admin build

Summary by CodeRabbit

  • New Features

    • New per-provider history endpoint and UI support to view provider-specific timeseries for a model.
    • Centralized model-level provider history loading with charts that can accept externally supplied data/loading.
  • Changes

    • Default history window for model details and provider history changed from 24h to 4h.
    • Initial chart loading behavior adjusted to avoid redundant fetches when an initial window is provided.

Copilot AI review requested due to automatic review settings March 19, 2026 10:30
@coderabbitai

coderabbitai Bot commented Mar 19, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Review was skipped due to path filters

⛔ Files ignored due to path filters (3)
  • apps/code/src/lib/api/v1.d.ts is excluded by !**/v1.d.ts
  • apps/playground/src/lib/api/v1.d.ts is excluded by !**/v1.d.ts
  • apps/ui/src/lib/api/v1.d.ts is excluded by !**/v1.d.ts

CodeRabbit blocks several paths by default. You can override this behavior by explicitly including those paths in the path filters. For example, including **/dist/** will override the default block on the dist directory, by removing the pattern from both the lists.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 3a048335-a6be-4e69-90f4-c8e4489b60b9

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Walkthrough

Backend adds a new admin endpoint returning per-provider history and changes default history window from "24h" to "4h"; frontend reads/validates a window search param, propagates it to the API, and moves provider history fetching to a centralized model-level call with externally-controlled charts.

Changes

Cohort / File(s) Summary
Backend: admin routes
apps/api/src/routes/admin.ts
Changed default history window fallback from "24h" to "4h" in model detail handler; added GET /models/{modelId}/providers/history endpoint and providerHistoryMapResponseSchema that aggregates minute-level modelProviderMappingHistory with hourly projectHourlyModelStats per provider.
Frontend: page + client
ee/admin/src/app/models/[modelId]/page.tsx, ee/admin/src/components/model-detail-client.tsx
Page now reads/validates searchParams.window (defaults to "4h"), passes it to backend; ModelDetailClient gains initialWindow prop and uses a ref to skip initial fetch when appropriate; initial loading state adjusted.
Frontend: charts
ee/admin/src/components/history-chart.tsx, ee/admin/src/components/model-provider-charts.tsx
HistoryChart now supports externally-controlled data/loading (externalData, externalLoading) and optional fetchData; ModelProviderCharts switched to centralized getModelProviderHistories(modelId, window) call, storing historyByProvider and shared loading, and forwards external props to charts.
Frontend: lib & types
ee/admin/src/lib/admin-history.ts, ee/admin/src/lib/types.ts
Added getModelProviderHistories(modelId, window) server helper that calls the new admin endpoint; added ModelProviderHistoriesResponse type derived from the new endpoint.

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant AdminAPI
  participant DB as Storage
  Client->>AdminAPI: GET /admin/models/{modelId}/providers/history?window=4h
  AdminAPI->>DB: Query modelProviderMappingHistory (minute-level) for modelId + window
  AdminAPI->>DB: Query projectHourlyModelStats (hour-level) for modelId + window
  AdminAPI->>AdminAPI: Aggregate per-provider minute mappings + hourly cost, compute mapHistoryRows
  AdminAPI-->>Client: 200 JSON { providerId: [historyPoints], ... }
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Suggested reviewers

  • smakosh
🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the primary change: fixing the admin model detail to use a 4h default window instead of 24h, which is the core objective addressing the root cause of the performance issue.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch ariana/thompson-75f3
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@steebchen
steebchen enabled auto-merge March 19, 2026 10:31

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Aligns the admin model detail “history window” default across the API and admin UI to reduce unnecessary aggregation work and eliminate an avoidable initial client refetch.

Changes:

  • API model detail endpoint now defaults window to 4h when absent.
  • Admin model detail SSR now parses ?window= (defaulting to 4h) and includes it in the server-side API request.
  • Client model detail now defaults to 4h and attempts to skip the initial refetch when SSR already rendered the active window.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
ee/admin/src/components/model-detail-client.tsx Defaults to 4h and adds “skip first refetch if SSR already has it” behavior.
ee/admin/src/app/models/[modelId]/page.tsx Parses window during SSR, defaults to 4h, passes initialWindow, and includes window in the API query.
apps/api/src/routes/admin.ts Fixes model detail route handler fallback default from 24h to 4h.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines 115 to +121
useEffect(() => {
if (!initialLoadSkippedRef.current && window === initialWindow) {
initialLoadSkippedRef.current = true;
return;
}
void loadStats(window);
}, [loadStats, window]);
}, [initialWindow, loadStats, window]);
Comment on lines +9 to +30
import type { HistoryWindow } from "@/components/history-chart";

const validHistoryWindows = new Set<HistoryWindow>([
"1m",
"2m",
"5m",
"15m",
"1h",
"2h",
"4h",
"12h",
"24h",
"2d",
"7d",
]);

function parseHistoryWindow(value?: string): HistoryWindow {
if (value && validHistoryWindows.has(value as HistoryWindow)) {
return value as HistoryWindow;
}
return "4h";
}
@steebchen
steebchen added this pull request to the merge queue Mar 19, 2026
Merged via the queue into main with commit 1a0335c Mar 19, 2026
7 checks passed
@steebchen
steebchen deleted the ariana/thompson-75f3 branch March 19, 2026 10:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants