fix(auth): prioritize login API keys over env fallbacks#4694
Open
roboomp wants to merge 1 commit into
Open
Conversation
- Marked API keys persisted by login so deliberate account switches outrank stale env fallbacks. - Kept ordinary stored API keys below explicit env vars and covered OpenCode Go regression. Fixes #4688
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
Collaborator
Author
|
No code change requested here. The Codex review did not run because code-review usage credits are exhausted; repo admin action is needed in the linked Codex settings to re-enable those reviews. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Repro
A focused regression test sets the OpenCode Go env fallback to
old-opencode-key, runsAuthStorage.login("opencode-go", ...)withnew-opencode-key, then callsgetApiKey("opencode-go", "session-opencode-go-login"); before the fix,bun test packages/ai/test/auth-storage-api-key-login.test.ts -t "fresh OpenCode Go"failed because the env key was returned.Cause
packages/ai/src/auth-storage.tspersisted API-key login results as ordinaryapi_keycredentials, andAuthStorage.getApiKeyresolved env fallbacks before storedapi_keyrows. That preserved env precedence for stale broker/static keys, but also made a deliberate OpenCode Go/loginaccount switch indistinguishable from an old stored key.Fix
AuthStorage.loginwith login provenance inpackages/ai/src/auth-storage.ts.getCredentialOriginanddescribeCredentialSourcealigned with the updated credential cascade.packages/ai/test/auth-storage-api-key-login.test.ts.packages/aichangelog entry.Verification
bun test packages/ai/test/auth-storage-api-key-login.test.ts packages/ai/test/auth-storage-credential-origin.test.tspassed with 13 tests and 38 assertions.bun checkpassed.bun run fixpassed before commit and during publish. Fixes #4688