Skip to content

feat(ui): show provider costs in context popover#100379

Merged
steipete merged 2 commits into
mainfrom
codex/context-usage-cost
Jul 5, 2026
Merged

feat(ui): show provider costs in context popover#100379
steipete merged 2 commits into
mainfrom
codex/context-usage-cost

Conversation

@steipete

@steipete steipete commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

What Problem This Solves

The chat context popover shows current context and latest-run token usage, but omits estimated run cost and the provider's available cost breakdown.

Related: #100264

Why This Change Was Made

This keeps the existing optional estimatedCostUsd session field as the latest-run total, preserves provider cost components through chat-history projection, and shows the latest completed provider response's input, output, cache-read, and cache-write costs when present. Provider and concrete responseModel identify that response; requested model and session metadata remain fallbacks. A newer unanswered user message suppresses stale provider costs. No Gateway protocol or config change.

User Impact

Users can see estimated run cost beside token usage and, when available, understand the provider-reported cost composition. Sessions and providers without those values continue to omit the cost rows rather than inventing data.

Evidence

Before

before

After

after

Visual-proof details and exact capture provenance.

  • Blacksmith Testbox via Crabbox: tbx_01kwskdnwc3af7w2dngkzkyd1q (jade-crayfish).
  • Exact-head focused Gateway/UI tests: 104 Gateway assertions and 8 UI assertions passed.
  • Exact-head browser E2E: ui/src/e2e/chat-flow.e2e.test.ts, 21 passed.
  • Exact-head pnpm ui:i18n:check: 20 locales clean, zero fallbacks.
  • Exact-head pnpm ui:build: passed.
  • Broad pnpm check:changed, docs MDX/link checks, focused tests, browser E2E, i18n, and UI build also passed before the current-main rebase.
  • Fresh autoreview: concrete-response-model finding fixed; no accepted/actionable findings remain. The repeated changelog suggestion was rejected because this repository keeps normal PR changelog generation release-owned.

AI-assisted implementation and review.

@openclaw-barnacle openclaw-barnacle Bot added app: web-ui App: web-ui size: M maintainer Maintainer-authored PR labels Jul 5, 2026
@clawsweeper

clawsweeper Bot commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed July 5, 2026, 1:42 PM ET / 17:42 UTC.

Summary
This branch adds estimated run cost and provider cost breakdown rendering to the chat context popover, preserves cost breakdown fields in Gateway chat-history projection, and updates docs, tests, and generated UI i18n.

PR surface: Source +161, Tests +84, Docs 0. Total +245 across 66 files.

Reproducibility: not applicable. as a feature PR rather than a bug report. Source inspection confirms current main has the Gateway cost field but the Control UI popover does not render it yet.

Review metrics: none identified.

Stored data model
Persistent data-model change detected: persistent cache schema: ui/src/i18n/.i18n/de.tm.jsonl, persistent cache schema: ui/src/i18n/.i18n/fa.tm.jsonl, persistent cache schema: ui/src/i18n/.i18n/hi.tm.jsonl, persistent cache schema: ui/src/i18n/.i18n/id.tm.jsonl, persistent cache schema: ui/src/i18n/.i18n/it.tm.jsonl, persistent cache schema: ui/src/i18n/.i18n/ja-JP.tm.jsonl, and 12 more. Confirm migration or upgrade compatibility proof before merge.

Merge readiness
Overall: 🐚 platinum hermit
Proof: 🦞 diamond lobster ✨ media proof bonus
Patch quality: 🐚 platinum hermit
Result: ready for maintainer review.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • none.

Next step before merge

  • No repair lane is needed because the prior changelog blocker is gone, no discrete code finding remains, and the remaining action is normal maintainer review and merge gating.

Security
Cleared: The diff touches UI rendering/types/tests/generated i18n, docs, and additive Gateway chat-history projection only; no concrete security or supply-chain concern was found.

Review details

Best possible solution:

Land the focused UI and Gateway display path after normal maintainer approval and required checks, keeping the existing context popover as the owner for session cost visibility.

