Skip to content

Add quota-run efficiency metrics on Charts (SOU-299) - #144

Merged
tsouth89 merged 1 commit into
mainfrom
feature/sou-299-quota-efficiency
Jul 25, 2026
Merged

Add quota-run efficiency metrics on Charts (SOU-299)#144
tsouth89 merged 1 commit into
mainfrom
feature/sou-299-quota-efficiency

Conversation

@tsouth89

@tsouth89 tsouth89 commented Jul 24, 2026

Copy link
Copy Markdown
Owner

Summary

  • Extend SOU-298 run snapshots with best-effort local token samples captured while the run is open (pre-reset).
  • Derive tokens / 1%, cache-read %, projected @ 100% (only when peak ≥ 25%), and run-over-run delta vs the previous complete run on the same window.
  • Charts card: Quota run efficiency, labeled as local observation (not a published allowance).
  • IPC: get_quota_run_efficiency (+ ACL).

Honesty

Provider % stays authoritative. Token totals may still be machine-wide for some providers; the card copy says so. Projection is suppressed early in a run.

Test plan

  • Rust quota_run tests (6)
  • ChartsSection vitest
  • clippy -D warnings, tsc
  • Live: complete a window reset with local logs; confirm card fills after a second run for deltas

Closes SOU-299. No release.

Summary by CodeRabbit

  • New Features
    • Added quota-run efficiency cards to provider usage charts.
    • Displays tokens per 1% usage, cache-read share, projected token capacity, and changes versus prior runs.
    • Captures local token samples to improve efficiency insights across quota windows.
  • Bug Fixes
    • Clarified quota-run history ordering in documentation.
  • Tests
    • Added coverage for efficiency metrics, projections, comparisons, and displayed values.

Capture best-effort local tokens during open runs, derive tokens per 1% used, cache-read share, projection to 100%, and run-over-run delta. Surface one card per window on Charts with honest local-observation labeling. Unblocks comparing how far an allowance actually went across resets.
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
ceiling 3e6c3de Commit Preview URL

Branch Preview URL
Jul 24 2026, 11:52 PM

@coderabbitai

coderabbitai Bot commented Jul 24, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Quota-run history now captures local token samples, computes efficiency metrics, exposes them through a new Tauri command and TypeScript bridge, and renders quota-efficiency cards in provider charts with supporting tests and styles.

Changes

Quota run efficiency

Layer / File(s) Summary
Persisted token sampling
apps/desktop-tauri/src-tauri/src/quota_run_history.rs
Quota-run snapshots and open runs now retain optional local token samples across creation, reset handling, and finalization.
Efficiency calculation and validation
apps/desktop-tauri/src-tauri/src/quota_run_history.rs
Efficiency results calculate token rates, cache share, projections, previous-run deltas, and notes with threshold gating and filtering.
Native command exposure
apps/desktop-tauri/src-tauri/src/commands/chart.rs, apps/desktop-tauri/src-tauri/src/main.rs, apps/desktop-tauri/src-tauri/permissions/commands.toml, apps/desktop-tauri/src/lib/tauri.ts, apps/desktop-tauri/src/types/bridge.ts
The new efficiency API is typed, permissioned, registered with Tauri, and exposed through the TypeScript bridge.
Provider chart presentation
apps/desktop-tauri/src/surfaces/settings/providers/sections/charts/ChartsSection.tsx, apps/desktop-tauri/src/styles.css, apps/desktop-tauri/src/surfaces/settings/providers/sections/charts/ChartsSection.test.tsx
Charts fetch and render efficiency cards with token, cache, projection, and comparison metrics, including UI coverage.
Estimated code review effort: 4 (Complex) ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant ProviderCharts
  participant TauriBridge
  participant NativeCommand
  participant QuotaRunHistory
  ProviderCharts->>TauriBridge: request provider efficiency
  TauriBridge->>NativeCommand: invoke get_quota_run_efficiency
  NativeCommand->>QuotaRunHistory: call efficiency_for_provider
  QuotaRunHistory-->>NativeCommand: return efficiency rows
  NativeCommand-->>TauriBridge: return typed rows
  TauriBridge-->>ProviderCharts: render quota efficiency card
Loading

Possibly related PRs

Suggested reviewers: finesssee

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 63.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: adding quota-run efficiency metrics to Charts.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/sou-299-quota-efficiency

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (2)
apps/desktop-tauri/src/surfaces/settings/providers/sections/charts/ChartsSection.tsx (2)

487-505: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Efficiency card doesn't refresh while the user stays on the same provider.

The fetch effect only re-runs on [providerId, accountEmail]. If a quota run closes (reset/drop) while the Charts tab remains open for the same provider/account, the new efficiency row won't appear until the user navigates away and back. Consider also refetching when usageWindowsKey/data changes (mirroring the existing chart-data refresh trigger).

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@apps/desktop-tauri/src/surfaces/settings/providers/sections/charts/ChartsSection.tsx`
around lines 487 - 505, The efficiency-fetching useEffect in ChartsSection must
also rerun when chart usage data refreshes, not only when providerId or
accountEmail changes. Add the existing usageWindowsKey/data refresh trigger to
its dependency array, matching the chart-data effect, while preserving the
cancellation and provider-support checks.

147-152: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Possible duplicate of the existing token formatter.

formatCompactTokens abbreviates tokens into K/M/B, the same style already used elsewhere in this component for token counts (e.g. the period cards). If an equivalent formatter already exists in this file/module, prefer reusing it instead of introducing a near-duplicate.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@apps/desktop-tauri/src/surfaces/settings/providers/sections/charts/ChartsSection.tsx`
around lines 147 - 152, Check the existing token-count formatter used by the
period cards in ChartsSection and reuse it for the new display instead of
maintaining formatCompactTokens. Remove the duplicate formatCompactTokens helper
and update its callers to use the existing formatter, preserving the current
K/M/B formatting behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In
`@apps/desktop-tauri/src/surfaces/settings/providers/sections/charts/ChartsSection.tsx`:
- Around line 487-505: The efficiency-fetching useEffect in ChartsSection must
also rerun when chart usage data refreshes, not only when providerId or
accountEmail changes. Add the existing usageWindowsKey/data refresh trigger to
its dependency array, matching the chart-data effect, while preserving the
cancellation and provider-support checks.
- Around line 147-152: Check the existing token-count formatter used by the
period cards in ChartsSection and reuse it for the new display instead of
maintaining formatCompactTokens. Remove the duplicate formatCompactTokens helper
and update its callers to use the existing formatter, preserving the current
K/M/B formatting behavior.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 5e838276-de65-4ee5-81bc-8a13878826be

📥 Commits

Reviewing files that changed from the base of the PR and between 9699998 and 3e6c3de.

📒 Files selected for processing (9)
  • apps/desktop-tauri/src-tauri/permissions/commands.toml
  • apps/desktop-tauri/src-tauri/src/commands/chart.rs
  • apps/desktop-tauri/src-tauri/src/main.rs
  • apps/desktop-tauri/src-tauri/src/quota_run_history.rs
  • apps/desktop-tauri/src/lib/tauri.ts
  • apps/desktop-tauri/src/styles.css
  • apps/desktop-tauri/src/surfaces/settings/providers/sections/charts/ChartsSection.test.tsx
  • apps/desktop-tauri/src/surfaces/settings/providers/sections/charts/ChartsSection.tsx
  • apps/desktop-tauri/src/types/bridge.ts

@tsouth89
tsouth89 merged commit 753f8bc into main Jul 25, 2026
10 of 11 checks passed
@tsouth89
tsouth89 deleted the feature/sou-299-quota-efficiency branch July 25, 2026 00:00
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