Skip to content

feat(ui): add comparative cost analysis#100432

Merged
steipete merged 9 commits into
mainfrom
codex/cost-analysis
Jul 5, 2026
Merged

feat(ui): add comparative cost analysis#100432
steipete merged 9 commits into
mainfrom
codex/cost-analysis

Conversation

@steipete

@steipete steipete commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

Closes #100405

AI-assisted: yes

What Problem This Solves

The Control UI Usage page showed one selected total and rich attribution, but operators still had to reload multiple presets and hover individual bars to compare recent spend or understand the chart scale.

Why This Change Was Made

This adds calendar-correct shorter cost windows derived from the daily data already loaded for the selected range, explicit daily chart scale labels, and cost-share percentages on provider/model/agent/channel rollups. It adds no request, storage, config, or protocol surface; day-filtered views deliberately omit category percentages because the backend category rollups are session-scoped rather than day-scoped.

Daily cost and session-detail buckets now share the request's UTC/browser offset through aggregation, zero-fill, cache identity, and cached-summary projection, so a remote Gateway cannot shift boundary usage into the wrong comparison day. UTC quarter-hour data remains UTC.

The product shape follows current CodexBar prior art while reusing OpenClaw's existing, richer Usage data model. The dashboard continues to describe estimated costs from available local session history, not provider invoices or lifetime spend.

User Impact

Operators can compare the selected range with Today, 7-day, 30-day, and 90-day windows at a glance, read the chart without hovering, see provider/model cost share when the data scopes match, and retain nonzero precision for sub-cent usage.

Before / after

Before — cost bars required hover to infer the scale, and comparing periods required repeated date-range reloads.

Usage cost analysis before

After — selected-range and shorter calendar windows, readable chart scale, and existing cost-type attribution in one view.

Usage cost analysis after

Evidence

  • Blacksmith Testbox through Crabbox: tbx_01kwswgnzqeazh2q1mcvfmsfd2 (coral-hermit)
  • Focused gateway/infra/UI: 94 gateway assertions, 64 infra tests, 16 UI tests, and the mocked Gateway browser E2E passed
  • Near-midnight regressions cover cached batch rebucketing and aggregate-only synchronous fallback while preserving UTC quarter-hour dates
  • Mocked Gateway browser E2E: usage-cost-analysis.e2e.test.ts passed and produced matched before/after captures
  • Broad changed gate: pnpm check:changed passed remotely, including core/core-test TSGo, complete core/UI/package lint, import-cycle, storage, loader, dependency, and runtime guards
  • Control UI i18n drift check: clean across 20 generated locale bundles
  • Docs MDX check: 691 files passed
  • Autoreview: clean at 0.97 confidence after addressing day-scope percentages, request-timezone bucketing, synchronous cache fallback, micro-cost precision, and chart baseline alignment

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation app: web-ui App: web-ui size: XL 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, 6:52 PM ET / 22:52 UTC.

Summary
The PR adds Control UI Usage comparative cost-window cards, daily chart scale labels, cost-share attribution, timezone-aligned usage aggregation/cache handling, docs, i18n, and regression coverage.

PR surface: Source +712, Tests +752, Docs +7. Total +1471 across 76 files.

Reproducibility: not applicable. this is a feature PR, not a broken existing behavior report. Source inspection confirms current main lacks the requested simultaneous cost-window cards and daily chart scale labels, while the PR proof shows the after-state UI.

Review metrics: none identified.

Stored data model
Persistent data-model change detected: persistent cache schema: src/gateway/server-methods/usage.test.ts, persistent cache schema: src/gateway/server-methods/usage.ts, persistent cache schema: src/infra/session-cost-usage.test.ts, persistent cache schema: ui/src/i18n/.i18n/ar.tm.jsonl, persistent cache schema: ui/src/i18n/.i18n/de.tm.jsonl, persistent cache schema: ui/src/i18n/.i18n/es.tm.jsonl, and 21 more. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster
Relationship: fixed_by_candidate
Canonical: #100405
Summary: This PR is the implementation candidate for the linked comparative Usage cost-window feature request.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

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

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

