Skip to content

fix(config): empty or placeholder API keys resolve to None and say so; blank inherited vars no longer shadow .env - #47

Open
LegaSage wants to merge 2 commits into
google:mainfrom
LegaSage:pr/credential-resolution
Open

LegaSage wants to merge 2 commits into
google:mainfrom
LegaSage:pr/credential-resolution

Conversation

@LegaSage

Copy link
Copy Markdown

Problem

.env.example ships GOOGLE_API_KEY= and GEMINI_API_KEY= as blank lines. When a user leaves a value empty (or edits .env while the daemon is already running), the planner fails with:

Planner requires GOOGLE_API_KEY in .env

which says the variable is missing when it is present and empty. Three things stack up:

  1. fallback_api_keys sanitizes placeholders under if val and is_placeholder_key(val). Pydantic's SecretStr("") is falsy, so an empty secret skips the check and survives as a non-None empty SecretStr; the GEMINI_API_KEY alias never applies.
  2. validate_provider raises a bare message that cannot distinguish "unset" from "present but empty/placeholder".
  3. load_dotenv never overrides a variable already in the environment, blank included. A daemon started with blank vars exports the blanks to every runner it spawns, so a corrected .env stays invisible until the whole daemon restarts.

Fix

  • Empty or placeholder credential values normalize to None, so the existing alias chain (GEMINI_API_KEY → GOOGLE_API_KEY → GCP_API_KEY) works.
  • Blank credential vars inherited from the environment are dropped before the dotenv load; a non-blank inherited value still wins.
  • Provider errors name the loaded dotenv path, the accepted aliases, and per-variable <unset> vs <present but empty/placeholder>. Key material is never printed.

Tests

tests/unit/config/test_credential_resolution.py (7 tests). The core assertion fails on main: Settings(_env_file=None) with GOOGLE_API_KEY="" yields a SecretStr on main and None with this change.

Found while running ARTEMIS from an MCP server whose .env had both key lines present and empty; the next task ran past the credential gate on the same, un-restarted daemon after this change.

@google-cla

google-cla Bot commented Sep 11, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@LegaSage

Copy link
Copy Markdown
Author

@googlebot I signed it!

@LegaSage
LegaSage force-pushed the pr/credential-resolution branch 2 times, most recently from 0fdf19e to 4af83a6 Compare September 11, 2026 19:24
An `.env` with `GOOGLE_API_KEY=` / `GEMINI_API_KEY=` (names present, values
empty) made `Settings.GOOGLE_API_KEY` a falsy `SecretStr("")` instead of None:
the placeholder sanitizer was guarded by `if val and ...`, which short-circuits
on the empty secret it is meant to drop. The Google provider check then raised
"Planner requires GOOGLE_API_KEY in .env", which reads as "the variable is
missing" even though the line is right there in the file — the wrong debugging
path.

- settings.fallback_api_keys: normalize on `is not None`, so empty/placeholder
  credentials always become None.
- llm.validate_provider: every missing-credential error now names the dotenv
  file that was actually loaded, lists the accepted aliases (GEMINI_API_KEY /
  GCP_API_KEY for Google), and distinguishes <unset> from <present but
  empty/placeholder>. No key material is ever included.
- tests/unit/config/test_credential_resolution.py pins all of it.
`load_dotenv` skips any variable already present in the process environment,
blank included. The ARTEMIS daemon was started while `.env` still had
`GEMINI_API_KEY=` / `GOOGLE_API_KEY=` empty, so it exported the blanks and every
child runner it spawned inherited them — filling in `.env` afterwards changed
nothing until the whole daemon was restarted, and the failure looked like "the
key is not in .env".

Blank carries no information, so drop blank credential vars from os.environ
before the dotenv load and let the file win; a non-blank inherited value still
takes precedence. Verified live: an ARTEMIS task that failed at the planner
credential check ran past it on the same unrestarted daemon after this change.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant