openclaw - ✅(Solved) Fix Bug: Cost Display Precision - Cached tokens show $0.00 instead of actual cost [4 pull requests, 2 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#50083Fetched 2026-04-08 00:59:17
View on GitHub
Comments
2
Participants
2
Timeline
9
Reactions
0
Timeline (top)
cross-referenced ×4referenced ×3commented ×2

Fix Action

Fixed

PR fix notes

PR #50104: fix(ui): Preserve small cached token costs display precision (#50083)

Description (problem / solution / changelog)

Summary

This PR fixes a UI formatting bug where very small non-zero usage costs (common with Bedrock prompt caching discounts) were rounded to $0.00, making cached tokens appear free even when they still incur reduced cost.

Link: https://github.com/openclaw/openclaw/issues/50083

Root Cause

The Usage dashboard cost formatter used fixed 2-decimal rounding (toFixed(2)), which turns values like 0.004 into 0.00.

Changes

  • Updated the UI cost formatter in ui/src/ui/views/usage-metrics.ts:
    • When callers do not pass an explicit decimals argument, we now render with:
      • $0.00 for 0
      • toFixed(4) for non-zero costs < 0.01
      • toFixed(2) for all other costs
    • If decimals is provided explicitly (e.g. formatCost(x, 4)), it preserves the existing precision behavior.

Behavior Changes (User Impact)

  • Usage dashboard costs no longer display as $0.00 for small non-zero cached usage.
  • Small costs now show the correct magnitude (e.g. $0.0040, $0.0050, etc.).

Tests

  • Added ui/src/ui/views/usage-metrics.test.ts
  • Verified locally:
    • pnpm test -- ui/src/ui/views/usage-metrics.test.ts

Files Changed

  • ui/src/ui/views/usage-metrics.ts
  • ui/src/ui/views/usage-metrics.test.ts

Checklist

  • Unit tests added for the formatting regression
  • Verified tests pass for the targeted suite
  • Kept the change scoped to the cost display/formatter layer

Changed files

  • ui/src/ui/views/usage-metrics.test.ts (added, +28/-0)
  • ui/src/ui/views/usage-metrics.ts (modified, +7/-2)

PR #50108: fix(ui): preserve sub-cent usage costs in dashboard

Description (problem / solution / changelog)

## Summary

  • Problem: the Usage dashboard formatted costs with a local toFixed(2) helper, so sub-cent cached token costs such as $0.0047 were displayed as $0.00.
  • Why it matters: this makes Bedrock cache-hit usage look free when it is actually discounted, which is misleading for cost tracking.
  • What changed: default cost formatting in usage-metrics.ts now delegates to the shared UI formatter for dynamic precision, while explicit precision overrides remain intact for derived metrics.
  • What did NOT change (scope boundary): no backend aggregation or provider billing logic changed in this PR; this is a UI formatting fix plus regression coverage only.

Change Type (select all)

  • Bug fix

Scope (select all touched areas)

  • UI / DX

Linked Issue/PR

  • Closes #50083

User-visible / Behavior Changes

  • Usage dashboard costs below one cent now preserve sub-cent precision instead of rounding to $0.00.

Security Impact (required)

  • New permissions/capabilities? No
  • Secrets/tokens handling changed? No
  • New/changed network calls? No
  • Command/tool execution surface changed? No
  • Data access scope changed? No
  • If any Yes, explain risk + mitigation:

Repro + Verification

Environment

  • OS: Windows 11
  • Runtime/container: local workspace
  • Model/provider: Usage dashboard / Bedrock cache-hit cost display path
  • Integration/channel (if any): Control UI Usage dashboard
  • Relevant config (redacted): None

Steps

  1. Open the Usage dashboard with usage totals that include sub-cent cache-hit costs.
  2. Render the cost through usage-metrics.ts default formatting.
  3. Observe the displayed cost label.

Expected

  • Costs like 0.0047 render as $0.0047 instead of $0.00.
  • Explicit precision overrides such as formatCost(value, 4) continue to work.

Actual

  • Covered by the new regression tests.

Evidence

  • Failing test/log before + passing after
  • Trace/log snippets
  • Screenshot/recording
  • Perf numbers (if relevant)

Targeted local verification: pnpm --dir ui test -- src/ui/views/usage-render-details.test.ts

Result:

  • Test Files 1 passed
  • Tests 12 passed

Human Verification (required)

What you personally verified (not just CI), and how:

  • Verified scenarios: sub-cent costs preserve precision; costs below one dollar keep three decimals by default; explicit precision overrides still render fixed decimals.
  • Edge cases checked: NaN falls back to $0.00.
  • What you did not verify: manual browser verification against a live Bedrock-backed dashboard; full pnpm build && pnpm check && pnpm test suite.

Review Conversations

  • I replied to or resolved every bot review conversation I addressed in this PR.
  • I left unresolved only the conversations that still need reviewer or maintainer judgment.

Compatibility / Migration

  • Backward compatible? Yes
  • Config/env changes? No
  • Migration needed? No
  • If yes, exact upgrade steps:

Failure Recovery (if this breaks)

  • How to disable/revert this change quickly: revert this PR
  • Files/config to restore: ui/src/ui/views/usage-metrics.ts, ui/src/ui/views/usage-render-details.test.ts
  • Known bad symptoms reviewers should watch for: only Usage dashboard cost labels regressing back to two-decimal rounding

Risks and Mitigations

  • Risk: callers that intentionally relied on two-decimal default formatting in usage-metrics.ts could now render more precision for values below $1.
    • Mitigation: explicit precision overrides are preserved, and the default path now matches the shared UI cost formatter already used elsewhere.

AI-assisted: yes. I verified the change locally and understand the formatting and test coverage added here.

Changed files

  • ui/src/ui/views/usage-metrics.ts (modified, +9/-2)
  • ui/src/ui/views/usage-render-details.test.ts (modified, +27/-0)

PR #50121: fix(ui): improve cost precision for small values in usage dashboard

Description (problem / solution / changelog)

Problem

The usage dashboard's formatCost() in usage-metrics.ts used toFixed(2) for all values, rounding costs below $0.01 to $0.00. This is misleading for cached tokens on Amazon Bedrock where the actual cost is non-zero but very small (e.g. $0.004).

Note: The main formatCost in ui/format.ts already handles this correctly with dynamic precision. This was a separate copy that didn't.

Fix

Use dynamic precision matching the existing ui/format.ts logic:

  • $0.00 for zero
  • 4 decimal places for values < $0.01
  • 3 decimal places for values < $1
  • 2 decimal places otherwise
  • Explicit decimals parameter still works as before

Fixes #50083 Fixes #50082 (duplicate)

Changed files

  • ui/src/ui/views/usage-metrics.ts (modified, +14/-2)

PR #49713: Agents: wait for rate-limit retry lifecycle before ending embedded run

Description (problem / solution / changelog)

Summary

Fixes a case where an embedded agent run could end its session/lane lifecycle too early when a 429 rate-limit happens on the final model call. In that scenario, the provider SDK may perform a delayed retry, but the reply context was already torn down, causing the eventual successful response to be silently dropped.

This change keeps the embedded run alive long enough (best-effort, bounded) to let the SDK’s retry lifecycle settle, then refreshes the message snapshot so the final assistant response is delivered through the normal session path.

Refs: https://github.com/openclaw/openclaw/issues/49645

Behavior Changes

  • Embedded runner lifecycle: when the last assistant message indicates a rate-limit error, the runner waits best-effort for the SDK retry lifecycle (if available) before finalizing/unsubscribing.
  • Snapshot refresh: after the wait, the runner refreshes the message snapshot so downstream delivery/subscribers observe the final state.

Existing Functionality Check

  • Searched for existing “rate-limit retry / unsubscribe / snapshot” handling in the embedded runner
  • Verified behavior is scoped to rate-limit terminal cases and remains best-effort + time-bounded

What Changed

  • Modified src/agents/pi-embedded-runner/run/attempt.ts

    • Detects “last assistant message is a rate-limit error”
    • Waits for retry lifecycle best-effort (bounded timeout) before final snapshot + teardown
  • Updated/added tests in src/agents/pi-embedded-runner/run/attempt.spawn-workspace.test.ts

    • Adds coverage that the runner waits for the retry hook before unsubscribing when the final turn is a 429/rate-limit error

Tests

Run locally:

  • pnpm test -- src/agents/pi-embedded-runner/run/attempt.spawn-workspace.test.ts -t "rate-limit retry"
  • pnpm test -- src/agents/pi-embedded-runner/run/attempt.spawn-workspace.test.ts
  • pnpm lint src/agents/pi-embedded-runner/run/attempt.ts

Manual Testing

  • Reproduced the “final 429 then delayed retry” sequence by simulating a rate-limit error on the last call and validating the run does not unsubscribe early, and the eventual successful response is observable via the normal embedded session lifecycle.

Files Changed

  • src/agents/pi-embedded-runner/run/attempt.ts
  • src/agents/pi-embedded-runner/run/attempt.spawn-workspace.test.ts

Checklist

  • PR scoped to one bugfix
  • Tests added/updated for the regression
  • Lint/format/typecheck compatible with repo conventions

Changed files

  • src/agents/pi-embedded-runner/run/attempt.spawn-workspace.test.ts (modified, +102/-0)
  • src/agents/pi-embedded-runner/run/attempt.ts (modified, +63/-0)
RAW_BUFFERClick to expand / collapse

Problem

When using Amazon Bedrock with 100% cache hit rate, tokens that cost < $0.01 display as $0.00 instead of showing the actual cost (e.g., $0.004 or $0.005).

This creates a misleading impression that cached tokens are completely free, when they actually have a reduced cost (90% discount on input tokens).

Expected Behavior

  • Display actual cost with 3-4 decimal places: $0.004, $0.005, etc.
  • OR show $0.00 with a tooltip/note indicating 'cached: saved $X.XX'
  • OR add a cache savings indicator in the dashboard

Actual Behavior

Shows $0.00 (appears free but isn't)

Technical Details

Location: OpenClaw distributed code

  • File: dist/session-cost-usage-B7YSslo_.js
  • Function: Cost formatter uses toFixed(2) rounding for all values

Steps to Reproduce

  1. Configure Amazon Bedrock with prompt caching enabled
  2. Make API calls that result in 100% cache hit rate
  3. Navigate to OpenClaw Control UI → Usage dashboard
  4. Observe models with low costs (e.g., Claude Haiku, Nova Lite)
  5. Notice they show $0.00 even though tokens were consumed

Affected Models

  • eu.anthropic.claude-haiku-4-5-20251001-v1:0 (4.7M tokens = $0.004, shows $0.00)
  • eu.amazon.nova-lite-v1:0
  • eu.amazon.nova-micro-v1:0

Real-World Impact

  • Dashboard appears to show free usage when it's actually reduced-cost
  • Cost tracking is inaccurate for small transactions
  • Billing transparency is compromised

Environment

  • OpenClaw Version: 2026.3.13
  • AWS Bedrock: eu-west-1
  • Prompt Caching: Enabled
  • Cache Hit Rate: 100%

extent analysis

Fix Plan

To address the issue of displaying actual costs with 3-4 decimal places for cached tokens, we will modify the cost formatter function in the dist/session-cost-usage-B7YSslo_.js file.

Step-by-Step Solution:

  1. Update the toFixed method: Change toFixed(2) to toFixed(4) to display costs with 4 decimal places.
  2. Add a conditional statement: Check if the cost is less than $0.01 and display a tooltip or note indicating the actual cost and savings.

Example Code:

// Before
cost = cost.toFixed(2);

// After
cost = cost.toFixed(4);
if (cost < 0.01) {
  // Display tooltip or note
  cost += ` (cached: saved $${(originalCost - cost).toFixed(4)})`;
}

Alternatively, you can add a cache savings indicator in the dashboard:

// Display cache savings indicator
if (cacheHitRate === 100) {
  cost += ` (cached: $${cost} - saved $${originalCost - cost})`;
}

Verification

To verify the fix, follow these steps:

  • Configure Amazon Bedrock with prompt caching enabled
  • Make API calls that result in 100% cache hit rate
  • Navigate to OpenClaw Control UI → Usage dashboard
  • Observe models with low costs (e.g., Claude Haiku, Nova Lite)
  • Verify that the costs are displayed with 3-4 decimal places and the tooltip or note is shown for cached tokens

Extra Tips

  • Consider adding a configuration option to customize the number of decimal places displayed for costs.
  • Ensure that the cost formatter function is correctly handling edge cases, such as costs greater than $1000 or negative costs.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING