Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(opencode): read the selected Go key from OpenCode 2's credential store #26165

Mergednolight132(GitHub profile, opens in a new tab)merged 1 commit intomain fromrefs/pull/26165/headmerged by maria-rcks View on GitHub

Problem

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 on main because T3 sends the imported key, and passes with this change. A second case checks the fallback to auth.json when 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, two opencode-go rows, imported one inactive). main returns probeFailed, 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

    2. Approvability

      Verdict: Approved at 4044c24

      Macroscope'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).
    3. coderabbitai[bot](GitHub profile, opens in a new tab)commented
      Review in Change Stack →

      Important

      Review skipped

      Review was skipped as selected files did not have any reviewable changes.

      Run configuration
      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_status to false in 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
      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.ts
      • packages/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 opencode and opencode-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

      Layer / File(s)Summary
      Credential selection and retry
      packages/provider-opencode/src/server/usageLimits.ts, packages/provider-opencode/src/server/status.test.ts
      The 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.
      Priority: Normal

      Estimated 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 review 4044c

      No actionable issue is identified in the Go usage credential fallback; the change is mergeable after normal checks.

      Pre-merge checks: Passed 4
      Check nameStatusExplanation
      Title checkPassedThe title clearly and concisely describes the primary fix: reading the selected Go key from OpenCode 2's credential store.
      Linked Issues checkPassedCheck skipped because no linked issues were found for this pull request.
      Out of Scope Changes checkPassedCheck skipped because no linked issues were found for this pull request.
      Description checkPassedThe 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 #14983 as 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 #14983 but 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
      Comment `@coderabbitai help` to get the list of available commands.
    4. maria-rckscommented

      Note

      Written by gpt-6.1-sol on behalf of Maria

      Verified 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 head 9656c0e79818d9bcc4a7b1d4c54b57414c53b4f6 in /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: [] and unavailable.reason: "unsupported", as expected without credentials. refresh completes and the page remains usable.
      • submitted actual codex gpt-6.1-sol turns through the web composer on main and the pr. provider logs show completed turns returning provider-path-ok and pr-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.ts through 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-ok

      main, without go credentials:

      main limits page without go credentials

      pr, with the same app-created data:

      pr limits page without go credentials

      real codex replies in the pr client

      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, no opencode.db, and no OPENCODE_* 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 authenticate https://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.

    5. maria-rcks merged thisd8430c0

    6. maria-rcks closed this

Sign in to join this conversation.