Risk before merge

  • [P1] The remaining blocker is maintainer product/landing acceptance for a protected maintainer-labeled feature PR, not a concrete code defect found in this review.

Maintainer options:

  1. Decide the mitigation before merge
    Land the UI-only Usage comparison after maintainer product acceptance and exact-head checks, keeping the change free of new protocol, config, and storage surfaces.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Next step before merge

  • [P2] Maintainers need to make the protected product/landing decision; there is no narrow ClawSweeper repair task on this head.

Maintainer decision needed

  • Question: Should maintainers accept and land this UI-only comparative Usage cost analysis on the current PR head once exact-head checks are green?
  • Rationale: The implementation appears sound and well-proven, but it adds a new operator-facing Usage presentation surface tied to a protected maintainer-labeled feature request, so product acceptance should remain a human decision.
  • Likely owner: steipete — This account opened the linked feature request, is assigned on the PR, and has recent Usage/provider-cost UI history plus repository product authority evidence in CONTRIBUTING.md.
  • Options:
    • Land after checks (recommended): Accept the current UI-only shape because it uses existing daily rows, addresses the prior timezone/filter review findings, and has screenshot plus mocked Gateway E2E proof.
    • Request product tweaks: Keep the PR open and ask for specific changes to card placement, covered windows, or visual/copy treatment before landing.
    • Defer the feature: Pause or close the PR if maintainers want comparative cost analysis to wait for a broader Usage dashboard redesign.

Security
Cleared: The diff touches UI, docs, gateway usage aggregation, tests, and generated i18n only; I found no new dependency, workflow, lockfile, secret, permission, or code-execution surface.

Review details

Best possible solution:

Land the UI-only Usage comparison after maintainer product acceptance and exact-head checks, keeping the change free of new protocol, config, and storage surfaces.

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

Not applicable: this is a feature PR, not a broken existing behavior report. Source inspection confirms current main lacks the requested simultaneous cost-window cards and daily chart scale labels, while the PR proof shows the after-state UI.

Is this the best way to solve the issue?

Yes, subject to product acceptance: deriving comparison windows from existing daily rows and aligning existing day-bucket semantics is the narrowest maintainable implementation path. I did not find a supported current Control UI path that already provides the side-by-side comparison.

AGENTS.md: found and applied where relevant.

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

Label changes

Label justifications:

  • P3: This is a low-risk Control UI ergonomics feature for recurring spend review, not a blocker, security issue, or regression.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (screenshot): Before/after screenshots in the PR body directly show the Usage UI change, and the body/comment include mocked Gateway browser E2E plus Testbox proof for the after behavior.
  • proof: sufficient: Contributor real behavior proof is sufficient. Before/after screenshots in the PR body directly show the Usage UI change, and the body/comment include mocked Gateway browser E2E plus Testbox proof for the after behavior.
  • proof: 📸 screenshot: Contributor real behavior proof includes screenshot evidence. Before/after screenshots in the PR body directly show the Usage UI change, and the body/comment include mocked Gateway browser E2E plus Testbox proof for the after behavior.
Evidence reviewed

PR surface:

Source +712, Tests +752, Docs +7. Total +1471 across 76 files.

View PR surface stats
Area Files Added Removed Net
Source 67 998 286 +712
Tests 8 756 4 +752
Docs 1 7 0 +7
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 76 1761 290 +1471

What I checked:

  • Live PR state: Live GitHub data shows this PR is open, non-draft, linked to [Feature]: Add comparative cost windows to Usage #100405, and labeled maintainer, app: web-ui, gateway, proof: sufficient, and status: ready for maintainer look. (892618170f5d)
  • Current main lacks the requested UI: Current main renders the compact daily chart without direct scale labels or cost-window comparison cards, so the central feature is not already implemented on main. (ui/src/pages/usage/view-overview.ts:166, a905eb42acda)
  • PR renders comparison windows from existing data: The PR builds selected-range and shorter calendar-window cards from existing daily cost rows, matching the linked issue's no-new-protocol/no-new-storage shape. (ui/src/pages/usage/view-overview.ts:180, 892618170f5d)
  • Prior filter-scope finding is addressed: The PR hides range-wide cost windows whenever query, agent, day, hour, or session filters are active, avoiding a mismatched unfiltered comparison panel. (ui/src/pages/usage/view.ts:326, 892618170f5d)
  • Prior timezone-bucket finding is addressed: The gateway resolves the request day-bucket offset and passes it through both usage.cost and sessions.usage, while cached session summaries can rebuild daily projections from transcript entries. (src/gateway/server-methods/usage.ts:944, 892618170f5d)
  • Cached session rebucketing path: Persisted Gateway-local summaries are rebuilt for request-scoped day offsets from cached transcript entries, with synchronous direct-scan fallback when no cache summary is usable. (src/infra/session-cost-usage.ts:1855, 892618170f5d)

