feat(platform): reconstruct real history for /me/ai-usage trend chart - #160
Merged
Conversation
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>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
/me/ai-usagedoesn't keep history — the trend chart is built only fromthe newest
metricsrow per repo, so it's bounded by that single push'sown analysis window (commonly ~90d via
DEFAULT_WINDOW_DAYS) with zeroaccumulation across pushes. A user active for months sees the chart reset
every time a new push overwrites the "latest" row.
getPersonalAIUsagenow fetches up toHISTORY_DEPTH(12) rows perrepo instead of just the newest, sized by
repos.length * HISTORY_DEPTH.snapshot, unchanged behavior).
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
getRepoTimeSeriesand the orgdashboard's
computePreviousPayloads(feat(platform): wire org-level trend deltas for Delivery Quality, PR Health, Cycle Time #153).buildUsageTrend()soit's unit-testable without a DB (no mocking convention exists in this
codebase — see
platform/CLAUDE.md), mirroring howisHyperEngineerwas pulled out of
org-summary.ts.usage_rollup(vendor AI telemetry) was ruled out as an alternative datasource — it discards individual identity by design (privacy ADR), so it
structurally can't answer a personal question.
Test plan
npx tsc --noEmit— cleannpm run lint— clean (no new warnings)npm run test— 267/267 passing, including 4 new tests forbuildUsageTrend(multi-row merge, overlap-dedup newest-wins,cross-repo merge, no-AI-data → null)
(
buildUsageTrenddoesn't exist without this change) and pass with itchart now shows a longer timeline than before
🤖 Generated with Claude Code