fix(opencode): read the selected Go key from OpenCode 2's credential store #26165
main fromrefs/pull/26165/head·merged by maria-rcks View on GitHubProblem#
OpenCode 2 imports auth.json into its credential table once, storing the Go key under integration_id = 'opencode-go', and reads only the database after that. When a user replaces the Go key, the new key exists only in the database. T3 never reads opencode-go rows, so it keeps sending the stale auth.json key, gets 401 api_key_expired, and shows "OpenCode Go could not read usage." while OpenCode works fine.
Change#
readStoredApiKey takes the integration id and now reads both opencode and opencode-go, using the same selection query as before. The reader tries the Console key, then the stored Go key, then auth.json / OPENCODE_API_KEY. It moves to the next distinct key only on a 401 or 403. With no opencode-go rows, behavior is unchanged.
Scope and approval#
Refs #14983. This is the first fix in the maintainer triage there: read the opencode-go key from the SQLite credential table and keep calling zen/go/v1/usage. Console OAuth support is out of scope.
#16605 targets the same bug and is marked for takeover. The difference here is the fallback. #16605 always prefers the database key. This PR fixes the replaced-key case Rowan-Paul reported there, and also falls back to auth.json or OPENCODE_API_KEY when the database key is the stale one. If the takeover lands first, the fallback could be carried over to it.
Verification#
- Added a test to
status.test.ts. It fails onmainbecause T3 sends the imported key, and passes with this change. A second case checks the fallback toauth.jsonwhen the stored key is rejected. vp test run packages/provider-opencode/src/server/status.test.ts: 36/36 passed.vp run check:changed: all checks pass.- Runtime check on a copy of a real OpenCode v2.2.0 data directory (stale
auth.json, twoopencode-gorows, imported one inactive).mainreturnsprobeFailed, and this branch returns all three Go windows.
Not checked live: a Console API-key login combined with a stored Go key. Only the unit test covers that ordering.
Written by Claude Opus 5.5 in Claude Code, running inside T3 Code.
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:S
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes
Important
Review skipped#
Review was skipped as selected files did not have any reviewable changes.
Run configuration-
- Source mode: Auto
- Repository: pingdotgg/t3code
- Branch: main
- File: .coderabbit.config.ts
- Commit: 6575ce3
- Layers: Repository TS config
- Review profile: CHILL
- Plan: Advanced
- Run ID:
484ba77c-4650-4a9e-8fe3-fdd732469d73
Commits-
Reviewing files that changed from the base of the PR and between 4044c2492248d38bd1b13be444cadeb9ac758047 and 9656c0e79818d9bcc4a7b1d4c54b57414c53b4f6.
You can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
- 🔍 Trigger review
No actionable comments were generated in the recent review.
Recent review info-
Run configuration-
- Source mode: Auto
- Repository: pingdotgg/t3code
- Branch: main
- File: .coderabbit.config.ts
- Commit: 1cf14a4
- Layers: Repository TS config
- Review profile: CHILL
- Plan: Advanced
- Run ID:
1a7249da-1233-46f8-9f6f-57e47ca6425a
Commits-
Reviewing files that changed from the base of the PR and between 1cf14a498fa27712a305097012c6f8f920a6da33 and 4044c2492248d38bd1b13be444cadeb9ac758047.
Files selected for processing: 2-
packages/provider-opencode/src/server/status.test.tspackages/provider-opencode/src/server/usageLimits.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
-
The usage probe now checks stored credentials for both
opencodeandopencode-go, combines them with the Go auth-file key, and retries another distinct key after a 401 or 403. Tests cover stored-key priority and fallback.Changes: Go usage credential selection
Priority:Layer / File(s) Summary Credential selection and retry
packages/provider-opencode/src/server/usageLimits.ts,packages/provider-opencode/src/server/status.test.tsThe probe reads stored keys for both integrations, combines them with the Go auth-file key, and removes duplicates. It tries another key after a 401 or 403. Tests verify the active stored key is tried first and the imported key is tried after a 401. NormalEstimated code review effort: 2 (Simple) | ~10 minutes
Change: Bug fix
Possibly related PRs
- pingdotgg/t3code#23606: Addresses OpenCode Go usage-limit credential selection and fallback in the same server module.
Suggested reviewers:
benglennon123
Merge Risk:
Minimal · previous review4044c-
No actionable issue is identified in the Go usage credential fallback; the change is mergeable after normal checks.
Pre-merge checks:
4-
Check name Status Explanation Title check The title clearly and concisely describes the primary fix: reading the selected Go key from OpenCode 2's credential store. Linked Issues check Check skipped because no linked issues were found for this pull request. Out of Scope Changes check Check skipped because no linked issues were found for this pull request. Description check The description follows the template closely. It has Problem, Change, Scope and approval, and Verification sections, all filled in with specific content. Problem: OpenCode 2 imports auth.json once int… Full details: Description check
-
Explanation
The description follows the template closely. It has Problem, Change, Scope and approval, and Verification sections, all filled in with specific content. Problem: OpenCode 2 imports auth.json once into the credential table under integration_id 'opencode-go', and T3 never reads opencode-go rows, so it keeps sending the stale auth.json key, receives 401 api_key_expired, and shows 'OpenCode Go could not read usage.' Change: readStoredApiKey takes an integration id, reads both opencode and opencode-go, and tries Console key, then stored Go key, then auth.json/OPENCODE_API_KEY, moving on only on 401 or 403. Scope: references issue
#14983as the triaged bug, states the scope is limited to reading the opencode-go key from SQLite and keeping zen/go/v1/usage, excludes Console OAuth, and explains the relationship to competing PR#16605. Verification: a new test in status.test.ts that fails on main and passes with the change, a fallback case, 36/36 test run, check:changed passing, and a runtime check against a copy of a real OpenCode v2.2.0 data directory. It also states what was not checked live (Console API-key login combined with a stored Go key). The description also ends with the model and harness attribution the template requests. Minor gaps: the Scope section cites the maintainer triage in#14983but does not link an explicit maintainer approval comment, and the description does not say whether the Go key fallback order was approved by maintainers.
-
Finishing Touches
-
🧪 Generate unit tests (beta)
-
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
-
Note
Written by
gpt-6.1-solon behalf of MariaVerified in a real dev environment#
partial verification only. this is not a live verification of the stored go key fix.
- inspected the description, diff and discussion. the pr is open and its only commit is by nolight132.
- installed dependencies and ran github/main (
6575ce3250) in/home/user/main, then the exact pr head9656c0e79818d9bcc4a7b1d4c54b57414c53b4f6in/home/user/t3code. stopped main before running the pr. used isolated dev state. - drove the actual web client with repo playwright and
/usr/bin/google-chrome. added a project pointing at the real repo, created a thread, added the local opencode provider through settings, and clicked usage > limits > refresh. - copied only the app-created dev state into the pr environment. the pr's server websocket response reports enabled opencode with
windows: []andunavailable.reason: "unsupported", as expected without credentials. refresh completes and the page remains usable. - submitted actual codex
gpt-6.1-solturns through the web composer on main and the pr. provider logs show completed turns returningprovider-path-okandpr-provider-path-ok. both replies are visible in the pr client. main's initial client view omitted its reply; reopening the thread on the pr displayed the persisted reply. - codex limits fail with
Codex could not read usage (JSON-RPC -32600)on both main and the pr. this is a baseline limitation of this environment, not a regression established by this check. - ran
vp test run packages/provider-opencode/src/server/status.test.tsthrough blacksmith-check after installing worker dependencies: 36/36 passed. these tests use controlled HTTP responses and do not replace live go verification. existing head CI checks are green.
short server transcript from the actual client refresh:
opencode: enabled=true, usageLimits.windows=[], unavailable.reason=unsupported codex: unavailable.reason=probeFailed codex: Codex could not read usage (JSON-RPC -32600). main codex turn: model=gpt-6.1-sol, status=completed, reply=provider-path-ok pr codex turn: model=gpt-6.1-sol, status=completed, reply=pr-provider-path-okmain, without go credentials:

pr, with the same app-created data:


Not verified#
- the original stale-key bug could not be reproduced on main, and successful recovery on this pr could not be exercised. this vm has no opencode go
auth.json, noopencode.db, and noOPENCODE_*credential overrides. installed opencode is 1.19.5, while the changed store belongs to opencode 2. no real go account/key is available. codex's local proxy credentials cannot authenticatehttps://opencode.ai/zen/go/v1/usage. - selected stored go key priority, console-key coexistence, real 401/403 fallback, and returned go usage windows remain unverified against the external service. no fake keys, mock endpoint or fabricated credentials were used for runtime verification.
- native ios/android, electron desktop, macos/windows and remote/relay clients were not exercised on this linux vm.
no source changes or pushes. the outcome is unverifiable for the core fix, despite passing focused tests and available neighboring checks.
maria-rcks merged thisd8430c0
maria-rcks closed this
Sign in to join this conversation.
Approvability#
Verdict: Approved at
4044c24Macroscope's review found this PR approvable — The usage reader now recognizes OpenCode 2’s selected Go credential, retaining existing authentication fallbacks. Read-only storage access, the fixed usage endpoint and external-server exclusions keep the change contained.
You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).