Skip to content

Port upstream 0.58.0: re-land stranded Usage & Spend daily ledger (#492) with the 0.67.0 30-row cap - #715

Merged
Finesssee merged 4 commits into
mainfrom
port/micro-0.58.0-reland-usage-spend-ledger
Oct 3, 2026
Merged

Finesssee merged 4 commits into
mainfrom
port/micro-0.58.0-reland-usage-spend-ledger

Conversation

@Finesssee

Copy link
Copy Markdown
Collaborator

Summary

Re-lands the upstream v0.58.0 Usage & Spend port #492. It was merged on 2026-09-13 only into the stacked base port/upstream-0.58.0 and never reached main; git cherry against main @ 7695471b still reported both commits as missing.

  • Daily ledger (Settings > Usage & Spend): a table built from the existing SpendContract.daily cost and token fields, newest day first. A missing cost or token count shows "Unknown", and an explicit zero stays $0.00 / 0 tokens.
  • Local cost chart hover titles (tray card): each bar's title now also shows that day's token count from chartData.tokensHistory.
  • Upstream 0.67.0 Fix Usage & Spend scroll lag on long ranges steipete/CodexBar#3998, which applies once the ledger exists: long ledgers open with the newest 30 days plus a Show all (N) / Show less control. 0.67.0.md row 18 marked this SKIP because Windows had no ledger. This PR adds the ledger, so the row is ported here.

The original commits are cherry-picked with -x. The second commit adapts them to main, which already keeps the canonical spend formatters in lib/usageSpendSharing.ts. The ledger reuses formatUsd, and the token-cell helper is added there as formatSpendTokens instead of a second formatter module.

Upstream reference

Ported / Deferred

Change Status
Daily ledger with unknown vs zero cells Ported (#492)
Token counts in local cost chart hover titles Ported (#492)
Newest 30 rows + Show all / Show less Ported (steipete#3998)
Upstream ledger Providers and Requests columns Not ported. The Windows SpendContract.daily point has no per-day provider mix or request count, and wire shapes are not invented.

Locale: six new keys (UsageSpendDailyLedger, UsageSpendDailyLedgerHelper, UsageSpendNoDailyData, UsageSpendColDate, UsageSpendColCost, UsageSpendColTokens) are in rust/src/locale.rs, keys.ts and all eight .ftl files. The toggle reuses the existing UsageSpendShowAll / UsageSpendShowLess.

Validation

Run in the worker worktree on Rust 1.98.0 and Node 24:

Command Result
pnpm install --frozen-lockfile pass
pnpm run check-locale 877 keys match between Rust and TS
pnpm test 66 files, 404 tests passed
pnpm run lint 0 errors. The 11 warnings are the same unused imports as on main
pnpm run build pass
cargo +1.98.0 fmt --all --check pass
cargo +1.98.0 clippy --workspace --all-targets -- -D warnings pass
cargo +1.98.0 test -p codexbar 2160 passed, 0 failed, 1 ignored
cargo +1.98.0 test -p codexbar-desktop-tauri -- --skip bootstrap_payload_exposes_every_provider_variant 459 passed, 0 failed

The skipped desktop test is the non-hermetic #684 test, which reads the real %APPDATA%\CodexBar\settings.json on main. #711 fixes it separately.

Affected areas

  • apps/desktop-tauri/src/components/UsageSpendDailyLedger.tsx (new) and its test
  • apps/desktop-tauri/src/components/MenuCardDetails.tsx (chart hover titles) and MenuCard.test.tsx
  • apps/desktop-tauri/src/lib/usageSpendSharing.ts (formatSpendTokens) and its test
  • apps/desktop-tauri/src/surfaces/settings/tabs/UsageSpendTab.tsx (mounts the ledger)
  • apps/desktop-tauri/src/styles.css, apps/desktop-tauri/src/i18n/keys.ts, rust/src/locale.rs, rust/src/locale/*.ftl

UI proof

Pending: a browser-use proof over WebView2 CDP of Settings > Usage & Spend (ledger, 30-row cap, Show all) and the tray card chart titles, built from this head with isolated data. It will be posted as a "UI proof (browser-use)" comment.

(cherry picked from commit f43cb6e)
Adapted to main: main already keeps the canonical spend formatters in
lib/usageSpendSharing.ts (formatUsd, formatSpendMetric), so the daily
ledger reuses them and the token-cell helper is added there as
formatSpendTokens instead of a second lib/usageSpendFormatters.ts module.
UsageSpendTab keeps main's layout unchanged.

(cherry picked from commit 89edce6)
The re-landed daily ledger added six keys to en-US only. Add them to the
other seven locale files so every .ftl stays aligned with locale.rs and
keys.ts.
Port upstream 0.67.0 steipete#3998 (ce1b808) now that the daily ledger exists:
the ledger opens with the newest 30 days and a Show all (N) / Show less
control expands it to the complete history. Translates the upstream
SpendDashboardDailyLedgerTests expansion test.
@coderabbitai

coderabbitai Bot commented Sep 30, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Autopilot is currently an internal CodeRabbit preview.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Finesssee

Finesssee commented Oct 1, 2026 •

Copy link
Copy Markdown
Collaborator Author

UI proof (browser-use)

Result: PASS on build 07f1bb7a4dcfaf5b31dbea2263520c343b8403d7, the current PR head "Start long daily ledgers with the newest 30 rows".

  • Settings > Usage & Spend: the daily ledger lists the scanned days newest first. It shows "Unknown" for a day without a known cost, opens long histories at 30 rows with "Show all (44)", expands to all 44 days and collapses again.
  • Tray card chart: every bar title now carries that day's token count, for example 2026-09-02: $0.18 · 131K tokens.

At the maintainer's direction, this proof drove the app's WebView2 over CDP with the browser-use CLI instead of CUA. It used no keyboard, mouse or focus. Clicks were DOM element.click() calls, and the global shortcut was off in the kit settings.

Setup

  • Build: pnpm run tauri:build:debug in the worker worktree at 07f1bb7a. The exe was copied to the proof kit; its SHA-256 is 5a1409d0…930bb1c, and it loads index-BXGF04xb.js.
  • Proof-only patch: never committed, and reverted after the build.
    • A workspace Cargo.toml [patch.crates-io] dirs shim for an isolated home, plus the resulting Cargo.lock change.
    • A no-focus overlay, because this branch doesn't include Stop CodexBar from stealing focus #713 yet. It changes only window focus: it drops the tray panel set_focus call, builds the float bar with focused(false) and adds SWP_NOACTIVATE to the DWM frame refresh.
  • Home and providers: USERPROFILE, HOME, APPDATA, LOCALAPPDATA and XDG_CONFIG_HOME pointed at a home inside the kit. CLAUDE_CONFIG_DIR and GEMINI_HOME pointed at empty kit folders, the provider API key variables were unset, and PATH was cut to the Windows system folders.
  • Settings: only Codex was enabled. The theme was auto, the float bar was off and the global shortcut was empty. For the tray run, the kit settings also set overview_layout to detailed, because the default compact overview hides the card's "Usage details" section.
  • Data: a generator wrote 45 days of synthetic Codex session logs, one token_count event per day at local noon, into the kit's CODEX_HOME. The app's real local cost scanner read them.
    • Every day from 2026-08-18 to 2026-10-01 used gpt-5, with 100,000 + 1,000 × (days ago) input tokens and 2,000 output tokens, except for two days.
    • 2026-09-26 used only proof-unpriced-model, with 50,000 input tokens. This gives a day with a known token count and an unknown cost.
    • 2026-09-22 has a gpt-5 event whose totals are all zero.
  • Seed: CODEXBAR_SEED_USAGE_JSON supplied the Codex quota card, with Session 40% used and Weekly 20% used.
  • Commands:
    • Run 1: bash launch.sh settings:usageSpend, which sets CODEXBAR_PROOF_MODE=settings:usageSpend.
    • Run 2: bash launch.sh trayPanel.
    • Both set WEBVIEW2_ADDITIONAL_BROWSER_ARGUMENTS=--remote-debugging-port=9335 .... Checks ran as BU_CDP_URL=http://127.0.0.1:9335 BU_NAME=worker-715 BH_TAB_MARKER=0 browser-use.
    • Before each attach, curl /json/version showed Edg/154 WebView2, and the port 9335 listener was a WebView2 child of the kit exe.

Results

# Assertion Result
T0 No real email or account from the host is visible. Every app page was scanned before each screenshot, and no scan found an @ address or the host user name. PASS
T1 Dark under theme auto in both runs: prefers-color-scheme: dark, data-theme=dark, body rgb(28, 28, 30) and text rgb(245, 245, 247). PASS
T2 Ledger structure at the default 30d: heading "Daily ledger", the caption "Recorded daily cost and token totals. Unknown means the source did not establish that value.", a table labelled "Daily ledger" and columns Date, Cost and Tokens. It has 29 rows, newest first, from 2026-10-01 to 2026-09-02: the 30-day window minus the all-zero day. There is no toggle, because 29 is at most 30. PASS
T3 Unknown is distinct from a known value. The 2026-09-26 row reads "Unknown" and "50,000 tokens". For that day, get_usage_spend_summary (a read-only invoke, historyDays: 0) returns costUsd: null and totalTokens: 50000. Priced days read, for example, "$0.15" and "102,000 tokens". PASS
T4 The 30-row cap. After "All time" was selected (aria-pressed=true), the contract has 44 days. The ledger shows 30 rows from 2026-10-01 to 2026-09-01 and a "Show all (44)" button with aria-expanded=false. PASS
T5 Show all. One click gives 44 rows and "Show less" with aria-expanded=true. All 44 rows match the generator's expected days, by date and token count, from 2026-10-01 to 2026-08-18 (146,000 tokens). The rows are newest first and no date repeats. PASS
T6 Show less. A second click goes back to 30 rows and "Show all (44)" with aria-expanded=false. PASS
T7 Other ranges. 7d shows 7 rows from 2026-10-01 to 2026-09-25, including the Unknown row, with no toggle. Going back to 30d restores the 29 rows. PASS
T8 Chart hover titles (tray card, "Usage details", chart labelled "30 day cost histogram"). All 30 bars have a title of the form <date>: <cost> · <tokens> tokens, from 2026-09-02: $0.18 · 131K tokens to 2026-10-01: $0.15 · 102K tokens. The unpriced day reads 2026-09-26: — · 50K tokens (its bar has opacity 0). The all-zero day reads 2026-09-22: $0.00 · 0 tokens: a zero token count now shows 0 instead of —. PASS
T9 The proof never took focus. Every app page reported document.hasFocus() as false in both runs. PASS
— Native paths Not applicable: the change is frontend-only, plus locale strings, which check-locale covers.

Explicit zero in the ledger: the Codex scanner keeps no day for an event whose token totals are all zero, so the contract had no 2026-09-22 point and the ledger had no row for it. The ledger's $0.00 / 0 tokens cell is covered by the unit test UsageSpendDailyLedger > renders newest daily rows and keeps zero distinct from unknown.

Validation at 07f1bb7a

Run in the worker worktree on Rust 1.98.0 and Node 24:

Command Result
pnpm install --frozen-lockfile pass
pnpm run check-locale 877 keys match between Rust and TS
pnpm test 66 files, 404 tests passed
pnpm run lint 0 errors. The 11 warnings are the same unused imports as on main.
pnpm run build pass
cargo +1.98.0 fmt --all --check pass
cargo +1.98.0 clippy --workspace --all-targets -- -D warnings pass
cargo +1.98.0 test -p codexbar 2160 passed, 0 failed, 1 ignored
cargo +1.98.0 test -p codexbar-desktop-tauri -- --skip bootstrap_payload_exposes_every_provider_variant 459 passed, 0 failed. The skipped test is the non-hermetic #684 test that #711 fixes.
ci/circleci: pr-check success

Screenshots

All paths are under %LOCALAPPDATA%\Win-CodexBar\port-audit\proof\715\shots\.

File What it shows
715-ledger-alltime-collapsed.png All time, top of the ledger: newest first, with the 2026-09-26 "Unknown" / "50,000 tokens" row.
715-ledger-alltime-toggle-collapsed.png All time, end of the collapsed ledger: the last row is 2026-09-01, followed by "Show all (44)".
715-ledger-alltime-expanded-end.png Expanded: the ledger ends at 2026-08-18 (146,000 tokens), followed by "Show less".
715-tray-local-chart.png The tray panel, dark, with the Codex card's Usage details open: Today $0.15, 30d cost $4.71, 30d tokens 3.3M, the token bar chart and the Cost (30 days) chart.

Not blocking (found on main, not caused by this PR)

  • The two 30-day cost totals disagree when a model is unpriced.
    • With the same logs, the tray card's "30d cost" reads $4.71, while the panel header and Settings > Usage & Spend (30 days) read $4.59.
    • The $0.125 difference is the unpriced day. The card's local-usage summary prices proof-unpriced-model with codex_cost_usd_fallback (rust/src/codex_costs.rs, default $2.50 per million input tokens). The daily history and the spend contract leave that day's cost unknown.
  • Provider detail rows render twice when the overview is detailed or a provider is selected.
    • MenuCardDetails.tsx renders provider.displayDetails in two identical menu-card__provider-details sections. One is gated on !compactOverview and one isn't, so outside the compact overview the rows appear twice.
    • Providers that set displayDetails include CodeRabbit, Hugging Face, Muse, Nous, Replicate and Venice.
    • This was found by reading the code. This proof didn't show it, because Codex has no display details.
  • An empty global_shortcut logs WARN codexbar_desktop_tauri::shortcut_bridge: Could not parse global shortcut: at every launch. This was already reported on Fix reset refresh timer for resets over 24.8 days away #720.

@Finesssee

Copy link
Copy Markdown
Collaborator Author

Adversarial validation passed at ef15c0d

Scope: re-land Usage & Spend daily ledger (#715, stranded #492 + 0.67.0 30-row cap steipete#3998), validated as merged into release/v0.70.0 (merge ef15c0d = merge of 07f1bb7 into 1313c80).

Attacks:

  • Collapsed cap: dailyLedgerVisibleRows sorts newest-first and slices to DAILY_LEDGER_COLLAPSED_ROWS = 30 collapsed; the test collapses to the upstream default of 30 rows pins the constant, and ledger expansion preserves every day in newest first order (%i days) covers 0/7/30/31/365 collapsed vs expanded for 0..365 days, asserting collapsed equals daily.slice(-30).reverse() — so the "start with the newest 30 days" rule holds even when daily arrives oldest-first.
  • Zero vs Unknown: the "zero token count distinct from an unknown one" test covers 0, 8100, null, undefined, -1 and NaN, asserting 0 tokens renders while null/undefined/-1/NaN become "Unknown". This is the stranded Port v0.58 usage spend daily ledger and chart details #492 restore target and it survived the re-land intact — the merged tree keeps formatSpendTokens in the shared file.
  • Show all/less: the integration test asserts collapsed length 30, newest-first top row 2026-01-31, bottom 2026-01-02, the 31st day absent until expanded, and the aria-expanded state flipping both ways.
  • Windows-specific: the locale keys (UsageSpendShowAll, UsageSpendShowLess) are in all 8 .ftl files, so no locale renders raw key text.

No defects found. The browser-use proof (issuecomment-5924578228 at 07f1bb7) already showed 29 ledger rows @30d, an unknown-cost row, and the 44-day "Show all"/"Show less" round-trip. READY for the un-draft rule.

@Finesssee
Finesssee merged commit ef15c0d into main Oct 3, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant