Skip to content

ADE-117: Make usage refresh reliable and lifetime totals accurate#782

Merged
arul28 merged 11 commits into
mainfrom
ade-117-compare-ade-usage-tracking-with-codexbar-and-improve-provider-coverage
Jul 10, 2026
Merged

ADE-117: Make usage refresh reliable and lifetime totals accurate#782
arul28 merged 11 commits into
mainfrom
ade-117-compare-ade-usage-tracking-with-codexbar-and-improve-provider-coverage

Conversation

@arul28

@arul28 arul28 commented Jul 10, 2026

Copy link
Copy Markdown
Owner

Summary

  • Separate live Claude/Codex quota refresh from expensive historical ledger scans, with phase timing, coalescing, adaptive cadence, bounded fallbacks, and explicit stale/source/auth state.
  • Rebuild historical activity across Claude, Codex, Cursor, Gemini, Droid, OpenCode, and Copilot, with provider/model breakdowns and exact-versus-estimated metadata.
  • Make All the default activity range on desktop and iOS, and show the actual combined lifetime total instead of a capped milestone badge.
  • Reconcile Codex JSONL detail with Codex Desktop's read-only thread index and archived sessions, adding only missing per-thread remainder without fabricating cost.
  • Carry quota and historical activity parity through desktop, CLI/TUI, remote runtime, and iOS.

Measured baseline

Fresh machine-local all-time scan on 2026-07-10:

  • Combined providers: 119,818,895,708 tokens
  • Codex: 103,255,910,895
  • Claude: 13,281,430,346
  • Droid: 3,263,490,634
  • Cursor, Gemini, OpenCode, and Copilot: remaining tracked total

Native token sources remain exact where available; providers without native token totals remain explicitly labeled as estimates.

Verification

  • /quality dual review passed with no remaining Medium-or-higher findings; the integrated stats branch also includes its quality pass.
  • Desktop typecheck, production build, lint (0 errors), targeted usage/service/renderer tests, and CI-style desktop shards passed; one unchanged sync-host timeout was reproduced on origin/main.
  • CLI typecheck/build and full 1,695-test suite passed; headless, socket, and remote usage paths passed.
  • iOS simulator build and focused mobile quota/activity decoding tests passed.
  • Documentation validation passed for 178 files.
  • Fresh local lifetime scan produced the combined baseline above.

Fixes ADE-117

Open in ADE

Greptile Summary

This PR makes usage refresh and historical activity reporting more reliable across ADE surfaces. The main changes are:

  • Separates live Claude/Codex quota refresh from provider history scans.
  • Adds provider freshness, stale/source/auth state, and quota snapshot commands.
  • Rebuilds provider-ledger activity totals with all-time ranges and provider/model breakdowns.
  • Updates desktop, CLI/TUI, remote sync, and iOS usage views to show the expanded activity data.

Confidence Score: 4/5

Mostly safe to merge after fixing the scoped mobile usage request.

The desktop and CLI refresh split is well covered, but the iOS stats request drops the new scope parameter and can show machine-wide provider totals in project views.

apps/ios/ADE/Services/SyncService.swift

T-Rex T-Rex Logs

What T-Rex did

  • Verified via the generated Node harness that the iOS fetchAdeUsageStats request is constructed with preset today and no scope, and that the host forwards and normalizes missing scope to machine with totals outside the project scope.
  • Validated that swift and xcodebuild are unavailable in this sandbox, so the repro used the source-level mobile harness plus handler simulation.
  • Ran the desktop usage tests; the command, working directory, and exit code show all 30 tests passing.
  • Observed a real Vite renderer launch and a Playwright navigation timeout when attempting to capture the usage surface.
  • Collected desktop capture artifacts including a Playwright renderer video and a poster image, along with related logs that document the capture attempts and UI state.

View all artifacts

T-Rex Ran code and verified through T-Rex

Important Files Changed

Filename Overview
apps/desktop/src/main/services/usage/usageTrackingService.ts Splits live quota polling from historical ledger refreshes, adds provider freshness state, and builds richer all-range usage stats.
apps/desktop/src/shared/types/usage.ts Extends usage contracts with scope, all-time breakdowns, freshness, and quota provider status metadata.
apps/desktop/src/renderer/components/settings/AdeUsageSection.tsx Reworks desktop usage settings around scoped ranges, quota refresh, activity charts, and provider/model breakdowns.
apps/desktop/src/renderer/components/usage/ActivityModule.tsx Adds the tabbed activity visualization with all-time default, persisted state, heatmap, and token/code/client summaries.
apps/ade-cli/src/services/sync/syncRemoteCommandService.ts Adds remote quota snapshot/refresh commands and validates/passes usage stats scope for remote clients.
apps/ade-cli/src/cli.ts Separates CLI live quota refresh from explicit historical usage scans via --history.
apps/ios/ADE/Services/SyncService.swift Adds mobile usage stats and quota remote-command fetches, but usage stats requests omit the new project scope.
apps/ios/ADE/Views/Work/WorkUsageActivityCarousel.swift Replaces the iOS usage carousel with a tabbed all-range activity module and live limits display.

Sequence Diagram

%%{init: {'theme': 'neutral'}}%%
sequenceDiagram
participant UI as Desktop/iOS/TUI usage UI
participant Remote as Sync remote command
participant Usage as UsageTrackingService
participant Quota as Claude/Codex quota APIs
participant Ledgers as Local provider ledgers
participant GitHub as GitHub activity scan

UI->>Remote: usage.getQuotaSnapshot / usage.refreshQuota
Remote->>Usage: getUsageSnapshot() / forceRefresh()
Usage->>Quota: poll live quota windows
Quota-->>Usage: windows + provider status
Usage-->>UI: UsageSnapshot

UI->>Remote: usage.getAdeStats(preset, scope)
Remote->>Usage: "getAdeUsageStats({preset, scope})"
Usage-->>UI: cached stats
Usage->>Ledgers: refreshHistory() when provider costs are stale
Usage->>GitHub: scan range when GitHub cache is stale
Ledgers-->>Usage: provider/model breakdowns
GitHub-->>Usage: refreshed usage update
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
sequenceDiagram
participant UI as Desktop/iOS/TUI usage UI
participant Remote as Sync remote command
participant Usage as UsageTrackingService
participant Quota as Claude/Codex quota APIs
participant Ledgers as Local provider ledgers
participant GitHub as GitHub activity scan

UI->>Remote: usage.getQuotaSnapshot / usage.refreshQuota
Remote->>Usage: getUsageSnapshot() / forceRefresh()
Usage->>Quota: poll live quota windows
Quota-->>Usage: windows + provider status
Usage-->>UI: UsageSnapshot

UI->>Remote: usage.getAdeStats(preset, scope)
Remote->>Usage: "getAdeUsageStats({preset, scope})"
Usage-->>UI: cached stats
Usage->>Ledgers: refreshHistory() when provider costs are stale
Usage->>GitHub: scan range when GitHub cache is stale
Ledgers-->>Usage: provider/model breakdowns
GitHub-->>Usage: refreshed usage update
Loading

Comments Outside Diff (1)

  1. apps/ios/ADE/Services/SyncService.swift, line 10554-10560 (link)

    P1 Project scope is dropped
    usage.getAdeStats now accepts scope, but this request sends only preset, so the host falls back to the machine-wide default. In a project-scoped Work view, iOS receives provider-ledger tokens from every local project and shows incorrect lifetime/range totals for the selected workspace.

    Artifacts

    Repro: generated harness extracting the iOS request and exercising missing-scope host default behavior

    • Contains supporting evidence from the run (text/javascript; charset=utf-8).

    Repro: harness output showing usage.getAdeStats args omit scope and normalize to machine scope

    • Keeps the command output available without making the summary code-heavy.

    Repro: native iOS tool availability check showing swift and xcodebuild are unavailable

    • Keeps the command output available without making the summary code-heavy.

    View artifacts

    T-Rex Ran code and verified through T-Rex

    Prompt To Fix With AI
    This is a comment left during a code review.
    Path: apps/ios/ADE/Services/SyncService.swift
    Line: 10554-10560
    
    Comment:
    **Project scope is dropped**
    `usage.getAdeStats` now accepts `scope`, but this request sends only `preset`, so the host falls back to the machine-wide default. In a project-scoped Work view, iOS receives provider-ledger tokens from every local project and shows incorrect lifetime/range totals for the selected workspace.
    
    How can I resolve this? If you propose a fix, please make it concise.

    Fix in Claude Code

Fix All in Claude Code

Prompt To Fix All With AI
Fix the following 1 code review issue. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 1
apps/ios/ADE/Services/SyncService.swift:10554-10560
**Project scope is dropped**
`usage.getAdeStats` now accepts `scope`, but this request sends only `preset`, so the host falls back to the machine-wide default. In a project-scoped Work view, iOS receives provider-ledger tokens from every local project and shows incorrect lifetime/range totals for the selected workspace.

Reviews (4): Last reviewed commit: "fix(usage): preserve polling and RPC fal..." | Re-trigger Greptile

arul28 and others added 3 commits July 10, 2026 13:57
ADE-113: wire db into prod usage service, per-day input/output/cache split,
local-timezone day keys (DST-safe), codeburn-parity dedup (cross-file message
ids, streaming keep-last, codex fork replay), ADE-originated attribution with
symmetric inclusion, machine/project scope toggle, labeled github-vs-local
activity groups (no Math.max merges), estimation flags, GitHub PR scan
early-out. 14 new named regression tests.

ADE-114: tabbed ActivityModule (compact/full) replaces the carousel on the
new-chat surface and Settings > Stats; sectioned Stats dashboard with scope
toggle, unified range vocabulary, quiet meta footer; provider brand color
tokens; streak/milestone chip; warm empty state; event-driven refresh; hero
moved up with logo glow removed.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Tabbed card parity with desktop (named tabs, unified range vocab incl. All,
input/output/cache token split, GitHub underlay on code bars, tap tooltips,
warm empty state, streak/milestone chip, skeleton loading, flat card without
glow). Hero scooted up and logo glow removed to match. RemoteModels decodes
the new optional daily fields.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Five-provider hand-computed fixture (resume/stream dedup, fork replay,
project scope, ADE attribution, estimation flags, local midnight, DST).
Oracle script (scripts/usage-oracle.mjs) diffs ADE token totals against
codeburn JSON on real ledgers: claude exact-match on closed ranges; codex
delta fully attributed to ADE-originated inclusion (external-only <0.5%).
Accuracy fixes from oracle findings: recursive claude subagents/** scan,
removed codex 14d/250-file/32MiB caps, cached-input double count, reasoning
tokens separated from displayed output.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@linear-code

linear-code Bot commented Jul 10, 2026

Copy link
Copy Markdown

ADE-117

@vercel

vercel Bot commented Jul 10, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
ade Ignored Ignored Preview Jul 10, 2026 8:53pm

@coderabbitai

coderabbitai Bot commented Jul 10, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@arul28, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 28 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 9b77a387-7a0e-4a13-bc0e-63dedb3e37b6

📥 Commits

Reviewing files that changed from the base of the PR and between c0e2ef0 and d095d65.

⛔ Files ignored due to path filters (10)
  • apps/ios/ADE.xcodeproj/project.pbxproj is excluded by !**/*.xcodeproj/project.pbxproj
  • docs/ARCHITECTURE.md is excluded by !docs/**
  • docs/features/chat/README.md is excluded by !docs/**
  • docs/features/chat/composer-and-ui.md is excluded by !docs/**
  • docs/features/onboarding-and-settings/README.md is excluded by !docs/**
  • docs/features/onboarding-and-settings/usage-tracking.md is excluded by !docs/**
  • docs/features/sync-and-multi-device/README.md is excluded by !docs/**
  • docs/features/sync-and-multi-device/ios-companion.md is excluded by !docs/**
  • docs/features/sync-and-multi-device/remote-commands.md is excluded by !docs/**
  • docs/features/web-client/README.md is excluded by !docs/**
📒 Files selected for processing (48)
  • apps/ade-cli/README.md
  • apps/ade-cli/src/adeRpcServer.test.ts
  • apps/ade-cli/src/bootstrap.ts
  • apps/ade-cli/src/cli.test.ts
  • apps/ade-cli/src/cli.ts
  • apps/ade-cli/src/services/sync/syncRemoteCommandService.test.ts
  • apps/ade-cli/src/services/sync/syncRemoteCommandService.ts
  • apps/ade-cli/src/services/sync/syncService.test.ts
  • apps/ade-cli/src/tuiClient/__tests__/RightPane.usage.test.tsx
  • apps/ade-cli/src/tuiClient/__tests__/commands.test.ts
  • apps/ade-cli/src/tuiClient/app.tsx
  • apps/ade-cli/src/tuiClient/commands.ts
  • apps/ade-cli/src/tuiClient/components/UsagePane.tsx
  • apps/ade-cli/src/tuiClient/types.ts
  • apps/desktop/scripts/usage-oracle.mjs
  • apps/desktop/src/main/main.ts
  • apps/desktop/src/main/services/adeActions/registry.ts
  • apps/desktop/src/main/services/ai/providerCredentialSources.ts
  • apps/desktop/src/main/services/ipc/registerIpc.ts
  • apps/desktop/src/main/services/usage/ledgers/localUsageLedgers.ts
  • apps/desktop/src/main/services/usage/localDay.ts
  • apps/desktop/src/main/services/usage/usageEndToEnd.test.ts
  • apps/desktop/src/main/services/usage/usageProviderStrategies.ts
  • apps/desktop/src/main/services/usage/usageStatsStore.ts
  • apps/desktop/src/main/services/usage/usageTrackingService.test.ts
  • apps/desktop/src/main/services/usage/usageTrackingService.ts
  • apps/desktop/src/preload/global.d.ts
  • apps/desktop/src/preload/preload.test.ts
  • apps/desktop/src/preload/preload.ts
  • apps/desktop/src/renderer/browserMock.ts
  • apps/desktop/src/renderer/components/chat/AgentChatPane.tsx
  • apps/desktop/src/renderer/components/settings/AdeUsageSection.tsx
  • apps/desktop/src/renderer/components/usage/ActivityModule.tsx
  • apps/desktop/src/renderer/components/usage/HeaderUsageControl.tsx
  • apps/desktop/src/renderer/components/usage/UsageActivityCarousel.tsx
  • apps/desktop/src/renderer/components/usage/UsageQuotaPanel.tsx
  • apps/desktop/src/renderer/components/usage/providerColors.ts
  • apps/desktop/src/renderer/components/usage/usage.test.tsx
  • apps/desktop/src/shared/ipc.ts
  • apps/desktop/src/shared/types/sync.ts
  • apps/desktop/src/shared/types/usage.ts
  • apps/ios/ADE/Models/RemoteModels.swift
  • apps/ios/ADE/Services/MobileUsageQuotaStore.swift
  • apps/ios/ADE/Services/SyncService.swift
  • apps/ios/ADE/Views/Settings/ConnectionSettingsView.swift
  • apps/ios/ADE/Views/Work/WorkNewChatScreen.swift
  • apps/ios/ADE/Views/Work/WorkUsageActivityCarousel.swift
  • apps/ios/ADETests/ADETests.swift
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch ade-117-compare-ade-usage-tracking-with-codexbar-and-improve-provider-coverage

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.

@arul28 arul28 changed the title ADE-117 Compare ADE usage tracking with CodexBar and improve provider coverage -> Primary ADE-117: Make usage refresh reliable across desktop, CLI, and mobile Jul 10, 2026
@arul28

arul28 commented Jul 10, 2026

Copy link
Copy Markdown
Owner Author

@copilot review but do not make fixes

arul28 and others added 3 commits July 10, 2026 14:56
Correctness (three-perspective review): PR pagination now orders/stops on
UPDATED_AT so long-lived PRs merged in-range are counted; GitHub-only
background refresh emits usage.onUpdate so Stats stops showing stale zeros;
empty-state predicate counts GitHub-only days; daily bucket scans capped at
250k newest rows with debug log. Judo: explicit scope branches in
buildCostSnapshots, shared RANGE_OPTIONS, dead export + doc fix in
providerColors, toDate helper in localDay.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Host-side sync command usage.getAdeStats now validates and forwards the new
scope arg (was silently dropped; regression test added). Internal docs
updated for the sectioned Stats dashboard, ActivityModule, localDay helpers,
provider colors, and the scope/estimation/github-vs-local contracts. TUI and
mobile verified in lockstep with no changes required.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@arul28 arul28 force-pushed the ade-117-compare-ade-usage-tracking-with-codexbar-and-improve-provider-coverage branch from 3157b8b to 64a5a8e Compare July 10, 2026 19:10
@arul28

arul28 commented Jul 10, 2026

Copy link
Copy Markdown
Owner Author

@copilot review but do not make fixes

arul28 and others added 2 commits July 10, 2026 15:44
Heatmap cells now scale to the box: one tall row for <=7 points, 7-row
calendar grid for longer ranges. Active tab with an all-zero series shows a
muted hint while keeping the legend, instead of a bare chart. iOS hasActivity
made github-aware to match desktop.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@arul28

arul28 commented Jul 10, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@arul28 arul28 changed the title ADE-117: Make usage refresh reliable across desktop, CLI, and mobile ADE-117: Make usage refresh reliable and lifetime totals accurate Jul 10, 2026

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e5c968e011

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

Comment thread apps/ade-cli/src/services/sync/syncRemoteCommandService.ts
@arul28

arul28 commented Jul 10, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 02b15d04d2

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

Comment thread apps/desktop/src/main/services/usage/usageTrackingService.ts Outdated
Comment thread apps/desktop/src/renderer/components/usage/ActivityModule.tsx Outdated
@arul28

arul28 commented Jul 10, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3df0c90997

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

Comment thread apps/desktop/src/main/services/usage/usageTrackingService.ts Outdated
Comment thread apps/desktop/src/main/services/usage/usageTrackingService.ts
@arul28 arul28 merged commit 3bf54cc into main Jul 10, 2026
31 checks passed
@arul28 arul28 deleted the ade-117-compare-ade-usage-tracking-with-codexbar-and-improve-provider-coverage branch July 10, 2026 20:59
arul28 added a commit that referenced this pull request Jul 10, 2026
Union merge: keeps ADE-117's quota snapshot/refresh commands, refresh
reliability, and lifetime-total accuracy alongside this lane's newer
ADE-113/114 pipeline and UI work (day-granular custom ranges, IPC
validation, exact-range ADE attribution, heatmap fill, iOS tabbed module).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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