fix(server): restore OpenCode Go limits for Console API keys#21007

merged5
main
GitHub fork: fix/opencode-go-limits-console-key
opened25d agobyBBenglennon123
View on GitHubTwo-way sync enabledPR last imported 22d ago

OpenCode 2 can run Go through a connected Console API key while its separate Go key has expired. T3's limits probe ignored that Console connection and reported “OpenCode Go could not read usage.”

Read the selected public Console API key from OpenCode's database read-only, ahead of the separate Go key. Match OpenCode's credential selection order and explicit OPENCODE_DB path; skip in-memory databases. Select one connection before interpreting its credential so OAuth, inactive, or self-hosted connections cannot expose an older Console account. Retry with a distinct Go key only on 401/403, and fingerprint the key that produced the successful response. Inline auth overrides and disabled/external-instance guards remain in place. The usage guide now describes API-key Console connections.

Taken over from @Benglennon123's #21007, preserving the original commit and merging main. Compared credential ordering, database paths, and public-server metadata against the official OpenCode 2.0.28 and 2.0.32 producers. The rebuild corrects creation-order selection and explicit public Console metadata; review also caught the wrong-account risk from ignoring OPENCODE_DB.

Verification on Linux:

  • pnpm exec vp test run packages/provider-opencode/src/server/status.test.ts packages/provider-opencode/src/server/usage.test.ts: 35 passed in two existing files. The single added SQLite regression was rewritten without adding test cases: original PR 28 status tests, merged baseline 29, final 29. It covers Console precedence, 401/403 fallback, non-auth failures, credential exclusions, legacy ordering, inline auth, custom databases, unchanged database bytes, and successful-key identity. It fails against main; the custom-database case also fails against the first rebuild.
  • Scoped provider typecheck, targeted lint, formatting, and diff checks pass.
  • Two independent whole-PR review rounds with Claude Opus 5.5 and Codex GPT-6 Sol; the second round is clean after the database-path correction.
  • Ran the production reader with real temporary SQLite files and the real Fetch HTTP client against an isolated loopback server. The transport asserted the unchanged public destination before redirecting to the fixture server. All credentials and usage responses were synthetic; no real account credentials were read or sent. Before/after on matching data:
text
1main: Console connected + expired separate Go key
2 requests=[legacy], unavailable=probeFailed, windows=[]
3head: requests=[Console], unavailable=none, windows=[session:17, weekly:33, monthly:16]
4401/403: requests=[Console, legacy], successful-key fingerprint matches legacy
5500: requests=[Console], unavailable=probeFailed, no retry
6custom DB: selects Console there even when default DB contains another account
7inline override: requests=[inline]
8disabled/external instance: no credential requests

The headless pass also checked inactive/OAuth/self-hosted exclusions and :memory: handling; database files were unchanged. Screenshots do not apply to this server-only change.

Not verified: acceptance by the live Console/Go service, a running client with a real account, custom-channel OpenCode builds without an explicit database override, macOS, Windows, iOS, Android, or Electron desktop. A human should verify a real Console API-key account with an expired Go key before landing. The earlier approval discussion deferred Console OAuth; this PR adds no OAuth support, endpoint, or setting. Approval for this API-key credential path remains a human decision. No merge performed.

Tests: GPT-6 Astra; implementation: GPT-6.1 Sol; independent reviews: Claude Opus 5.5 and GPT-6 Sol; integration and preparation: GPT-6.1 Sol. Codex harness in T3 Code, with Claude used only for review.

Checks

21 successful · 7 skipped
All checks passed
31a3f32

Added 1 commit

  • fix(server): restore OpenCode Go limits for Console API keys3cb5b4f
Synced from GitHub

Approvability

Verdict: Needs Human Approval

Macroscope's review found this PR requires human approval — The PR narrowly restores OpenCode Go limit reporting and includes targeted regression coverage, but it changes production handling of Console API credentials by reading them from SQLite and sending them to the usage service. The authentication and sensitive-data implications require human review.

You can add or adjust custom eligibility rules. Learn more.

Synced from GitHub

Review in Change Stack →

Warning

Review limit reached

Only developers with an assigned seat can use this organization's usage-based review budget, and seats here are assigned manually. Ask an admin to assign a seat, or change the review continuation mode in Billing.

Next included review available in 7 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 10 included reviews currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: Path: .coderabbit.config.ts
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 6b7cf157-4b2f-4ef5-a461-e6ed3653f7d2
📥 Commits

Reviewing files that changed from the base of the PR and between 3cb5b4f9f49332a6e7e204df49c991bc56b251c9 and 31a3f3267891780e8a5a12a03d48a5908cca5962.

📒 Files selected for processing: 3
  • docs/user/usage.md
  • packages/provider-opencode/src/server/status.test.ts
  • packages/provider-opencode/src/server/usageLimits.ts

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Path: .coderabbit.config.ts
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 0a505897-5a85-40b9-b002-84c98589bc07
📥 Commits

