Repository navigation
SWF(bug): count model aliases once per receipt in Stats and Insights - #45
Conversation
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
… carry main's future-dated-runs entry into it)
00db281 to
468e0ed
Compare
|
Capy couldn't review this pull request because Cojo's workspace is out of credits, add credits or enable auto-reload to resume automatic reviews. The code reviews included with your plan this billing period are used up, so reviews are paid from your credits until the plan resets. A Low or Medium effort review counts as 1 included review, and a High effort review counts as 2. |
…l-alias-run-count Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> # Conflicts: # CHANGELOG.md
Summary
A run that used two IDs for the same model (e.g.
claude-sonnet-4-5-20250929andclaude-sonnet-4-5) was counted as 2 runs for that model in Stats and Insights, so Insights showed cost per run at half the real figure ($0.45 instead of $0.90).Root cause:
Database.stats(server/db.py) and_models_block(server/insights.py) map each raw model bucket to its display label withfriendly_modelinside the bucket loop and bumpruns/priced_runs/ quality samples once per bucket. Two aliases in one receipt collapse to one label, so that label's counters are bumped twice. Tokens and dollars add up correctly; per-receipt counts do not.Fix: one shared helper,
receipt_models(models, partial)inserver/model_rollup.py, merges same-label buckets per receipt (summing tokens and cost) before either rollup counts anything. Both consumers now iterate its output, so each receipt counts once per label.partial(cost is a lower bound,≥on the dashboard). A label where every alias is unpriced stays unpriced, as before.renderModelsonly displays API values; compliance exports callinsights.computeand get the fix; CSV export and CLIstatskey by raw model ID, so they are not affected.Evidence
Live local team server, one receipt POSTed (201) with buckets Sonnet 4.5 dated (1,000 tok, $0.60) + undated alias (500 tok, $0.30), total $0.90:
/api/stats?days=30Sonnet 4.5runs: 2,priced_runs: 2,cost_usd: 0.9runs: 1,priced_runs: 1,cost_usd: 0.9/api/insights?days=30Sonnet 4.5runs: 2,priced_runs: 2,cost_per_run: 0.45runs: 1,priced_runs: 1,cost_per_run: 0.9New tests in
tests/test_server.py(both APIs, fully priced and partly priced aliases, quality weighting across receipts, empty and malformed buckets) fail on main:and pass on this branch:
Full suite: main
4137 passed, 41 skipped; this branch4143 passed, 41 skipped(the 6 new tests).Try it:
Not tested: the 41 skipped tests (platform-specific); browser check was Chromium on Linux only.
Implemented in session Count model aliases once per receipt in Insights
Review with Devin · Open in Devin Desktop