fix: warn when the environment overrides a .env setting - #57
Merged
davidmckayv merged 1 commit intoSep 25, 2026
Merged
Conversation
process.loadEnvFile never overrides variables that are already set, so a stale shell export or a system-wide variable silently wins over .env. For example, a system-wide OPENAI_API_KEY for OpenAI gets sent to an OPENAI_BASE_URL gateway instead of the gateway key in .env, and the only symptom is a provider authentication error. On startup, name the .env keys whose value is replaced by a different environment value. Only key names are logged, never values. Loading precedence is unchanged.
This was referenced Sep 25, 2026
jerelvelarde
added a commit
to jerelvelarde/openmuse-1
that referenced
this pull request
Sep 29, 2026
Resolve tests/config.test.ts: keep both the Jev mode test and main's shadowed-.env test (CopilotKit#57).
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 changed
process.loadEnvFile(".env")never overrides variables that are already set. A stale shell export or a system-wide variable therefore silently wins over.env. In practice, a system-wideOPENAI_API_KEYfor OpenAI gets sent to theOPENAI_BASE_URLgateway instead of the gateway key in.env. The only symptom is a provider authentication error in chat ("Missing Authentication header" from OpenRouter), which points nowhere near the cause.On startup, the server now logs the
.envkeys whose value is replaced by a different environment value:Only key names are logged, never values. Loading precedence is unchanged.
Verification
tests/config.test.tscase covers a different value, an identical value, a key present only in.env, and an empty.envvalue.OPENAI_API_KEYand a different gateway key in.env, the warning printed with the key name only.pnpm typecheckandpnpm build:serverpass. Biome reports no issues for the changed files.pnpm test: 162 passed, 1 failed. The failure isDocker subprocess uses literal argv…, which fails on Windows with or without this change.Integration limits
pnpm dev:browserloads.envwithnode --env-file, which has the same precedence; this change only covers the API and task worker.