Skip to content

fix(ui): chat cost popover hides the session's total spend - #198261

Merged
obviyus merged 1 commit into
mainfrom
fix/ui-session-cost
Nov 13, 2026
Merged

obviyus merged 1 commit into
mainfrom
fix/ui-session-cost

Conversation

@obviyus

@obviyus obviyus commented Nov 13, 2026

Copy link
Copy Markdown
Collaborator

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 d5d77e1): 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).

Before: latest run only

After: latest run plus session total

After the next real run: both rows refreshed

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]>
@clawsweeper

clawsweeper Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@obviyus
obviyus marked this pull request as ready for review November 13, 2026 12:36
@obviyus
obviyus enabled auto-merge (squash) November 13, 2026 12:44
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 13, 2026
@clawsweeper

clawsweeper Bot commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This 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.

  • Before: The popover shows only Latest run Cost $0.0025.
  • After: It also shows Session total Cost $0.027, then updates the total to $0.041 after another turn.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Useful and supported by live visual proof, with one non-blocking layout defect and unresolved exact-head CI attribution.
Proof confidence 🦞 diamond lobster (5/6) ✨ media proof bonus Sufficient (screenshot): Inspected before/after screenshots and the recorded real-Gateway/provider scenario exercise the composer popover, distinct lifetime totals, and refresh after a subsequent real turn.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Product

Kind: Feature · Worth it: Yes · Fix scope: Complete
User problem: Users inspecting a long cached conversation cannot see its cumulative spend beside the inexpensive latest run.
Reason: The maintainer-authored direction adds useful accounting context through an existing read without new settings or changes to billing suppression.

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
Reviewed head: 4981a5f1cefc25e34429b64cf43a940963b60fc5

Before merge

None.

Findings

  • [P3] Reserve space for the total row while usage loads — ui/src/pages/chat/components/chat-context-breakdown.tsx:105

Tests

  • Missing end-to-end proof: The submitted regression-test results do not show the added cases failing against the base.
Agent review details

How this fits together

The 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]
Loading

Technical review

Best 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:

  • [P3] Reserve space for the total row while usage loads — ui/src/pages/chat/components/chat-context-breakdown.tsx:105
    On the first popover opening with a delayed sessions.usage response, cost is initially null, so this condition renders no row; accepting the response then inserts a row with a 26px minimum height. The popover grows after appearing, contrary to ui/AGENTS.md's layout-stability contract. Keep a same-height loading slot until the total is available.
    Confidence: 0.96

Overall correctness: patch is correct
Overall confidence: 0.9

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against f978e54df2d8.

Provenance checked

  • Shared context-report read and date window changes intended behavior with a stated reason (ff63be5: Move context inspection into the composer while sharing one scoped read and retaining existing cost presentation.)
  • Canonical usage request builder keeps the original intent (6eaf1b8: Consolidate session usage requests under one canonical owner; the new query alternative preserves existing dated callers.)
  • Lazy context presentation keeps the original intent (a36d048: Keep dormant Chat presentation outside the initial evaluation path.)
  • Subscription dollar suppression keeps the original intent (999ab3e: Keep subscription classification independent of account-specific quota availability so estimates do not appear as actual subscription spend.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

  • Pinned change and current-main gap: The introduced diff adds whole-history usage and the total row; fetched main still requests today's window and has no cost field in the context snapshot. (ui/src/lib/session-context-report.ts:116, 4981a5f1cefc)
  • Existing whole-history contract: The Gateway already accepts range all, includes untimestamped history, and returns instance-scoped usage with computing and missing-price information. (src/gateway/server-methods/usage-date-range.ts:308, 4981a5f1cefc)
  • Inspected visual proof: All three downloaded screenshots were inspected: latest-run-only before, separate $0.027 total after, and updated $0.013 latest-run/$0.041 total after another turn; the PR identifies an isolated real Gateway and provider. (4981a5f1cefc)
  • Exact-head CI is failing: The UI failure reports a 375-versus-374-pixel overflow in the untouched chat-divider browser test; changed lint also failed, but its annotations contain only unrelated-file warnings and a generic exit failure. Job-log retrieval was blocked by the proxy's Azure-host allowlist, so neither failure is conclusively attributed. (4981a5f1cefc)
  • Original presentation and billing intent: feat(ui): move context breakdown into the composer popover #179225 established the shared context read and latest-run presentation; fix(ui): match quota summaries to the selected account #192418 deliberately preserved subscription cost suppression, which this PR retains. (ui/src/pages/chat/components/chat-composer-context-panel.tsx:141, 4981a5f1cefc)
  • Review policy and inspection limits: Read the complete root and UI AGENTS files, relevant Solid/test guidance, and simplification steps; no nested UI AGENTS files or maintainer-notes directory were present. The installed Solid cheatsheet was absent, and older-history reads encountered unavailable objects; current source and scoped history supplied the relevant contracts. (ui/AGENTS.md, 4981a5f1cefc)

PR surface

Source +68, Tests +106. Total +174 across 7 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 5 77 9 +68
Tests 2 106 0 +106
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 7 183 9 +174

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Labels

Label changes:

  • add P2: Session-spend visibility is a useful, limited-scope improvement without an urgent runtime or billing-operation failure.
  • add proof: sufficient: Contributor real behavior proof is sufficient.
  • add proof: 📸 screenshot: Contributor real behavior proof includes screenshot evidence.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦞 diamond lobster and patch quality is 🦐 gold shrimp.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P2: Session-spend visibility is a useful, limited-scope improvement without an urgent runtime or billing-operation failure.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦞 diamond lobster and patch quality is 🦐 gold shrimp.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.
  • proof: 📸 screenshot: Contributor real behavior proof includes screenshot evidence.

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Have the CI owner classify the failed lint and UI checks before landing.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed November 13, 2026, 7:54 AM ET / 12:54 UTC.

@obviyus

obviyus commented Nov 13, 2026

Copy link
Copy Markdown
Collaborator Author

Maintainer override: both failing jobs are unrelated to this PR, which only changes the chat context popover, its usage read and its tests.

  • check-lint-core-4 (job): every annotation is max-lines on files this PR does not touch (ui/src/app/app-shell-gateway.ts, ui/src/components/board/board-widget-frame.tsx, ui/src/pages/chat/chat-pane-session-events.test.ts, ui/src/pages/sessions/sessions-page.test.ts, ui/src/pages/activity/activity-page.test.ts, ui/src/e2e/settings-layout.e2e.test.ts, src/auto-reply/reply/session-event-handoff.ts). They are already over the limit on the base commit (for example app-shell-gateway.ts is 759 lines at d5d77e1). The ui lane's changed-lint scope pulls them in; main's push run lints a different scope and passes.
  • checks-ui (2/3) (job): chat-divider.browser.test.tsx asserts a notice row's scrollWidth <= clientWidth and got 375 vs 374. The test mounts ChatNotice alone and does not render the popover or use the changed code. It passes locally on this exact head (5/5).

Exact-head proof: real Gateway E2E with openai/gpt-5.4-mini, before and after screenshots in the PR body, and ClawSweeper ready on 4981a5f.

@obviyus
obviyus disabled auto-merge November 13, 2026 12:56
@obviyus
obviyus merged commit eb1a592 into main Nov 13, 2026
159 of 163 checks passed
@obviyus
obviyus deleted the fix/ui-session-cost branch November 13, 2026 12:56
@obviyus

obviyus commented Nov 13, 2026

Copy link
Copy Markdown
Collaborator Author

Landed in eb1a592.

  • Bug: the context popover showed only the latest run's cost, so a long cached session looked like it had cost cents.
  • Fix: a Session total row now shows the lifetime cost, read from the same sessions.usage request as the context breakdown (now over the whole history). Lower bounds show as ≥ and usage with no price shows as Unpriced.
  • Proof: real Gateway E2E with gpt-5.4-mini on the same session, before and after this change, and the total updated live after a new run. Browser tests with a simulated Gateway and unit tests also pass. ClawSweeper was ready on this head.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 14, 2026
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app: web-ui App: web-ui P2 Normal backlog priority with limited blast radius. proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant