Skip to content

Port upstream 0.67.0: opt-in LiteLLM model activity and Claude workspace spend - #664

Closed
Finesssee wants to merge 2 commits into
port/upstream-0.67.0from
port/micro-0.67.0-optional-provider-details
Closed

Finesssee wants to merge 2 commits into
port/upstream-0.67.0from
port/micro-0.67.0-optional-provider-details

Conversation

@Finesssee

Copy link
Copy Markdown
Collaborator

Summary

Ports upstream CodexBar 0.67.0 items 12 and 13 as one opt-in feature, off by default:

  • LiteLLM model activity: top 20 models by total tokens over the last 30 UTC days, with requests and input/output token counts.
  • Claude workspace spend: per-workspace 30 day spend from the Admin API cost report, shown only when more than one workspace exists.

A single per-provider setting (ProviderConfig.optional_details_enabled, LiteLLM and Claude only) is exposed as one checkbox in Settings > Providers and carried to fetchers through FetchContext.optional_details_enabled. Rows use the existing ProviderDisplayDetail list, which gained an optional bounded section so the UI can print a heading per group (Settings usage pane and tray card).

Upstream reference

steipete/CodexBar release 0.67.0 (read from cached release-tag sources only): litellm.ts plugin, LiteLLMModelUsageTests, ClaudeAdminAPIUsageFetcher, ClaudeAdminAPIUsageSnapshot, ClaudeAdminAPIUsageTests.

Ported / Deferred

Ported:

  • LiteLLM GET {base}/user/daily/activity (up to 3 pages, 2 s per request, Bearer auth, exact 200), strict validation (safe integers, date window, row and model bounds, 2^53-1 sums, repeated-page detection), any failure yields no rows (debug log reason only, never a body). Only attached when the key/info root reports a user_id.
  • Claude: group_by[]=workspace_id appended to the existing cost request (no extra request), blank workspace ids grouped as "Default", cents summed per workspace, top 20 by spend then name.
  • Section headings in the CLI text/JSON output, Settings usage pane and tray card.

Deferred / deviations:

  • Upstream env-var opt-ins (LITELLM_MODEL_USAGE_ENABLED, ANTHROPIC_ADMIN_WORKSPACE_SPEND) are not ported; the setting is the only switch.
  • CLI usage and serve do not load per-provider settings, so the opt-in stays off there. diagnose, hooks and the desktop shell honour it.
  • Claude workspace totals sum the same buckets as the local organization total (all returned buckets over a 30 day range); upstream filters to the last 30 daily buckets with start <= now.
  • Tie ordering is by byte order, not localeCompare.
  • Pre-existing local LiteLLM gaps (no user/info or team/info fallback, no private-network http) are unchanged.
  • Pre-existing on base: MenuCardDetails.tsx renders the displayDetails block twice, so tray card headings and rows show twice. Not changed here; flagged for a follow-up.
  • Pre-existing environment failure unrelated to this change: commands::tests::bootstrap_payload_exposes_every_provider_variant (catalog 79 vs 78).

Validation

Rust (E-cores, +1.98.0, --test-threads=4):

  • cargo fmt --all: clean
  • cargo clippy --workspace --all-targets -- -D warnings: clean
  • cargo test -p codexbar: 2190 passed, 0 failed, 1 ignored (38 in the focused litellm / admin_api / optional_details / display_detail / sectioned filters)
  • cargo test -p codexbar-desktop-tauri: 463 passed, 1 failed (the pre-existing failure above)

Frontend (apps/desktop-tauri, pnpm):

  • pnpm exec vitest run: 69 files, 408 tests passed
  • pnpm run lint: no errors (existing warnings only)
  • pnpm run build: check-locale OK (884 keys match Rust and TS), tsc --noEmit and vite build succeed

Affected areas

  • rust/src/providers/litellm/ (model_activity.rs new), rust/src/providers/claude/admin_api.rs
  • rust/src/core/display_detail.rs, provider.rs (FetchContext), rust/src/settings/ (optional_details.rs new)
  • CLI render/diagnose/hooks; Tauri commands (set_provider_optional_details, provider detail DTO, bridge section)
  • React: Settings provider pane (OptionalDetailsSection), UsageSection, MenuCardDetails, en-US locale keys

UI proof

Pending: coordinator will capture CUA proof on a fresh build.

@coderabbitai

coderabbitai Bot commented Sep 29, 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

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

Copy link
Copy Markdown
Collaborator Author

Thermo-nuclear review

Scope: PR #664 head de4c824 against the optional-provider-details spec (0.67.0 audit). Behavior matches the spec on the points I checked: 3-page cap and 2 s per-page timeout, strict page/day/model/counter validation, flat and nested metrics counters, same-day rows combined across pages, top 20 by total tokens with name ties, the extra group_by[]=workspace_id with no extra request, the "Default" workspace, and the more-than-one-workspace gate. No file crosses 1000 lines. The admin_api.rs tests moved to a sibling admin_api_tests.rs, as required.

Findings

  1. Blocker (fixing in this PR): the tray card renders provider display details twice. MenuCardDetails.tsx has two identical menu-card__provider-details sections, one gated by !compactOverview and one unconditional. The second already covers every case, so the first only doubles output outside compact mode. That was a latent copy/paste; this PR pastes the new section-heading logic into both. With model activity (up to 20 rows plus a heading) the whole section would show twice in the tray. Fix: delete the redundant block and keep one heading-aware render.
  2. Simplification (fixing in this PR): the for row in rows { result = result.with_display_detail(Some(row)) } loop is repeated in LiteLLM and Claude. Add ProviderFetchResult::with_display_details(iter) next to with_display_detail and use it in both.

Noted, left as is

  • One shared optional_details_enabled flag instead of the two spec-named fields (litellm_model_usage_enabled, claude_workspace_spend_enabled). The single bool, guarded by provider_has_optional_details and a per-provider copy map, is smaller, serialized only when true, and each provider has exactly one breakdown, so I am not splitting it. If a provider ever gets a second optional detail, split it then. The Rust allowlist and the TS OPTIONAL_DETAILS_COPY map must stay in step; the Rust side is authoritative through optionalDetailsSupported.
  • Overall timeout. The spec says 40 s when enabled. The local shell budget is 35 s per provider. The LiteLLM worst case is a 15 s key/info plus 3 x 2 s pages = 21 s, so the budget is never hit and no timeout change is needed.
  • Object<T> wrapper and Value round trip in model_activity.rs. It exists to stop derived structs from being filled positionally from JSON arrays, and it is documented and tested. Acceptable for a strict wire validator.
  • codexbar usage, guard, and the dashboard pass optional_details_enabled: false because they resolve no saved API keys; diagnose and hooks read the setting. This is consistent.

@Finesssee

Copy link
Copy Markdown
Collaborator Author

Thermo-nuclear review: fixes landed

Reviewed by Codex gpt-6-luna (xhigh); verified and validated by Claude. Head: bb53fec.

Fixed:

  • MenuCardDetails.tsx: removed the duplicated menu-card__provider-details section; one heading-aware render remains.
  • Added ProviderFetchResult::with_display_details and used it in LiteLLM and Claude (with an order/dedupe test).
  • litellm/model_activity.rs: impossible calendar days such as 2026-09-00 are now rejected (regression test added).
  • commands/providers.rs: optional LiteLLM model activity gets the spec's 40 s fetch budget (assertion added).

Left, and why:

  • Codex proposed an exclusive bound for float counters at 2^53. Reverted: MAX_SAFE_INTEGER as f64 is exactly 2^53-1, so the existing inclusive check already rejects 2^53; the change would have wrongly rejected a valid 9007199254740991.0. The extra test case for 9007199254740992.0 was kept.
  • Single shared optional_details_enabled flag: unchanged, as noted in the review above.

Commands run: cargo +1.98.0 fmt --all --check; clippy -D warnings on rust and apps/desktop-tauri/src-tauri; focused cargo tests (litellm, display_detail, claude::admin, provider_fetch_timeout); vitest src/components (87 passed); pnpm install --frozen-lockfile. No desktop app run.

@Finesssee

Finesssee commented Sep 30, 2026 •

Copy link
Copy Markdown
Collaborator Author

CUA proof

Build commit: bb53fec041a77ca4e9b68758d23785981019c09c (debug desktop build via pnpm run tauri:build:debug).

Proof-only patch (throwaway, not committed): root Cargo.toml [patch.crates-io] dirs = <proof-shim> so config/data dirs live under an isolated proof home. No provider fetch was needed, so no mocks and no source patches.

Setup: isolated profile with enabled_providers: ["litellm"], theme: "auto", dummy LITELLM_API_KEY; launched with CODEXBAR_PROOF_MODE=settings:providers; driven with cua-driver background actions only (UIA invoke/toggle, set_value), window kept on the secondary monitor.

