Skip to content

fix(opencode): Usage → Limits shows why OpenCode could not read usage - #40340

Open
juliusmarminge wants to merge 2 commits into
mainfrom
factory/issue-40331
Open

juliusmarminge wants to merge 2 commits into
mainfrom
factory/issue-40331

Conversation

@juliusmarminge

Copy link
Copy Markdown
Member

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, 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

Run by the t3code factory in T3 Code.

juliusmarminge and others added 2 commits November 21, 2026 12:58
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>
@github-actions github-actions Bot added vouch:trusted Author is trusted by repo permissions or the VOUCHED list. size:S 10-29 changed lines (additions + deletions). labels Nov 21, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Thread transfer impact

✅ Thread transfer remains within every enforced ceiling.

Provider Metric Main baseline This PR Impact PR ceiling
Codex Total thread wire 5.0 KiB 5.0 KiB 0 B (0.0%) 6.8 KiB ✅
Codex Thread snapshot wire 3.8 KiB 3.8 KiB 0 B (0.0%) 4.9 KiB ✅
Codex Live turn WebSocket wire 1.2 KiB 1.2 KiB 0 B (0.0%) 2.0 KiB ✅
Codex Live turn WebSocket decoded 21.5 KiB 21.5 KiB 0 B (0.0%) 24.4 KiB ✅
Codex Live turn messages 1 1 0 (0.0%) 8 ✅
Claude Total thread wire 5.0 KiB 5.0 KiB 0 B (0.0%) 6.8 KiB ✅
Claude Thread snapshot wire 3.8 KiB 3.8 KiB 0 B (0.0%) 4.9 KiB ✅
Claude Live turn WebSocket wire 1.2 KiB 1.2 KiB 0 B (0.0%) 2.0 KiB ✅
Claude Live turn WebSocket decoded 21.9 KiB 21.9 KiB 0 B (0.0%) 24.4 KiB ✅
Claude Live turn messages 1 1 0 (0.0%) 8 ✅

Other scenarios

All 64 scenario measurements match main.

