fix(coding-agent): treat a set-but-empty credential env var as missing - #1513
Open
snimu wants to merge 4 commits into
Open
fix(coding-agent): treat a set-but-empty credential env var as missing#1513snimu wants to merge 4 commits into
snimu wants to merge 4 commits into
Conversation
resolveConfigValue and resolveConfigValueUncached fell back with `envValue || config`, so an env var explicitly set to "" resolved to the literal variable name, which then got sent to providers as the API key and produced confusing 401s instead of a clear missing-credential error. An unset variable still falls back to the literal config string (pasted keys keep working). A set-but-empty variable now resolves to undefined, matching the shell-command path which already normalizes empty output to undefined, so resolveConfigValueOrThrow raises the proper error. Closes #1468 (discussion).
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.
What this does
Fixes credential resolution when an env var is set but empty (reported in discussion #1468).
The bug
resolveConfigValue()/resolveConfigValueUncached()fell back withenvValue || config.||treats""as falsy, so a variable explicitly set to empty (export MY_API_KEY="", orKEY=in a.envfile) resolved to the literal string"MY_API_KEY"— which was then sent to the provider as the API key, producing confusing 401s instead of a clear missing-credential error.resolveConfigValueOrThrownever threw because the literal name is notundefined.The fix
undefined(missing credential). This matches the shell-command path, which already normalizes empty output toundefined, and makesresolveConfigValueOrThrowraise its proper "Failed to resolve ..." error.Validation
test/resolve-config-value.test.tscovering set / unset / set-but-empty (and the OrThrow error path).auth-storage,model-registry, and the new suite: 126/126 pass keyless.Note
Low Risk
Small, localized change to credential env resolution with new tests; behavior only shifts for explicitly empty env vars, which were already incorrect when sent as API keys.
Overview
Fixes credential resolution when a config value is an environment variable name and that variable is set to an empty string (for example
export MY_API_KEY=""orKEY=in a.envfile).Previously,
resolveConfigValue/resolveConfigValueUncachedusedenvValue || config, so empty strings fell through to the literal variable name and could be sent to providers as the API key, causing confusing 401s instead of a clear missing-credential error.The change adds
resolveEnvOrLiteral: unset variables still fall back to the literal config string (literal keys unchanged); set-but-empty values resolve toundefined, matching empty shell-command output and allowingresolveConfigValueOrThrowto raise Failed to resolve …. New unit tests cover set, unset, and set-but-empty paths.Reviewed by Cursor Bugbot for commit 4926567. Bugbot is set up for automated code reviews on this repo. Configure here.
Note
Fix
resolveConfigValueto treat set-but-empty credential env vars as missingPreviously, if a credential was configured as an env var name and that var was set to an empty string,
resolveConfigValuewould fall back to returning the literal env var name instead ofundefined. This fix maps empty string env var values toundefined, matching the behavior expected for missing credentials.resolveEnvOrLiteralhelper in resolve-config-value.ts that explicitly distinguishes unset vs. set-but-empty env vars.undefinedrather than the literal variable name string.Macroscope summarized 4926567.