# Assertion Result
1 No real email/account from the user's machine visible PASS
2 Settings > Providers > LiteLLM shows "Optional details" with "Show model activity", unchecked by default, with the extra-requests helper text PASS
3 Ticking the checkbox (UIA Toggle) leaves it checked after the pane reloads from the backend PASS
4 Dark theme still applied under theme auto PASS

Limits: settings.json is DPAPI-encrypted (secure_file), so persistence was confirmed through the UI state after the backend round-trip, not by reading the file. The model-activity/workspace-spend data rendering was not exercised (unit tests cover the parsers).

Screenshots (local, not committed), in %LOCALAPPDATA%\Win-CodexBar\port-audit\proof\664\shots\:

  • 01-settings-providers.png
  • 02-litellm-selected.png (toggle off by default)
  • 03-model-activity-on.png (toggle on)

@Finesssee

Copy link
Copy Markdown
Collaborator Author

UI proof (browser-use)

Combined build of integrate/v0.70.0-ports at ddd85594 (all 40 port PRs and the follow-ups). Debug desktop build in proof mode, isolated config/data dirs, driven by browser-use over the WebView2 DevTools protocol with DOM events only (no mouse or keyboard input, no focus changes). All data is synthetic: local mock servers for L1, a seeded usage snapshot plus synthetic local logs for L2.

Scenario Check Result
L1 tray (mock servers) #664 LiteLLM: personal 25% $12.50/$50.00, team Proof Team 30% $30.00/$100.00 PASS
L1 tray (mock servers) #664 LiteLLM: grouped render has no duplicated detail rows PASS
L1 tray (mock servers) #664 LiteLLM: model activity hidden while opt-in is off PASS
L1 settings #664 LiteLLM settings: 'Show model activity' opt-in present and off by default PASS
L1 settings #664 LiteLLM settings: opt-in turns on and persists (provider detail reports enabled) PASS
L1 settings #664 LiteLLM tray after opt-in + refresh: model activity rows gpt-proof-large, claude-proof, proof-mini next to the unchanged budgets PASS
L1 settings #664 LiteLLM mock: /user/daily/activity requested for the bound user with the bearer PASS
L1 settings #664 LiteLLM settings: opt-in turns back off PASS
L1 mock request logs #664/#630 LiteLLM mock: key/info -> user/info for the bound user, bearer on every request PASS

Every surface also passed the privacy check (no email-like text, account e-mail nodes or profile paths in the DOM) and theme auto rendered dark on the tray flyout, float bar and settings windows.

Validation at ddd85594: cargo fmt --all --check, cargo clippy --workspace --all-targets -- -D warnings, cargo test -p codexbar (3567 passed, 0 failed) and cargo test -p codexbar-desktop-tauri (606 passed, 0 failed). Screenshots were captured for each scenario and kept with the local proof kit.

@Finesssee

Copy link
Copy Markdown
Collaborator Author

Shipped in v0.70.0: this PR's head is included in main via #735 (merge commit 9d0a37a). Closing as integrated.

@Finesssee Finesssee closed this Oct 3, 2026
junglesub-bot Bot pushed a commit to junglesub/Win-CodexBar that referenced this pull request Oct 4, 2026
…vity and Claude workspace spend

Resolved onto the release display-detail and LiteLLM flows:
- One section mechanism: nesszer#664's parallel ProviderDisplayDetail `section`
  (field, builder, getter, bridge key, TS field, displaySectionHeading,
  .provider-usage-subheading) duplicated release's `section_title` /
  `sectionTitle` grouping. Model activity and workspace spend now use
  with_section_title(); MenuCardDetails/UsageSection keep the release
  grouped render; the nesszer#664 heading tests check groupProviderDisplayDetails
  and the release role=heading markup; the CLI prints and emits
  `sectionTitle` once per group (Aixy groups included).
- LiteLLM: kept the release typed key -> user/team budget flow plus the
  nesszer#630 spend-report fallback. The opt-in threads into fetch_key_usage;
  model activity is requested only for a user-bound key after the budgets
  succeed (upstream 0.67.0), never on the team path or the spend-report
  fallback, and its failure never fails the budgets. nesszer#664's Value-based
  key/info helpers and their tests are superseded by info.rs/tests.rs.
- FetchContext literals added since the fork (serve dashboard, CLI
  fetch_context tests) carry optional_details_enabled: false.
- Kept both sides of the locale/keys lists, the shell fetch-context
  OpenCode Go rule, and the gateway section next to OptionalDetailsSection.
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