Do we have a high-confidence way to reproduce the issue?

Not applicable as a feature PR rather than a bug report. Source inspection confirms current main has the Gateway cost field but the Control UI popover does not render it yet.

Is this the best way to solve the issue?

Yes. The existing context popover is the right owner boundary for showing the already-exposed session cost, and the provider-cost breakdown is additive with focused UI, Gateway projection, docs, and test coverage.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 35272d01b5dd.

Label changes

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient. The PR comment includes inspected before/after screenshots showing the after-fix Control UI popover with Est. cost and provider cost breakdown visible.
  • add proof: 📸 screenshot: Contributor real behavior proof includes screenshot evidence. The PR comment includes inspected before/after screenshots showing the after-fix Control UI popover with Est. cost and provider cost breakdown visible.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit. Replaced prior rating: 🦪 silver shellfish.
  • remove rating: 🦪 silver shellfish: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.

Label justifications:

  • P2: This is a normal-priority Control UI feature with limited blast radius and no urgent runtime regression or security signal.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit. Replaced prior rating: 🦪 silver shellfish.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Sufficient (screenshot): The PR comment includes inspected before/after screenshots showing the after-fix Control UI popover with Est. cost and provider cost breakdown visible.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR comment includes inspected before/after screenshots showing the after-fix Control UI popover with Est. cost and provider cost breakdown visible.
  • proof: 📸 screenshot: Contributor real behavior proof includes screenshot evidence. The PR comment includes inspected before/after screenshots showing the after-fix Control UI popover with Est. cost and provider cost breakdown visible.
Evidence reviewed

PR surface:

Source +161, Tests +84, Docs 0. Total +245 across 66 files.

View PR surface stats
Area Files Added Removed Net
Source 62 284 123 +161
Tests 3 90 6 +84
Docs 1 1 1 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 66 375 130 +245

What I checked:

  • Repository policy read and applied: Root AGENTS.md plus scoped ui, gateway, and docs guides were read; the relevant guidance affected the review through protected-label handling, generated i18n treatment, and docs/Gateway review scope. (AGENTS.md:23, 35272d01b5dd)
  • Current main exposes backend cost data: Current main already includes estimatedCostUsd in the Gateway session event payload, so this PR consumes an existing backend field rather than adding a new protocol source. (src/gateway/session-event-payload.ts:59, 35272d01b5dd)
  • Current main still has the UI gap: The Control UI session row type on current main does not include estimatedCostUsd, and the existing context popover only renders input/output usage, so the central UI change remains necessary. (ui/src/api/types.ts:499, 35272d01b5dd)
  • PR renders validated cost fields: At the PR head, the context notice accepts finite non-negative estimatedCostUsd values, renders the Est. cost stat, and passes chat messages through for provider cost breakdown display. (ui/src/pages/chat/components/chat-composer.ts:1308, 50b62df91c45)
  • Gateway projection preserves provider cost breakdown: The PR head broadens chat-display cost sanitization from total-only to input, output, cacheRead, cacheWrite, and total so the UI can display the reported breakdown. (src/gateway/chat-display-projection.ts:401, 50b62df91c45)
  • Focused tests cover the visible behavior: The PR head mocked browser E2E fixture includes estimatedCostUsd and cost breakdown data, then asserts the popover contains Est. cost and individual provider cost values. (ui/src/e2e/chat-flow.e2e.test.ts:254, 50b62df91c45)

Likely related people:

  • steipete: Authored the recent context-popover work, current-main context notice implementation, and this follow-up extends the same Control UI surface. (role: recent area contributor; confidence: high; commits: ba821e7220ff, f607ba0691b2, db96218c0562; files: ui/src/pages/chat/components/chat-composer.ts, ui/src/styles/chat/layout.css, ui/src/pages/chat/chat-composer.test.ts)
  • MrMiaigi: Authored earlier merged work around estimatedCostUsd session-cost snapshot semantics, which is the backend field this UI change exposes. (role: cost behavior contributor; confidence: medium; commits: 8e1339314cec, 9efd2d10e7f2; files: src/agents/command/session-store.ts, src/auto-reply/reply/session-usage.ts, src/cron/isolated-agent/run.ts)
  • gumadeiras: Authored the merged Gateway startup/runtime refactor that appears in the recent history for Gateway surfaces adjacent to chat display projection. (role: gateway adjacent contributor; confidence: low; commits: 8de63ca26825; files: src/gateway/chat-display-projection.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

How this review workflow works
  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.
Review history (1 earlier review cycle)
  • reviewed 2026-07-05T16:33:12.149Z sha 5c1ba3f :: needs real behavior proof before merge. :: [P2] Remove the release-owned changelog entry

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: df2b217b76

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread CHANGELOG.md Outdated

### Changes

- **Control UI context cost:** show the current run's estimated USD cost in the chat context popover when the Gateway exposes it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Remove the manual changelog entry

The root AGENTS.md Docs / Changelog rule says CHANGELOG.md is release-only and should not be edited for normal PRs or direct fixes because release generation owns these entries. This feature already carries release-note context in the commit message, so keeping this manual Unreleased line creates release-generation churn or duplicate/stale notes when the release changelog is regenerated.

Useful? React with 👍 / 👎.

@steipete
steipete force-pushed the codex/context-usage-cost branch from df2b217 to 5c1ba3f Compare July 5, 2026 16:27
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal backlog priority with limited blast radius. labels Jul 5, 2026
@steipete steipete self-assigned this Jul 5, 2026
@steipete
steipete force-pushed the codex/context-usage-cost branch from 5c1ba3f to 50b62df Compare July 5, 2026 17:36
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime size: L and removed size: M labels Jul 5, 2026
@steipete

steipete commented Jul 5, 2026

Copy link
Copy Markdown
Contributor Author

Before

before

After

after

Visual proof: Chromium at 1280×900 with a deterministic public fixture. The after state shows the estimated run total plus distinct input, output, cache-read, and cache-write provider costs, provider, and concrete response model. The complete popover remains in view and dismisses with Escape.

Before capture used the original PR base e62cf76bd50f; the relevant base popover is unchanged after the current-main rebase. Current exact-head unit, browser E2E, i18n, and production-build proof passed at 50b62df91c4 on Blacksmith Testbox tbx_01kwskdnwc3af7w2dngkzkyd1q (jade-crayfish).

@steipete steipete changed the title feat(ui): show estimated run cost in context popover feat(ui): show provider costs in context popover Jul 5, 2026
@steipete

steipete commented Jul 5, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

@steipete

steipete commented Jul 5, 2026

Copy link
Copy Markdown
Contributor Author

Land-ready at 50b62df91c45a074042595adf184fc7c0e3ce2e8.

  • Exact-head hosted CI: run 28749206382, success.
  • Blacksmith Testbox: tbx_01kwskdnwc3af7w2dngkzkyd1q (jade-crayfish).
  • corepack pnpm test ui/src/pages/chat/chat-composer.test.ts src/gateway/server.chat.gateway-server-chat-b.test.ts: 104 Gateway + 8 UI assertions passed.
  • corepack pnpm test:ui:e2e ui/src/e2e/chat-flow.e2e.test.ts: 21 passed.
  • corepack pnpm ui:i18n:check: 20 locales clean, zero fallbacks.
  • corepack pnpm ui:build: passed.
  • OPENCLAW_TESTBOX=1 scripts/pr prepare-run 100379: exact-head hosted gates passed.
  • Before/after visual proof is embedded in the PR body.

Known proof gaps: none.

@steipete
steipete merged commit 8a18744 into main Jul 5, 2026
133 of 139 checks passed
@steipete
steipete deleted the codex/context-usage-cost branch July 5, 2026 17:49
@steipete

steipete commented Jul 5, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 6, 2026
* feat(ui): show estimated run cost

* feat(ui): show provider cost breakdown
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 docs Improvements or additions to documentation gateway Gateway runtime maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: L status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant