You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I searched existing issues and did not find a duplicate request.
I reviewed current behavior on the production released OpenCode version.
OpenCode version reviewed
1.18.4
Problem statement
The xAI quota provider on main@2a6b919 intentionally treats OpenCode as the sole owner of OAuth refresh and auth.json persistence. It reads the latest xAI OAuth entry directly, which correctly picks up tokens refreshed by OpenCode.
However, if the stored xAI access token expires before the first xAI model request in a new OpenCode session, startup/sidebar quota collection cannot display the SuperGrok meter. It reports:
xAI OAuth token expired; use xAI in OpenCode to refresh it or reconnect xAI
After an xAI model request, OpenCode refreshes and persists the token; the next quota query succeeds. This means startup quota works only after using xAI once.
Reproduction:
Connect xAI with SuperGrok OAuth.
Let the access token expire without making another xAI model request.
Restart OpenCode or run opencode-quota show --provider xai.
Observe the expired-token error instead of the quota meter.
Send one xAI model request, then repeat the quota query; it succeeds.
Proposed change
Provide a maintainer-approved path for the quota provider to obtain a fresh xAI access token at startup while preserving OpenCode as the credential owner. Prefer one of these approaches:
an OpenCode client/API operation that asks the provider auth plugin to refresh and persist its credential; or
an OpenCode-authenticated request path that performs provider-owned refresh before the billing request.
The quota plugin should then re-read the updated xAI credential and query the existing billing endpoint. It should not duplicate OAuth refresh logic or write auth.json directly unless that ownership model is explicitly accepted.
Alternatives considered
Direct refresh and auth.json writes inside opencode-quota were prototyped in closed PR fix(provider): refresh xAI OAuth for startup quota #180. That approach was not pursued because it duplicates OpenCode OAuth logic and can race with rotating refresh tokens or concurrent auth-file updates.
Requiring one xAI model request works today, but defeats startup quota display.
Reconnecting xAI works but is unnecessary when the refresh token remains valid.
Acceptance criteria
An expired xAI access token with a valid refresh token can yield quota at startup without a preceding xAI model request.
OpenCode remains the authoritative OAuth refresher and credential writer.
Rotating refresh tokens and concurrent requests do not trigger duplicate refreshes.
OPENCODE_AUTH_CONTENT remains read-only.
No access or refresh token is exposed in logs, errors, diagnostics, or tests.
Existing xAI quota and expired-token tests are updated for the accepted architecture.
Pre-flight checks
OpenCode version reviewed
1.18.4Problem statement
The xAI quota provider on
main@2a6b919intentionally treats OpenCode as the sole owner of OAuth refresh andauth.jsonpersistence. It reads the latest xAI OAuth entry directly, which correctly picks up tokens refreshed by OpenCode.However, if the stored xAI access token expires before the first xAI model request in a new OpenCode session, startup/sidebar quota collection cannot display the SuperGrok meter. It reports:
After an xAI model request, OpenCode refreshes and persists the token; the next quota query succeeds. This means startup quota works only after using xAI once.
Reproduction:
opencode-quota show --provider xai.Proposed change
Provide a maintainer-approved path for the quota provider to obtain a fresh xAI access token at startup while preserving OpenCode as the credential owner. Prefer one of these approaches:
The quota plugin should then re-read the updated xAI credential and query the existing billing endpoint. It should not duplicate OAuth refresh logic or write
auth.jsondirectly unless that ownership model is explicitly accepted.Alternatives considered
auth.jsonwrites inside opencode-quota were prototyped in closed PR fix(provider): refresh xAI OAuth for startup quota #180. That approach was not pursued because it duplicates OpenCode OAuth logic and can race with rotating refresh tokens or concurrent auth-file updates.Acceptance criteria
OPENCODE_AUTH_CONTENTremains read-only.