Skip to content

fix(opencode): show ChatGPT allowance in Usage Limits - #22885

Closed
razzeee wants to merge 1 commit into
pingdotgg:mainfrom
razzeee:fix/opencode-chatgpt-limits
Closed

razzeee wants to merge 1 commit into
pingdotgg:mainfrom
razzeee:fix/opencode-chatgpt-limits

Conversation

@razzeee

@razzeee razzeee commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Problem

As a user signed into ChatGPT through OpenCode, Usage → Limits tells me that no provider reports subscription limits. I have to leave T3 and open chatgpt.com to see how much allowance I have left and when it resets, even though T3 already shows those limits for Codex accounts.

Fix

Extend the existing Limits workflow to local OpenCode 2 ChatGPT connections when no Go subscription is reported. Read the selected OAuth credential from OpenCode's database read-only and fetch the account's allowance windows and reset times. Identify windows by their duration, including OSS accounts whose primary window is weekly. Failed reads after an account switch cannot reuse the previous account's quota.

This supplies the existing shared limits contract used by web, desktop, mobile, and /usage-limits. External OpenCode servers, credit balances, and banked-reset redemption are outside this change. Expired logins are refreshed by OpenCode, not T3; token-sharing logins without access to the account API remain unsupported.

Scope and approval

Submitted as a focused fix for a provider-support gap in the existing Usage → Limits capability: users signed into ChatGPT through OpenCode cannot see the allowance and reset times already available to Codex users. This reuses the existing limits contract and views, with account-switch handling needed to avoid displaying another account's quota. It does not introduce a new user workflow. On that basis, this is submitted under the focused, obvious-bug exemption; no prior maintainer approval is claimed.

Verification

  • vp run check:changed passed: formatting, lint, knip, typechecking 20 affected/dependent packages, and 21 tests across three files.
  • Focused tests cover account selection, read-only database access, OSS and five-hour/weekly windows, configured database paths, disabled/remote instances, unsupported auth, malformed responses, and account switches.
  • A read-only probe using the implementation returned the signed-in account's weekly usage and reset timestamp without changing credentials or redeeming a reset.
  • No browser or native-client verification was performed; no UI components changed.

Model: GPT-6 Astra. Harness: OpenCode in T3 Code.

Read the selected local OpenCode 2 ChatGPT login to report subscription
allowance and reset times through the existing Limits views. Preserve
account identity on failed probes so switching accounts cannot reuse the
previous quota.
@github-actions github-actions Bot added vouch:unvouched Author is not yet trusted in the VOUCHED list. size:L 100-499 changed lines (additions + deletions). labels Oct 21, 2026
@macroscopeapp

macroscopeapp Bot commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Needs Human Approval

Macroscope's review found this PR requires human approval — This PR adds a new production ChatGPT allowance integration for local OpenCode v2, including local OAuth credential reads, an external authenticated request, and shared usage-state changes. Its new capability and authentication-sensitive data flow warrant human review.

You can add or adjust custom eligibility rules. Learn more.

@coderabbitai

coderabbitai Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Path: .coderabbit.config.ts
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: a868c5f6-3112-4c6e-b91f-0bc3029230e0
📥 Commits

Reviewing files that changed from the base of the PR and between 448b8a9 and fa15ee1.

📒 Files selected for processing: 6
  • docs/user/usage.md
  • packages/provider-core/src/server/usageLimits.test.ts
  • packages/provider-core/src/server/usageLimits.ts
  • packages/provider-opencode/src/server/chatGptUsageLimits.test.ts
  • packages/provider-opencode/src/server/chatGptUsageLimits.ts
  • packages/provider-opencode/src/server/driver.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

📝 Walkthrough

OpenCode v2 now retrieves ChatGPT usage limits from local credentials when the Go usage reader reports unsupported. Credential-aware resolution clears previously published limits when the selected account changes. Documentation and tests cover the retrieval conditions and account-change behavior.

Changes: ChatGPT Usage Limit Discovery

Layer / File(s) Summary
Local credential discovery and usage probing
packages/provider-opencode/src/server/chatGptUsageLimits.ts, packages/provider-opencode/src/server/chatGptUsageLimits.test.ts
The new reader loads and validates local OpenCode credentials, requests ChatGPT usage data, and classifies returned windows. Tests cover credential selection, request behavior, response handling, privacy, and unsupported configurations.
Provider fallback and account-change handling
packages/provider-opencode/src/server/driver.ts, packages/provider-core/src/server/usageLimits.ts, packages/provider-core/src/server/usageLimits.test.ts, packages/provider-opencode/src/server/chatGptUsageLimits.test.ts, docs/user/usage.md
Eligible OpenCode v2 checks use the ChatGPT reader when the Go usage reader reports unsupported. Changed credential fingerprints prevent previous-account limits from being retained. Tests and documentation cover fallback conditions and account changes.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant checkProvider
  participant GoUsageReader
  participant readOpenCodeChatGptUsageLimits
  participant OpenCodeSQLite
  participant ChatGPTUsageAPI
  checkProvider->>GoUsageReader: Request usage limits
  GoUsageReader-->>checkProvider: Return unsupported
  checkProvider->>readOpenCodeChatGptUsageLimits: Read eligible OpenCode v2 limits
  readOpenCodeChatGptUsageLimits->>OpenCodeSQLite: Load active credential
  OpenCodeSQLite-->>readOpenCodeChatGptUsageLimits: Return credential data
  readOpenCodeChatGptUsageLimits->>ChatGPTUsageAPI: Send authenticated usage request
  ChatGPTUsageAPI-->>readOpenCodeChatGptUsageLimits: Return usage windows
  readOpenCodeChatGptUsageLimits-->>checkProvider: Return probed limits
Loading

Suggested reviewers: maria-rcks, juliusmarminge

Merge Risk: ⚪ Minimal · up to fa15e

The identified account-switch and fallback concerns do not block merging after normal checks.

Pre-merge checks: Passed 4
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: showing ChatGPT allowance in Usage Limits for OpenCode.
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.
Description check Passed The description is complete and relevant. It explains the problem, proposed fix, scope, focused-fix exemption, verification results, limitations, and agent details. The author uses "## Fix" instead of…
Full details: Description check

Explanation

The description is complete and relevant. It explains the problem, proposed fix, scope, focused-fix exemption, verification results, limitations, and agent details. The author uses "## Fix" instead of the template's "## Change" heading, but the required information is present.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@maria-rcks

Copy link
Copy Markdown
Collaborator

Note

Written by gpt-6.1-sol on behalf of Maria

dry-run draft, no action taken.

closure is warranted under the prior approval rule. The diff adds a new OpenCode ChatGPT subscription integration that reads OAuth credentials from its database and calls the account usage API, beyond the existing Go limits reader; no triaged issue or maintainer approval establishes that expanded support scope.

Agree with a maintainer on ChatGPT support and credential-reading scope, then link explicit approval or triage establishing the intended behavior for reconsideration; retain the unsupported-limits use case and read-only probe evidence.

@maria-rcks maria-rcks closed this Oct 31, 2026
@razzeee

razzeee commented Oct 31, 2026

Copy link
Copy Markdown
Contributor Author

So which design do you want?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L 100-499 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.

2 participants