Skip to content

fix(console): route new Console keys to inference - #49036

Merged
vaprdev merged 1 commit into
devfrom
go-key-routing
Sep 14, 2026
Merged

vaprdev merged 1 commit into
devfrom
go-key-routing

Conversation

@vaprdev

@vaprdev vaprdev commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

Problem

The V2 Console issues service-account API keys with the oc_sk_ prefix. The documented Go flow (create key in Console → /connectOpenCode Go → paste) sends them to https://opencode.ai/zen/go/v1, where proxyInference decides whether to forward to the new inference application by looking the key up in the legacy key table and checking workspace.migrated_at.

New keys have never existed in that table, so the lookup returns nothing, the request falls through to the legacy Zen handler, and the user gets Invalid API key. in the TUI.

Change

inference-proxy.ts: keys starting with oc_sk_ skip the legacy lookup and are forwarded to the mapped /inference/... path unconditionally. The destination owns authentication, revocation, and accounting as before.

Old sk- keys are unchanged: migrated workspaces forward, unmigrated workspaces stay on legacy Zen.

Supporting cleanup in the same file:

  • The lookup moved into a migratedWorkspace helper that filters migrated_at IS NOT NULL in SQL, so the caller only asks "is there a routable workspace?" (if (legacy && !workspace) return undefined).
  • Dropped the !go && condition on the ProviderTable join. Every /zen/go/* route uses modelList: "lite", so handler.ts already passes provider: undefined for Go; the proxy was re-checking what the caller owns.

Why the prefix is a safe discriminator

  • Both legacy key generators (console/core/src/key.ts, console/core/script/create-api-key.ts) produce sk- + 64 alphanumerics and always have.
  • Verified against production opencode.key: 3,729,853 rows, all matching ^sk-[A-Za-z0-9]{64}$.
  • New service_api_key prefixes are only oc_sk_... (native) and sk-... (imported legacy).

No format validation beyond the prefix: a forged oc_sk_ gains nothing but a 401 from the destination.

Verification

  • bun typecheck in packages/console/app; pre-commit turbo typecheck across the repo.
  • No existing tests cover this module; it is DB-backed and forwards via fetch, so a unit test would need to mock both. Not added.
  • Not exercised against a deployed stage. Preview stages have an empty ConsoleMigration.inferenceUrl, so forwarded requests there return 503; oc_sk_ keys on preview move from legacy's 401 to that 503, same as migrated keys already do.

Companion

anomalyco/opencode-console#2280 updates the inference README "Public Routing Gate" section to reference this change.

@github-actions github-actions Bot added needs:issue needs:compliance This means the issue will auto-close after 2 hours. labels Sep 14, 2026
@github-actions

Copy link
Copy Markdown
Contributor

This PR doesn't fully meet our contributing guidelines and PR template.

What needs to be fixed:

  • PR description is missing required template sections. Please use the PR template.

Please edit this PR description to address the above within 2 hours, or it will be automatically closed.

If you believe this was flagged incorrectly, please let a maintainer know.

@github-actions

Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@vaprdev
vaprdev merged commit 5cf4e13 into dev Sep 14, 2026
10 checks passed
@vaprdev
vaprdev deleted the go-key-routing branch September 14, 2026 21:33
hugojosefson pushed a commit to hugojosefson/opencode that referenced this pull request Sep 18, 2026
rossigee pushed a commit to rossigee/opencode that referenced this pull request Sep 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs:compliance This means the issue will auto-close after 2 hours. needs:issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant