Skip to content

feat(platform): reconstruct real history for /me/ai-usage trend chart - #160

Merged
clickmatos merged 1 commit into
mainfrom
feat/personal-ai-usage-history
Aug 13, 2026
Merged

feat(platform): reconstruct real history for /me/ai-usage trend chart#160
clickmatos merged 1 commit into
mainfrom
feat/personal-ai-usage-history

Conversation

@clickmatos

Copy link
Copy Markdown
Contributor

Summary

/me/ai-usage doesn't keep history — the trend chart is built only from
the newest metrics row per repo, so it's bounded by that single push's
own analysis window (commonly ~90d via DEFAULT_WINDOW_DAYS) with zero
accumulation across pushes. A user active for months sees the chart reset
every time a new push overwrites the "latest" row.

  • getPersonalAIUsage now fetches up to HISTORY_DEPTH (12) rows per
    repo instead of just the newest, sized by repos.length * HISTORY_DEPTH.
  • The per-repo summary table still shows the newest row only (current
    snapshot, unchanged behavior).
  • The trend chart is rebuilt from each repo's full fetched history,
    deduping per-repo-per-week (newest push wins) before merging into the
    existing cross-repo weekly aggregate — same "query N rows per entity,
    newest-first" pattern already used in getRepoTimeSeries and the org
    dashboard's computePreviousPayloads (feat(platform): wire org-level trend deltas for Delivery Quality, PR Health, Cycle Time #153).
  • Extracted the per-week aggregation into a pure buildUsageTrend() so
    it's unit-testable without a DB (no mocking convention exists in this
    codebase — see platform/CLAUDE.md), mirroring how isHyperEngineer
    was pulled out of org-summary.ts.

usage_rollup (vendor AI telemetry) was ruled out as an alternative data
source — it discards individual identity by design (privacy ADR), so it
structurally can't answer a personal question.

Test plan

  • npx tsc --noEmit — clean
  • npm run lint — clean (no new warnings)
  • npm run test — 267/267 passing, including 4 new tests for
    buildUsageTrend (multi-row merge, overlap-dedup newest-wins,
    cross-repo merge, no-AI-data → null)
  • Confirmed the new tests fail against pre-fix code
    (buildUsageTrend doesn't exist without this change) and pass with it
  • Manual check in a tenant with >1 historical push per repo that the
    chart now shows a longer timeline than before

🤖 Generated with Claude Code

getPersonalAIUsage kept only the newest metrics row per repo, so the
trend chart was bounded by that single push's own analysis window
(commonly ~90d via DEFAULT_WINDOW_DAYS) with no accumulation across
pushes over time — the exact "doesn't keep history" gap flagged for
this page. Fetch up to HISTORY_DEPTH (12) rows per repo instead of one,
and rebuild the weekly trend from each repo's full fetched history,
deduping per-repo-per-week with the newest push winning when pushes'
analysis windows overlap.

The per-week aggregation is extracted into a pure buildUsageTrend()
so it's unit-testable without a DB, consistent with how isHyperEngineer
was pulled out of org-summary.ts.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@vercel

vercel Bot commented Aug 13, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
clickbus-iris Ready Ready Preview Aug 13, 2026 9:04pm

Request Review

@clickmatos
clickmatos merged commit 05ba679 into main Aug 13, 2026
5 checks passed
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.

1 participant