All 64 scenario measurements
Provider Scenario Metric Main baseline This PR Impact PR ceiling
Codex short turn resume WebSocket decoded 10.5 KiB 10.5 KiB 0 B (0.0%) 12.7 KiB ✅
Codex short turn resume WebSocket messages 2 2 0 (0.0%) 2 ✅
Codex long turn running, cold open HTTP decoded 281.7 KiB 281.7 KiB 0 B (0.0%) 302.7 KiB ✅
Codex long turn running, cold open rows 75 75 0 (0.0%) 75 ✅
Codex long turn running, history page HTTP decoded 92.4 KiB 92.4 KiB 0 B (0.0%) 107.4 KiB ✅
Codex long turn running, history page rows 75 75 0 (0.0%) 75 ✅
Codex long turn finished, cold open HTTP decoded 381.5 KiB 381.5 KiB 0 B (0.0%) 410.2 KiB ✅
Codex long turn finished, cold open rows 151 151 0 (0.0%) 151 ✅
Codex long turn finished, socket cold open WebSocket decoded 381.6 KiB 381.6 KiB 0 B (0.0%) 410.2 KiB ✅
Codex long turn finished, socket cold open WebSocket messages 2 2 0 (0.0%) 2 ✅
Codex long turn finished, socket cold open rows 151 151 0 (0.0%) 151 ✅
Codex long turn finished, work page HTTP decoded 186.2 KiB 186.2 KiB 0 B (0.0%) 200.2 KiB ✅
Codex long turn finished, work page rows 150 150 0 (0.0%) 150 ✅
Codex idle thread resume WebSocket decoded 65 B 65 B 0 B (0.0%) 200 B ✅
Codex idle thread resume WebSocket messages 1 1 0 (0.0%) 1 ✅
Codex fleet shell snapshot HTTP decoded 42.4 KiB 42.4 KiB 0 B (0.0%) 53.7 KiB ✅
Codex fleet shell snapshot rows 27 27 0 (0.0%) 27 ✅
Codex fleet shell subscribe WebSocket decoded 65 B 65 B 0 B (0.0%) 200 B ✅
Codex fleet shell subscribe WebSocket messages 1 1 0 (0.0%) 1 ✅
Codex fleet shell resume check HTTP decoded 18 B 18 B 0 B (0.0%) 100 B ✅
Codex fleet shell resume check rows 0 0 0 0 ✅
Codex stale shell reload HTTP decoded 42.4 KiB 42.4 KiB 0 B (0.0%) 53.7 KiB ✅
Codex stale shell reload rows 27 27 0 (0.0%) 27 ✅
Codex stale shell resume WebSocket decoded 140 B 140 B 0 B (0.0%) 400 B ✅
Codex stale shell resume WebSocket messages 2 2 0 (0.0%) 2 ✅
Codex stale todo list cold open HTTP decoded 72.4 KiB 72.4 KiB 0 B (0.0%) 83.0 KiB ✅
Codex stale todo list cold open rows 75 75 0 (0.0%) 75 ✅
Codex stale todo list cold open nodes 2 2 0 (0.0%) 4 ✅
Codex stale todo list cold open subagents 2 2 0 (0.0%) 4 ✅
Codex stale todo list cold open plans 1 1 0 (0.0%) 2 ✅
Codex stale todo list cold open providerTurns 1 1 0 (0.0%) 2 ✅
Codex stale todo list cold open checkpoints 1 1 0 (0.0%) 2 ✅
Claude short turn resume WebSocket decoded 10.6 KiB 10.6 KiB 0 B (0.0%) 12.7 KiB ✅
Claude short turn resume WebSocket messages 2 2 0 (0.0%) 2 ✅
Claude long turn running, cold open HTTP decoded 283.3 KiB 283.3 KiB 0 B (0.0%) 302.7 KiB ✅
Claude long turn running, cold open rows 75 75 0 (0.0%) 75 ✅
Claude long turn running, history page HTTP decoded 93.4 KiB 93.4 KiB 0 B (0.0%) 107.4 KiB ✅
Claude long turn running, history page rows 75 75 0 (0.0%) 75 ✅
Claude long turn finished, cold open HTTP decoded 384.2 KiB 384.2 KiB 0 B (0.0%) 410.2 KiB ✅
Claude long turn finished, cold open rows 151 151 0 (0.0%) 151 ✅
Claude long turn finished, socket cold open WebSocket decoded 384.3 KiB 384.3 KiB 0 B (0.0%) 410.2 KiB ✅
Claude long turn finished, socket cold open WebSocket messages 2 2 0 (0.0%) 2 ✅
Claude long turn finished, socket cold open rows 151 151 0 (0.0%) 151 ✅
Claude long turn finished, work page HTTP decoded 188.1 KiB 188.1 KiB 0 B (0.0%) 200.2 KiB ✅
Claude long turn finished, work page rows 150 150 0 (0.0%) 150 ✅
Claude idle thread resume WebSocket decoded 66 B 66 B 0 B (0.0%) 200 B ✅
Claude idle thread resume WebSocket messages 1 1 0 (0.0%) 1 ✅
Claude fleet shell snapshot HTTP decoded 43.0 KiB 43.0 KiB 0 B (0.0%) 53.7 KiB ✅
Claude fleet shell snapshot rows 27 27 0 (0.0%) 27 ✅
Claude fleet shell subscribe WebSocket decoded 66 B 66 B 0 B (0.0%) 200 B ✅
Claude fleet shell subscribe WebSocket messages 1 1 0 (0.0%) 1 ✅
Claude fleet shell resume check HTTP decoded 18 B 18 B 0 B (0.0%) 100 B ✅
Claude fleet shell resume check rows 0 0 0 0 ✅
Claude stale shell reload HTTP decoded 43.0 KiB 43.0 KiB 0 B (0.0%) 53.7 KiB ✅
Claude stale shell reload rows 27 27 0 (0.0%) 27 ✅
Claude stale shell resume WebSocket decoded 140 B 140 B 0 B (0.0%) 400 B ✅
Claude stale shell resume WebSocket messages 2 2 0 (0.0%) 2 ✅
Claude stale todo list cold open HTTP decoded 73.4 KiB 73.4 KiB 0 B (0.0%) 83.0 KiB ✅
Claude stale todo list cold open rows 75 75 0 (0.0%) 75 ✅
Claude stale todo list cold open nodes 2 2 0 (0.0%) 4 ✅
Claude stale todo list cold open subagents 2 2 0 (0.0%) 4 ✅
Claude stale todo list cold open plans 1 1 0 (0.0%) 2 ✅
Claude stale todo list cold open providerTurns 1 1 0 (0.0%) 2 ✅
Claude stale todo list cold open checkpoints 1 1 0 (0.0%) 2 ✅

Baseline: 0775dc4 · PR result: fd5ea73 · Source CI: success

Scenario and decoded snapshot size

10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.

  • Codex decoded thread snapshot: 108.5 KiB
  • Claude decoded thread snapshot: 108.8 KiB

Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.

@coderabbitai

coderabbitai Bot commented Nov 21, 2026

Copy link
Copy Markdown
Contributor

Explain Change →

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.

Changes: OpenCode usage-limit probe errors

Layer / File(s) Summary
Usage-limit probe response handling
packages/provider-opencode/src/server/v2/usageLimits.ts, packages/provider-opencode/src/server/v2/OpenCode2Client.test.ts
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.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: tris203

Merge Risk: Minimal · up to fd5ea

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: Passed 4

Check name Status Explanation
Title check Passed 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 Passed 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 Passed [#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 Passed 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
Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 0775dc4 and fd5ea73.

Files selected for processing: 2

  • packages/provider-opencode/src/server/v2/OpenCode2Client.test.ts
  • packages/provider-opencode/src/server/v2/usageLimits.ts

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:S 10-29 changed lines (additions + deletions). vouch:trusted Author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Usage → Limits hides OpenCode Console 401 auth failure behind generic "OpenCode could not read workspace usage." warning

1 participant