Reviewing files that changed from the base of the PR and between 13aa882c22d584de5388dfce3b3ca413387ba059 and 3cb5b4f9f49332a6e7e204df49c991bc56b251c9.

📒 Files selected for processing: 3
  • docs/user/usage.md
  • 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 OpenCode Go usage probe can read a Console API key from OpenCode’s local database. It tries that key before the Go API key and falls back to the Go key after HTTP 401 or 403. The usage guide clarifies which credentials are accepted.

Changes: OpenCode Go usage credentials

Layer / File(s)Summary
Read Console credentials from SQLite
packages/provider-opencode/src/server/usageLimits.ts
The code reads eligible opencode key records from the local database. It excludes records with a server override and handles database errors without returning a Console key.
Use Console credentials with Go-key fallback
packages/provider-opencode/src/server/usageLimits.ts, packages/provider-opencode/src/server/status.test.ts, docs/user/usage.md
The probe tries the Console key first and retries with the Go key after HTTP 401 or 403. Tests cover credential selection and fallback. The usage guide clarifies the accepted credentials.

Priority: ➖ Normal

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

Change: Bug fix

Sequence Diagram(s)

mermaid
1sequenceDiagram
2 participant GoUsageProbe
3 participant OpenCodeDatabase
4 participant UsageEndpoint
5 GoUsageProbe->>OpenCodeDatabase: Read an eligible Console key unless inline auth overrides lookup
6 OpenCodeDatabase-->>GoUsageProbe: Return the Console key or no key
7 GoUsageProbe->>UsageEndpoint: Request usage with the Console key when available
8 UsageEndpoint-->>GoUsageProbe: Return usage or HTTP 401/403
9 GoUsageProbe->>UsageEndpoint: Retry with the Go key after HTTP 401/403 when it differs

Suggested reviewers: maria-rcks, nexxeln

Merge Risk: ⚪ Minimal · up to 3cb5b

No issue identified that should block merging the Console API-key usage fix after normal checks.

Security architecture risk: 🔵 Low · up to 3cb5b

The change uses an additional local credential source but retains the existing HTTPS destination, local-instance restrictions, and read-only behavior. No new credential-disclosure or authorization-bypass path was established. Compatibility with all supported OpenCode credential formats remains unverified.

Retained concerns No architecture-level concerns identified.

Security review details

Security Blast Radius

  • observed — The additional secret accessed is the selected Console key under the effective local OpenCode data directory. Instance overrides can change that directory, while empty instance configuration inherits the process environment; isolation is not created by this reader. The selected key is sent to the existing fixed opencode.ai usage endpoint.

Trust Boundaries and Controls

  • observed — Disabled instances and any nonempty external server URL return before credential access. Neither the supplied server URL nor credential metadata determines the HTTP destination. Inline authentication remains an explicit database-lookup override.

Resilience and Maintainability Implications

  • observed — Each probe closes its database handle before issuing HTTP requests, and fallback modifies only local request state. The surrounding probe retains its five-second Effect timeout. Shared snapshot handling can retain last-good limits after probeFailed unless the existing account-switch check detects a change; that retention policy is unchanged by this PR.

Hardening Proposals

  • proposed — Document and validate the supported OpenCode producer contract for credential type, active-row selection, and self-hosted server metadata. This would strengthen confidence that future upstream schema changes cannot silently alter which credential is transmitted.
Pre-merge checks: Passed 3 · Failed 1

Failed Failed checks: 1 warning

Check nameStatusExplanationResolution
Description checkWarningThe description fully explains the problem, implementation, scope, verification results, limitations, and test evidence. However, the required maintainer approval for the Console API-key path is not p…Add a link to explicit maintainer approval of the direction and scope, including the approval comment. If the change qualifies as an obvious focused fix without prior approval, explain why it qualifies under the repository requirements.
Passed Passed checks: 3 passed
Check nameStatusExplanation
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.
Title checkPassedThe title clearly and concisely identifies the main change: restoring OpenCode Go limits for Console API keys.
Full details: Description check

Explanation

The description fully explains the problem, implementation, scope, verification results, limitations, and test evidence. However, the required maintainer approval for the Console API-key path is not provided; the description states that approval remains a human decision.

Resolution

Add a link to explicit maintainer approval of the direction and scope, including the approval comment. If the change qualifies as an obvious focused fix without prior approval, explain why it qualifies under the repository requirements.

✨ 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.

Taking over this one. I’ll verify the Console credential format and precedence, keep the reader scoped to local instances, and refresh the regression and headless proof before pushing to this branch.

Added 4 commits

  • Merge remote-tracking branch 'origin/main' into fix/opencode-go-limits-console-key8c670e8
  • fix(server): follow selected Console credentials for Go limits30b946c
  • fix(server): use the instance OpenCode credential database496dd6c
  • Merge remote-tracking branch 'origin/main' into fix/opencode-go-limits-console-key31a3f32