Likely related people:

  • steipete: This account authored and is assigned to the linked feature request and PR, is listed in CONTRIBUTING.md as Peter Steinberger, owns .github/CODEOWNERS, and authored recent provider-cost UI work adjacent to this feature. (role: product decision owner and recent area contributor; confidence: high; commits: 2bc50d0656bd, 8a187447f94a; files: ui/src/pages/usage/view-overview.ts, ui/src/pages/usage/view.ts, docs/reference/api-usage-costs.md)
  • shakkernerd: GitHub commit metadata shows this account authored/reviewed the recent Control UI route-owned architecture refactor that introduced the current Usage page file shape. (role: recent Control UI area contributor; confidence: medium; commits: 65e12328aa20; files: ui/src/pages/usage/view-overview.ts, ui/src/pages/usage/view.ts, ui/src/pages/usage/metrics.ts)
  • vincentkoc: Recent history on session-cost usage and gateway usage aggregation includes authored, co-authored, and reviewed maintenance by this account. (role: usage and cache adjacent owner; confidence: high; commits: c45124ab8554, eb03d0ee2ba1, aebf0bbd2da7; files: src/infra/session-cost-usage.ts, src/gateway/server-methods/usage.ts)
  • obviyus: GitHub commit metadata shows recent pricing-fingerprint and cache-entry maintenance in the central usage-cache path by this account. (role: recent usage-cache maintainer; confidence: medium; commits: 16861088b702, 6103b359cb3d; files: src/infra/session-cost-usage.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 (9 earlier review cycles; latest 8 shown)
  • reviewed 2026-07-05T19:29:22.239Z sha 221230f :: needs changes before merge. :: [P2] Align cost and session daily buckets
  • reviewed 2026-07-05T20:26:19.627Z sha 782737d :: needs changes before merge. :: [P2] Regenerate locale metadata without fallbacks
  • reviewed 2026-07-05T20:50:38.541Z sha c0725b2 :: found issues before merge. :: [P2] Scope cost windows to active filters
  • reviewed 2026-07-05T21:09:53.893Z sha 222f45d :: needs maintainer review before merge. :: none
  • reviewed 2026-07-05T21:18:23.703Z sha 222f45d :: needs maintainer review before merge. :: none
  • reviewed 2026-07-05T21:35:25.700Z sha d590a0a :: needs maintainer review before merge. :: none
  • reviewed 2026-07-05T22:01:48.891Z sha 032013b :: needs maintainer review before merge. :: none
  • reviewed 2026-07-05T22:39:07.969Z sha 3408b62 :: needs maintainer review before merge. :: none

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. labels Jul 5, 2026
@steipete
steipete force-pushed the codex/cost-analysis branch from 6aeffaf to 55b4fc5 Compare July 5, 2026 19:13
@openclaw-barnacle openclaw-barnacle Bot added the gateway Gateway runtime label Jul 5, 2026

@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: 55b4fc5d33

ℹ️ 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".

const summary = await loadCostUsageSummaryCached({
startMs,
endMs,
dailyUtcOffsetMinutes: resolveDayBucketUtcOffsetMinutes(dateInterpretation),

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 Align cost and session daily buckets

When the UI requests UTC or browser-local dates from a gateway running in another timezone, this new offset is applied only to usage.cost; sessions.usage still returns activityDates and dailyBreakdown from cached session summaries built with gateway-local formatDayKey(...) in src/infra/session-cost-usage.ts. The Usage view then intersects those session dates with data.costDaily, so a message near midnight can land on 2026-02-11 in the cost rows but 2026-02-12 in the session row, making selected-session/day filtering hide or misattribute the new cost-window/daily-chart data. Please either pass the same bucket contract through the session-summary path or avoid mixing these two daily sources.

Useful? React with 👍 / 👎.

@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Jul 5, 2026
@steipete steipete self-assigned this Jul 5, 2026
@steipete

steipete commented Jul 5, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Addressed both review findings at exact prepared head 222f45d23927f0e320b4d22d49682f27da3b0b67:

  • sessions.usage passes the same request-scoped UTC/browser offset used by usage.cost into every session daily projection.
  • Persisted Gateway-local summaries rebucket from cached transcript entries; UTC quarter-hour fields remain UTC.
  • The synchronous direct-scan fallback remains authoritative when cache detail is missing or aggregate-only.
  • Range-wide cost-window cards now hide whenever query, agent, day, hour, or session filters narrow the visible page. Exact filtered daily costs do not exist for every filter, so hiding avoids false precision.
  • Added near-midnight cache/fallback regressions plus unfiltered and filtered cost-window render coverage.

Proof:

  • Blacksmith Testbox tbx_01kwswgnzqeazh2q1mcvfmsfd2 (coral-hermit): 94 gateway assertions, 64 infra tests, 16 UI tests, and the mocked Gateway browser E2E passed.
  • Remote pnpm check:changed passed, including TSGo, complete core/UI/package lint, import-cycle, storage, loader, dependency, and runtime guards.
  • Exact-head CI exposed and drove repairs for offset-aware cache-key assertions, locale fallbacks, and combined-tree raw-copy baseline drift; each focused rerun passed.
  • Blacksmith Testbox tbx_01kwt158mvz8mef2sx1ca01pez (amber-lobster), Actions run 28754668376: 5 Usage view tests and the Usage cost-analysis browser E2E passed after the filter-scope fix.
  • Fresh autoreview after the filter-scope fix: clean, 0.88 confidence.
  • Canonical i18n check on current main: 20 locales, 1,535 keys, zero fallbacks; raw-copy baseline 693 entries.
  • Exact-SHA native CI fallback is running at https://github.com/openclaw/openclaw/actions/runs/28754858430.

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

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

@clawsweeper clawsweeper Bot added 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. and removed proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. labels Jul 5, 2026
@clawsweeper clawsweeper Bot added status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Jul 5, 2026
@openclaw-barnacle openclaw-barnacle Bot added the channel: discord Channel integration: discord label Jul 5, 2026

@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: d590a0ab99

ℹ️ 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".

defer { self.finishSetupAttempt(attemptID) }
defer {
self.finishSetupAttempt(attemptID)
self.pendingTargetSuppression.resumeAutoConnect(.qrScanner, controller: self.gatewayController)

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 Keep QR target suppression through trust prompts

When a scanned QR setup link targets a TLS gateway with no stored fingerprint, connectManual returns after setting pendingTrustPrompt; it has not connected or failed yet. This defer then resumes the .qrScanner lease opened with suspendCurrentGateway: true, so the previously active gateway can be restored behind the certificate-review alert before the user accepts or declines the new target (the Settings QR handler has the same defer). Keep or release the lease from the trust-prompt resolution path instead.

Useful? React with 👍 / 👎.

@steipete
steipete force-pushed the codex/cost-analysis branch from 032013b to 641f048 Compare July 5, 2026 22:15
@openclaw-barnacle openclaw-barnacle Bot removed channel: discord Channel integration: discord channel: matrix Channel integration: matrix channel: voice-call Channel integration: voice-call channel: whatsapp-web Channel integration: whatsapp-web app: android App: android app: ios App: ios app: macos App: macos cli CLI command changes scripts Repository scripts commands Command implementations docker Docker and sandbox tooling agents Agent runtime and tooling labels Jul 5, 2026
@steipete

steipete commented Jul 5, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

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 P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: XL 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.

[Feature]: Add comparative cost windows to Usage

1 participant