Skip to content

feat(usage): include OpenCodex activity - #7939

Closed
Hylouis233 wants to merge 2 commits into
pingdotgg:mainfrom
Hylouis233:feat/opencodex-usage
Closed

Hylouis233 wants to merge 2 commits into
pingdotgg:mainfrom
Hylouis233:feat/opencodex-usage

Conversation

@Hylouis233

@Hylouis233 Hylouis233 commented Aug 22, 2026 •

Copy link
Copy Markdown
Contributor

What Changed

  • Add OpenCodex as a first-class Usage provider across the contracts, server, web, and mobile clients.
  • Read the canonical OPENCODEX_HOME/usage.jsonl ledger in a bounded worker, with 90-day window coverage metadata, durable cache reuse, request-id deduplication, and incomplete-source reporting.
  • Normalize OpenCodex account-scoped provider labels and inclusive cache accounting before pricing through the existing LiteLLM rate table.
  • Preserve rolling-upgrade compatibility: legacy clients receive v4 while compatible clients negotiate v5.

Why

OpenCodex already records authoritative per-request token usage for its command-line and desktop/tray surfaces, but T3 Code does not currently include that activity. Reading the provider-owned ledger keeps usage complete even when requests were not initiated by T3 Code and avoids summing retry attempts twice.

UI Changes

The Usage page gains an OpenCodex provider mark, chart series, table column, model breakdown, and explicit partial/failed-store notice on web and mobile. Screenshots are omitted because the populated view depends on private local usage history; there is no motion or interaction change.

Validation

  • 10 focused usage test files: 92/92 tests passed
  • Typechecks passed for t3, @t3tools/web, @t3tools/mobile, @t3tools/contracts, and @t3tools/shared
  • Focused lint, formatting, and git diff --check passed for all 25 changed files
  • Real local ledger validation: 88,479,120 bytes, 57,954 in-window records, 67 models, 651 sessions; 799 ms cold scan with a 13 ms maximum event-loop timer gap

Merge ordering

This branch is independently compatible with current main and uses usage contract v5. PRs #7877, #7904, #7936, and this PR each add a v5 provider independently; whichever merges later must rebase and advance the combined contract/cache migration as needed.

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • I included before/after screenshots for any UI changes
  • No animation/interaction change requires a video

Note

Add OpenCodex activity to usage tracking and bump contract to v5

  • Integrates OpenCodex as a new usage provider across the server, web, and mobile clients
  • Parses OpenCodex JSONL ledgers in a dedicated worker thread with a 30s timeout in usageTranscriptReader.ts to avoid blocking the server event loop
  • Introduces contract version negotiation in UsageService.ts to serve v5 to compatible clients while maintaining backward compatibility with v4
  • Updates the merge logic in usageMerge.ts to track partial or failed usage sources, and surfaces these states as warnings in the web and mobile UIs
  • Risk: Existing v2 usage scan caches are invalidated and rebuilt as v3 in usageScanCache.ts due to new OpenCodex coverage bounds

Macroscope summarized 9057972.


Note

Medium Risk
Touches the usage contract, on-disk scan cache (v2→v3), and merge ownership of duplicate stores, which can change reported totals. Also introduces an eval’d worker to parse large ledgers off the event loop.

Overview
Adds OpenCodex to usage reporting: clients advertise contract v5, the server reads OPENCODEX_HOME/usage.jsonl (default ~/.opencodex), and web/mobile charts, tables, and legends include the new provider.

The server parses the append-only ledger in a bounded worker, splits inclusive cache tokens, normalizes account-scoped provider ids, and prices via the existing LiteLLM table. Scan cache v3 stores a coverage bound so a narrower OpenCodex window can reuse a broader scan. Legacy clients still get v4 responses with OpenCodex omitted.

Source health is now ok / partial / failed instead of treating I/O errors as missing. Merge prefers a complete duplicate over a partial one, drops fully failed stores from totals, and surfaces incompleteSources in the coverage notice.

Reviewed by Cursor Bugbot for commit 9057972. Bugbot is set up for automated code reviews on this repo. Configure here.

@coderabbitai

coderabbitai Bot commented Aug 22, 2026 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 75d296be-cc67-4cd1-bfe5-0ae55081ce78

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

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.

@github-actions github-actions Bot added vouch:unvouched Author is not yet trusted in the VOUCHED list. size:XL 500-999 changed lines (additions + deletions). labels Aug 22, 2026
@Hylouis233
Hylouis233 marked this pull request as ready for review August 22, 2026 23:18
Copilot AI lite review requested due to automatic review settings August 22, 2026 23:18

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

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

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

@macroscopeapp

macroscopeapp Bot commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Skipped

Macroscope did not run approvability analysis for this PR. Macroscope could not determine whether this PR modifies its approvability configuration, so the PR was not approved automatically. A PR that may change the rules that govern approval is never approved automatically.

@t3dotgg

t3dotgg commented Aug 23, 2026

Copy link
Copy Markdown
Member

Note

🤖 GPT-5.6 Sol responding on behalf of Theo

Closing this PR after an automated pass over open pull requests. Expands usage contracts and client interfaces for a provider that the product does not support.

@t3dotgg t3dotgg closed this Aug 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XL 500-999 changed lines (additions + deletions). vouch:unvouched Author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants