Skip to content

feat(web): add public leaderboard provider race endpoint - #4787

Merged
chrarnoldus merged 6 commits into
mainfrom
leaderboard-provider-race-endpoint
Jul 28, 2026
Merged

feat(web): add public leaderboard provider race endpoint#4787
chrarnoldus merged 6 commits into
mainfrom
leaderboard-provider-race-endpoint

Conversation

@pedroheyerdahl

@pedroheyerdahl pedroheyerdahl commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds a public Snowflake-backed endpoint GET /api/public/leaderboard-provider-race that serves weekly token volume per model lab for the kilo.ai/leaderboard/race visualization. The race page currently hardcodes 53 weeks of data in the landing repo; this endpoint lets it load dynamically.

The query groups kilo_dw.dbt_prod.usage_daily at week × model_provider_company × is_open_weights (fixed start 2025-07-01 → most recent complete day). One payload drives both the per-lab race and an open-weight vs proprietary toggle. The lab mapping (model_provider_company, is_open_weights) comes from the dbt model_dim seed rather than being re-derived in SQL — this is the same gap the Omni dashboard's CASE workaround was papering over.

Follows the existing createPublicSnowflakeReport pattern (Redis-cached 1h, CORS, Sentry) used by leaderboard-model-usage and leaderboard-model-provider-usage.

Verification

  • oxlint clean on both changed files (0 errors)
  • Route is a structural copy of the adjacent leaderboard-model-usage/route.ts; tsgo reports no errors on the new files (full-repo typecheck blocked locally by unbuilt workspace packages — pre-existing, unrelated)
  • End-to-end with live Snowflake data — validated locally against kilo_dw.dbt_prod.usage_daily

Live data verification (2026-07-27)

Endpoint tested locally on localhost:3000:

GET /api/public/leaderboard-provider-race
HTTP 200 | 207,685 bytes | 9ms (Redis-cached)
2,361 rows | 56 weeks | 50 providers
First week: 2025-06-30
Last week:  2026-07-20  (current partial week correctly excluded)

Top 5 labs in latest complete week (Jul 20, 2026):

Rank Provider Tokens Open Weights
1 Other 1.06T
2 StepFun 1.56T
3 DeepSeek 942B
4 Z.ai 438B
5 OpenAI 381B

Total platform volume: 6.90T tokens — matches the landing page headline.

Snowflake Query History confirms the query executed with status Success on warehouse WH_DBT_BACKEND_SANDBOX as KILOCODE_USER_DEV.

anding race page consuming this endpoint
Screenshot 2026-07-27 at 11 01 58

Snowflake query history (Success)
Screenshot 2026-07-27 at 11 07 08

Screenshot 2026-07-27 at 11 23 30

No errors in server logs. To verify: in the cloud tmux dashboard, select the nextjs pane (arrow keys + Enter) — incoming requests log there with status codes. Alternatively, browser DevTools → Network tab shows the 200 response with full JSON body.

Visual Changes

N/A

Reviewer Notes

  • Deploy dependency: the query reads usage_daily.is_open_weights, added by kilocode-dbt PR feat(kiloclaw): controller, device pairing, and dashboard redesign #480 + its backfill (2026-07-25-backfill-is-open-weights.sql). That backfill must run before this endpoint returns data; until then the query errors and the endpoint returns 502 (cached null).
  • Response shape: [{ weekStart: "YYYY-MM-DD", provider: string, isOpenWeights: boolean | null, tokens: number }]. isOpenWeights is null for unmapped models (is_open_weights NULL in model_dim) so the client can distinguish "unknown" from a confirmed closed-weight lab; only explicit 'true'/'false' become a boolean. is_open_weights is per-model in dbt, so a lab like Alibaba appears in both open and closed rows; the client sums across isOpenWeights for the lab race and across provider for the open/closed view.
  • model_provider_company = 'other' (unmapped models) is included so the client can bucket it; drop here if we'd rather exclude upstream.

Comment thread apps/web/src/app/api/public/leaderboard-provider-race/route.ts Outdated
@kilo-code-bot

kilo-code-bot Bot commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Executive Summary

The incremental change adds a SQL filter to LEADERBOARD_PROVIDER_RACE_QUERY excluding BYOK infrastructure-artifact model ids (URIs, ckpt: refs, HuggingFace class names); the filter matches the accompanying comment, uses appropriately case-sensitive/insensitive matching, and introduces no logic bugs or breaking changes.

Files Reviewed (1 file)
  • apps/web/src/app/api/public/leaderboard-provider-race/route.ts - new NOT (...) filter clause; no issues
Previous Review Summaries (7 snapshots, latest commit 8447a0a)

Current summary above is authoritative. Previous snapshots are kept for context only.

Previous review (commit 8447a0a)

Status: No Issues Found | Recommendation: Merge

Executive Summary

No code changes since the previous review (commit ced28ee); the underlying files are byte-identical, and the previously flagged is_open_weights NULL-to-false coercion issue remains resolved via parseOpenWeights.

Files Reviewed (3 files)
  • apps/web/src/app/api/public/leaderboard-provider-race/route.ts - unchanged; NULL-coercion issue remains resolved
  • apps/web/src/app/api/public/leaderboard-provider-race/route.test.ts - unchanged; no issues
  • apps/web/src/lib/redis-keys.ts - unchanged; no issues

Previous review (commit ced28ee)

Status: No Issues Found | Recommendation: Merge

Executive Summary

Reviewed the incremental change since the last review (commit b48b90b → ced28ee): a type-only cleanup of the new test file (replacing the namespace-style type import with a ReturnType alias and typing the redis set mock) with no logic changes; the previously resolved is_open_weights NULL-to-false coercion issue in route.ts remains fixed via parseOpenWeights, and no new issues were found.

