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
{{ message }}
Repository navigation
fix(opencode): Usage → Limits shows why OpenCode could not read usage - #40340
When OpenCode cannot read Console usage, for example because an expired Console login makes opencode.ai answer 401, Usage → Limits showed only "OpenCode could not read workspace usage." and no cause. It now shows the error message OpenCode returns for a non-2xx usage response, and falls back to the generic text when the response has no message.
Commit 7ef7ba0 (origin/main). Installed @opencode/cli@2.3.2 in a scratch HOME/XDG_DATA_HOME and imported a fake OpenCode Console credential (opencode auth import, integration opencode, type key, invalid token, metadata.orgID set), so opencode auth list shows OpenCode Console Personal stored. Direct opencode serve + GET /api/experimental/usage/limits?location[directory]=/tmp returned 503 {"_tag":"ServiceUnavailableError","message":"OpenCode Console budgets are unavailable: StatusCode: non 2xx status code (401 GET https://opencode.ai/console/api/policies/current-budgets)","service":"opencode"}, matching the report. Then ran T3CODE_DEV_SEED=0 vp run dev with that OpenCode on PATH and the same XDG dirs, paired the web client, added an OpenCode instance via Settings → Providers → Add provider (status became v2.3.2 · Authenticated), opened Usage → Limits (All environments / All providers) and clicked Refresh limits. The UI showed only OpenCode: OpenCode could not read workspace usage.; T3's server.trace.ndjson recorded the call with http.response.status_code 503 and exit HttpClientError: StatusCode error (503 GET …/api/experimental/usage/limits). Failing test: an added row in the existing 'distinguishes missing endpoints, signed out, and failed remote probes' table in OpenCode2Client.test.ts (503 with OpenCode's ServiceUnavailableError body); on main it fails with expected 'OpenCode could not read workspace usa…' to include 'OpenCode Console budgets'.
Evidence
Being captured: before and after in the real app. This section is filled in before the pull request can merge.
Tests
vp test run src/server/v2/OpenCode2Client.test.ts with the fix stashed: fails with expected 'OpenCode could not read workspace usa…' to include 'OpenCode Console budgets' (the repro)
vp test run src/server/v2/OpenCode2Client.test.ts src/server/driver.test.ts (packages/provider-opencode): 58/58 passed
vp run check:changed: format, lint, knip, typecheck (10 packages) and tests (2 files) all passed
Not in this change
The catch-all in driver.ts checkUsageLimits still shows the generic text for transport failures and timeouts, where there is no OpenCode error body to report.
The /api/provider lookup inside the usage probe still silently becomes an empty list on any error.
Who did the work
Written by Claude Opus 5.5, in Claude Code
Reviewed by GPT-6.1 Sol, in Codex, and by Claude Opus 5.5, each on its own
Proof captured by GPT-6.1 Sol and checked by Claude Opus 5.5
Reproduces #40331: an OpenCode 2 server answers 503 with the upstream
Console 401 in its body, and T3 shows only the generic warning.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
When OpenCode answers the usage-limits request with an error status, show
the message from its JSON error body (for example the Console 401 behind an
expired login) instead of the generic warning.
Fixes#40331
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
No actionable comments were generated in the recent review.
Walkthrough
The OpenCode usage-limits probe now reports a non-2xx response’s trimmed JSON error message when available. It uses a shared fallback message when the error body is invalid or its message is blank. Tests cover a 503 response.
Non-2xx responses return unavailable limits with reason probeFailed and use a trimmed error message when present. Invalid or blank messages use a shared fallback, which the timeout fallback also uses. Tests cover a 503 response and its error message.
This change shows OpenCode's own error message in Usage → Limits when the probe fails, and keeps the generic text when no message is available. It is a narrow, low-risk improvement and is ready to merge.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
The title names the main change: the Usage → Limits view now shows why OpenCode could not read usage, which matches the usageLimits.ts and test changes that surface the non-2xx error message. It uses …
Description check
The description follows the template. It states the problem with expected behavior and reproduction context, explains the change, links the issue (#40331), and gives detailed verificat…
Linked Issues check
[#40331] The issue asks that Usage → Limits show OpenCode's error message, or otherwise explain the Console 401, when the usage-limits probe fails. In packages/provider-opencode/src/server/v2/usageLim…
Out of Scope Changes check
The whole-PR diff against the merge base 7ef7ba0 touches the usage-limits probe in usageLimits.ts and its test in OpenCode2Client.test.ts. The changes add the non-2xx error-body path, a shared prob…
Full details: Title check
Explanation
The title names the main change: the Usage → Limits view now shows why OpenCode could not read usage, which matches the usageLimits.ts and test changes that surface the non-2xx error message. It uses the conventional commit format and is specific.
Full details: Description check
Explanation
The description follows the template. It states the problem with expected behavior and reproduction context, explains the change, links the issue (#40331), and gives detailed verification with test commands and results. It also includes a Not in this change section and the agent/model attribution. The Evidence section is explicitly still pending, with before/after app captures not yet attached. That is a required UI-change item, but the rest of the description is complete, so the check passes with a note.
Full details: Linked Issues check
Explanation
[#40331] The issue asks that Usage → Limits show OpenCode's error message, or otherwise explain the Console 401, when the usage-limits probe fails. In packages/provider-opencode/src/server/v2/usageLimits.ts, the diff now handles non-2xx responses before the success path. It decodes the JSON body with ErrorBody and returns makeUnavailableUsageLimits with reason "probeFailed" and the trimmed body message. If the body is not valid JSON or the message is blank, it falls back to "OpenCode could not read workspace usage.". The OpenCode2Client.test.ts table gained a 503 ServiceUnavailableError row that asserts the message includes "OpenCode Console budgets". The reported v2 path is covered. The issue's secondary catch-all in driver.ts (transport failures and timeouts) is unchanged. The PR states this is intentional, because those failures have no OpenCode error body. The issue does not require a change there for the reported 503 case. The issue's optional login/logout suggestion is not implemented, but the issue presents it as one alternative, not a requirement. The test results in the PR description were not re-run here. The code diff supports the claimed behavior.
Full details: Out of Scope Changes check
Explanation
The whole-PR diff against the merge base 7ef7ba0 touches the usage-limits probe in usageLimits.ts and its test in OpenCode2Client.test.ts. The changes add the non-2xx error-body path, a shared probeFailedMessage constant that replaces the inline string in the probe and timeout fallbacks, and one test row. All of these support the issue's requirement to surface OpenCode's error message. No unrelated changes were seen in the inspected diff. The PR description's other files (driver.ts, /api/provider lookup) are left unchanged and are named as out of scope.
Finishing Touches
Generate unit tests (beta)
Commit to this branch
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.
This branch has not been deployed
No deployments
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
size:S10-29 changed lines (additions + deletions).vouch:trustedAuthor is trusted by repo permissions or the VOUCHED list.
1 participant
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When OpenCode cannot read Console usage, for example because an expired Console login makes opencode.ai answer 401, Usage → Limits showed only "OpenCode could not read workspace usage." and no cause. It now shows the error message OpenCode returns for a non-2xx usage response, and falls back to the generic text when the response has no message.
Fixes #40331
Reproduction on main
Commit 7ef7ba0 (origin/main). Installed @opencode/cli@2.3.2 in a scratch HOME/XDG_DATA_HOME and imported a fake OpenCode Console credential (
opencode auth import, integrationopencode, type key, invalid token, metadata.orgID set), soopencode auth listshowsOpenCode Console Personal stored. Directopencode serve+GET /api/experimental/usage/limits?location[directory]=/tmpreturned503 {"_tag":"ServiceUnavailableError","message":"OpenCode Console budgets are unavailable: StatusCode: non 2xx status code (401 GET https://opencode.ai/console/api/policies/current-budgets)","service":"opencode"}, matching the report. Then ranT3CODE_DEV_SEED=0 vp run devwith that OpenCode on PATH and the same XDG dirs, paired the web client, added an OpenCode instance via Settings → Providers → Add provider (status becamev2.3.2 · Authenticated), opened Usage → Limits (All environments / All providers) and clicked Refresh limits. The UI showed onlyOpenCode: OpenCode could not read workspace usage.; T3's server.trace.ndjson recorded the call with http.response.status_code 503 and exitHttpClientError: StatusCode error (503 GET …/api/experimental/usage/limits). Failing test: an added row in the existing 'distinguishes missing endpoints, signed out, and failed remote probes' table in OpenCode2Client.test.ts (503 with OpenCode's ServiceUnavailableError body); on main it fails withexpected 'OpenCode could not read workspace usa…' to include 'OpenCode Console budgets'.Evidence
Being captured: before and after in the real app. This section is filled in before the pull request can merge.
Tests
vp test run src/server/v2/OpenCode2Client.test.tswith the fix stashed: fails withexpected 'OpenCode could not read workspace usa…' to include 'OpenCode Console budgets'(the repro)vp test run src/server/v2/OpenCode2Client.test.ts src/server/driver.test.ts(packages/provider-opencode): 58/58 passedvp run check:changed: format, lint, knip, typecheck (10 packages) and tests (2 files) all passedNot in this change
checkUsageLimitsstill shows the generic text for transport failures and timeouts, where there is no OpenCode error body to report./api/providerlookup inside the usage probe still silently becomes an empty list on any error.Who did the work
Run by the t3code factory in T3 Code.