Repository navigation
feat(web): show session cost on review and session trace screens - #6886
Conversation
…creens Code review details now prefer the billing-derived session cost (getSessionUsageFromBilling) over the orchestrator-accumulated total_cost_musd, which stays 0 for v2 cloud-agent-next reviews and for failed, cancelled or interrupted runs. The admin session trace viewer renders cli_sessions_v2.total_cost_microdollars, and the v1 session shape nulls that field so v1/v2 responses stay consistent.
Code Review SummaryStatus: No Issues Found | Recommendation: Merge Executive SummaryThe incremental change (HEAD Files Reviewed (2 source files + 3 screenshot assets)
Previous Review Summary (commit e5e9754)Current summary above is authoritative. Previous snapshots are kept for context only. Previous review (commit e5e9754)Status: No Issues Found | Recommendation: Merge Executive SummaryVerified the billing-derived Files Reviewed (5 files)
Reviewed by deepseek-v4.1-flash · Input: 0 · Output: 0 · Cached: 0 Review guidance: REVIEW.md from base branch |
Both cost rows now use the shared formatSessionCost/isRenderableSessionCost helpers from the cloud agent session UI, so the value is shown to the cent instead of four decimals, and the row is hidden below half a cent rather than showing $0.00. Screenshots refreshed without the source-survey popup.
Summary
Session cost was not visible where it matters. The code review details screen only showed
review.total_cost_musd, which stays0for v2 (cloud-agent-next) reviews because the orchestrator accumulates nothing from SSE, so failed / cancelled / interrupted reviews showed no cost. The admin session trace viewer never rendered cost at all.This change:
codeReviews.get): returns a newsessionCostMusdderived from the billing aggregategetSessionUsageFromBilling(...)that the router already computes for token usage (sumsmicrodollar_usage.costjoined viamicrodollar_usage_metadata.session_id, bounded by the review's created/completed times).CodeReviewDetailClientprefers it and falls back toreview.total_cost_musd.cli_sessions_v2.total_cost_microdollarsas a Cost row.total_cost_microdollars(v1cli_sessionshas no cost column) so the v1/v2 response shape stays consistent.Both screens render the value through the existing
formatSessionCosthelper (the same one the cloud agent session UI uses), so the cost is shown to the cent ($12.35) rather than four decimals, and the row is hidden below half a cent (isRenderableSessionCost) instead of showing$0.00.Note: the completion status route already copies the billing cost into
total_cost_musdon success, so the visible gain is mainly failed / cancelled / interrupted reviews and cases where that copy did not happen.Verification
Manually tested on the local dev stack (this worktree's nextjs on port 7700 and its own Postgres), against seeded rows only — no production data.
/admin/session-traces?sessionId=ses_...: showsCost: $12.35for a v2 session withtotal_cost_microdollars = 12345678./code-reviews/<id>: showsCost $4.32for a completed review whosetotal_cost_musd = 0and whose only cost is a billing row (microdollar_usage.cost = 4321000). This exercises the billing path, not the fallback.cli_session_idandtotal_cost_musd = 999000showsCost $1.00.apps/web):typecheckexit 0;oxlint0 warnings / 0 errors on the changed files; jestcode-reviews-router.test.ts+admin-session-traces.test.ts115/115 passed.Visual Changes
total_cost_musd = 0Fallback (no linked session, cost from
review.total_cost_musd):Reviewer Notes
sessionCostMusdis not role-gated, but it exposes no raw ledger identifiers, and the pre-existing Cost row already renderedreview.total_cost_musd.listForOrganizationdeliberately keeps cost visible to non-admin members.formatSessionCost/isRenderableSessionCost, shared with the cloud agent session UI, so the cent rounding and the sub-half-cent cutoff stay consistent with the rest of the product.review.total_cost_musd = 0). Not covered by unit tests:sessionCostMusd === nullwhen there are no billing rows, and the client-side fallback (both verified manually above).