Repository navigation
fix(ui): chat cost popover hides the session's total spend - #198261
Conversation
The composer context popover showed only the latest run's cost, which on a long cached session reads as the whole conversation costing cents. The shared sessions.usage read behind the context breakdown now covers the session's whole history, and the popover adds a Session total row from that row's lifetime cost: lower bounds render as ≥, unpriced usage as Unpriced. Co-authored-by: obviyus <[email protected]>
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. What this changesThis PR adds a lifetime session-cost row beside the latest-run cost in the chat context popover. Example: Inspect a session after three real provider turns.
Review scores
ProductKind: Feature · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep this PR open: it adds useful session-spend visibility with convincing live screenshots; no blocking code defect was found, but failed CI remains unresolved. Priority: P2 Before mergeNone. Findings
Tests
Agent review detailsHow this fits togetherThe Control UI's shared context-report owner requests session usage from the Gateway and supplies context categories and cost totals to the composer popover. flowchart LR
A[Composer popover] --> B[Shared context report]
B --> C[Session usage request]
C --> D[Gateway usage owner]
D --> E[Session usage summaries]
E --> B
B --> F[Context and session total]
Technical reviewBest possible solution: Retain the shared whole-history usage read and separate totals, reserving the total row's space during initial loading. Do we have a high-confidence way to reproduce the issue? Current-main source and the submitted before screenshot establish that the popover exposes latest-run cost without a lifetime total; no target code was executed during this review. Is this the best way to solve the issue? The implementation uses the existing Gateway accounting and shared read owner, preserves dated Usage-dashboard callers, and avoids another request or persistence model. Full review comments:
Overall correctness: patch is correct AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against f978e54df2d8. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
PR surfaceSource +68, Tests +106. Total +174 across 7 files. Added test files: 0. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. LabelsLabel changes:
Label justifications:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment Reviewed November 13, 2026, 7:54 AM ET / 12:54 UTC. |
|
Maintainer override: both failing jobs are unrelated to this PR, which only changes the chat context popover, its usage read and its tests.
Exact-head proof: real Gateway E2E with |
|
Landed in eb1a592.
|
…198261) ## What Problem This Solves Fixes: the chat context popover shows only the latest run's cost, so a long, cached session looks like it cost a few cents in total. ## User Impact User impact: the popover still shows the latest run's cost and now also shows a **Session total** row with the session's lifetime cost. If the total is still being summarized or some usage has no price, the row shows it as a lower bound (`≥ $X`). If no usage has a price, the row shows `Unpriced`. Subscription sessions still hide all dollar amounts. ## Why This Change Was Made The cost next to "Latest run" comes from the session row, which only keeps the latest run's usage. With prompt caching, one run on a 535k-token session can cost $0.12 while the whole session has cost $99. The popover already reads `sessions.usage` for this session to build the context breakdown. That read now covers the whole session history instead of only today's UTC date, and the same response supplies the lifetime total. The popover still sends one request. A side effect: sessions with no activity today now also get a context breakdown. ## Evidence **Real Gateway, real provider (`openai/gpt-5.4-mini`), same session state before and after:** - Three real turns on an isolated Gateway. The Gateway's `sessions.usage` reports $0.027168 for the session's lifetime. The latest run (`estimatedCostUsd`) was $0.0025. - **Before (`main` 05b5a58):** the popover shows `Latest run · Cost $0.0025` and no session total. - **After (this branch, same state dir):** the popover shows `Latest run · Cost $0.0025` and `Session total · Cost $0.027`. - **Live update:** with the popover open, I sent a fourth turn. The popover changed from `$0.0025 / $0.027` to `Latest run $0.013 / Session total $0.041`. The Gateway's lifetime total was $0.0406068. - On a long real session (535k context, 100% cache hit), `sessions.usage` with `range: "all"` returned a $99.14 total while the latest run showed $0.116. A read with `range: "all"` took about as long as the old single-day read. **Tests** - `ui/src/lib/session-context-report.test.ts`: maps the lifetime total, the lower-bound and unpriced states, a `sessionId` mismatch from a rotated instance, and the `range: "all"` request shape. - `ui/src/e2e/session-context-breakdown.e2e.test.ts` (mocked-Gateway browser E2E): the popover shows both rows and the total refreshes after the next run, including the `≥` state. Passes together with the existing breakdown and quota-popover browser suites (10/10). Co-authored-by: Ayaan Zaidi <[email protected]>
What Problem This Solves
Fixes: the chat context popover shows only the latest run's cost, so a long, cached session looks like it cost a few cents in total.
User Impact
User impact: the popover still shows the latest run's cost and now also shows a Session total row with the session's lifetime cost. If the total is still being summarized or some usage has no price, the row shows it as a lower bound (
≥ $X). If no usage has a price, the row showsUnpriced. Subscription sessions still hide all dollar amounts.Why This Change Was Made
The cost next to "Latest run" comes from the session row, which only keeps the latest run's usage. With prompt caching, one run on a 535k-token session can cost $0.12 while the whole session has cost $99. The popover already reads
sessions.usagefor this session to build the context breakdown. That read now covers the whole session history instead of only today's UTC date, and the same response supplies the lifetime total. The popover still sends one request. A side effect: sessions with no activity today now also get a context breakdown.Evidence
Real Gateway, real provider (
openai/gpt-5.4-mini), same session state before and after:sessions.usagereports $0.027168 for the session's lifetime. The latest run (estimatedCostUsd) was $0.0025.maind5d77e1): the popover showsLatest run · Cost $0.0025and no session total.Latest run · Cost $0.0025andSession total · Cost $0.027.$0.0025 / $0.027toLatest run $0.013 / Session total $0.041. The Gateway's lifetime total was $0.0406068.sessions.usagewithrange: "all"returned a $99.14 total while the latest run showed $0.116. A read withrange: "all"took about as long as the old single-day read.Tests
ui/src/lib/session-context-report.test.ts: maps the lifetime total, the lower-bound and unpriced states, asessionIdmismatch from a rotated instance, and therange: "all"request shape.ui/src/e2e/session-context-breakdown.e2e.test.ts(mocked-Gateway browser E2E): the popover shows both rows and the total refreshes after the next run, including the≥state. Passes together with the existing breakdown and quota-popover browser suites (10/10).