Files Reviewed (3 files)
  • apps/web/src/app/api/public/leaderboard-provider-race/route.ts - unchanged from last review; NULL-coercion issue remains resolved
  • apps/web/src/app/api/public/leaderboard-provider-race/route.test.ts - type-only cleanup (import type, mock typings); no logic changes; no issues
  • apps/web/src/lib/redis-keys.ts - unchanged; no issues

Previous review (commit b48b90b)

Status: No Issues Found | Recommendation: Merge

Executive Summary

Full review at the current head (commit SHAs were rewritten again since the last review); the only new commit adds test coverage for the route, and the previously resolved NULL-to-false coercion issue in is_open_weights remains fixed via parseOpenWeights returning null for unmapped/unexpected values — no new issues found.

Files Reviewed (3 files)
  • apps/web/src/app/api/public/leaderboard-provider-race/route.ts - unchanged from last review; NULL-coercion issue remains resolved
  • apps/web/src/app/api/public/leaderboard-provider-race/route.test.ts - new test file; covers 503/502/200 paths, CORS/OPTIONS, and the isOpenWeights true/false/null mapping; no issues
  • apps/web/src/lib/redis-keys.ts - no issues

Previous review (commit c217b0a)

Status: No Issues Found | Recommendation: Merge

Executive Summary

Full review of the current head (the branch's commit SHAs were rewritten since the prior review, so the previous incremental-diff base commit no longer exists in history); the public leaderboard provider race endpoint correctly maps unmapped/NULL is_open_weights values to null rather than coercing to false, and no new issues were found.

Files Reviewed (2 files)
  • apps/web/src/app/api/public/leaderboard-provider-race/route.ts - previously flagged NULL-coercion issue remains resolved; no new issues
  • apps/web/src/lib/redis-keys.ts - no issues

Previous review (commit aa9aee5)

Status: No Issues Found | Recommendation: Merge

Executive Summary

The previously flagged NULL-coercion issue in the provider race endpoint is now resolved by mapping unmapped is_open_weights values to null instead of false.

Files Reviewed (1 file changed since last review)
  • apps/web/src/app/api/public/leaderboard-provider-race/route.ts - previous WARNING resolved (parseOpenWeights now returns null for unmapped/NULL values instead of coercing to false); no new issues

Previous review (commit 3431d73)

Status: 1 Issue Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 1
SUGGESTION 0
Issue Details (click to expand)

WARNING

File Line Issue
apps/web/src/app/api/public/leaderboard-provider-race/route.ts 54 is_open_weights NULL (e.g. unmapped model_provider_company = 'other' rows) is silently coerced to false instead of being validated or flagged
Files Reviewed (1 file changed since last review)
  • apps/web/src/app/api/public/leaderboard-provider-race/route.ts - query updated to exclude the partial current week; no new issues

Fix these issues in Kilo Cloud

Previous review (commit e1a74e2)

Status: 1 Issue Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 1
SUGGESTION 0
Issue Details (click to expand)

WARNING

File Line Issue
apps/web/src/app/api/public/leaderboard-provider-race/route.ts 53 is_open_weights NULL (e.g. unmapped model_provider_company = 'other' rows) is silently coerced to false instead of being validated or flagged
Files Reviewed (2 files)
  • apps/web/src/app/api/public/leaderboard-provider-race/route.ts - 1 issue
  • apps/web/src/lib/redis-keys.ts - 0 issues

Fix these issues in Kilo Cloud


Reviewed by claude-sonnet-5 · Input: 28 · Output: 4.9K · Cached: 735.6K

Review guidance: REVIEW.md from base branch main

@pedroheyerdahl
pedroheyerdahl force-pushed the leaderboard-provider-race-endpoint branch from aa9aee5 to c217b0a Compare July 27, 2026 13:10
Weekly token volume per model lab for the kilo.ai/leaderboard/race
visualization. Grouped at week x model_provider_company x is_open_weights
so one payload drives both the per-lab race and an open-weight vs
proprietary toggle. Lab mapping comes from the dbt model_dim seed rather
than being re-derived in SQL.

Depends on the kilocode-dbt usage_daily backfill that adds is_open_weights.
Match the prior '52 complete weeks' behavior so the latest returned week
is always complete (keeps the insights 'latest complete week' stat correct).
Map only explicit 'true'/'false' strings to a boolean and return null for
NULL/unmapped models so the open/closed split isn't silently corrupted by
model_dim mapping gaps. Also removes the string===boolean comparison that
broke the typecheck (TS2367).
Mocks the Snowflake statement executor and Redis to exercise the route
without a warehouse: 503 when unconfigured, 502 on query failure or a
malformed row, CORS/OPTIONS, and the is_open_weights mapping where only
'true'/'false' become booleans and NULL/unknown become null.
Type the redis set mock so mockResolvedValue isn't inferred as never, and
replace the namespace-style SnowflakeModule type import (TS2709) with a
ReturnType alias over a type-only function import. Verified with tsgo.
@pedroheyerdahl
pedroheyerdahl force-pushed the leaderboard-provider-race-endpoint branch from ced28ee to 8447a0a Compare July 27, 2026 14:01
Filter URI/path ids (s3://, gs://...), ckpt: checkpoint refs, and
HuggingFace class names (AtlasForCausalLM) out of the race aggregation.
These are single-org self-hosted/eval traffic that can't be attributed to
a lab and would dominate the 'other' bucket. Applied in the race query
only - the dbt usage_daily base model stays complete.
@chrarnoldus
chrarnoldus merged commit 655f8c3 into main Jul 28, 2026
15 checks passed
@chrarnoldus
chrarnoldus deleted the leaderboard-provider-race-endpoint branch July 28, 2026 07:46
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