fix(settings): API key export overwrites env; drop multi-tenant docs claim#109
Open
shoom1 wants to merge 1 commit into
Open
fix(settings): API key export overwrites env; drop multi-tenant docs claim#109shoom1 wants to merge 1 commit into
shoom1 wants to merge 1 commit into
Conversation
…claim Review finding 7 (countered): export_api_keys_to_env() set provider env vars only when absent, so in a process with two settings instances the first manager's export silently pinned credentials for every later one — while config.py advertised SettingsContext for multi-tenant use. The reviewer's fix (pass credentials to every provider client) fights ADK 1.x: AnthropicLlm/Gemini construct SDK clients from env internally. Instead: - export now OVERWRITES env from the settings instance. This is precedence-consistent: the key fields bind only via their env alias (validation_alias, no populate_by_name — constructor kwargs and JSON files never set them), so divergence only means the process env changed after this instance loaded, and the configured value must win. Unset keys still leave the environment untouched. - config.py no longer claims multi-tenant isolation for SettingsContext; it documents that credentials are process-global env vars. Claude-Session: https://claude.ai/code/session_01SwkKXQpy3JLEqrPkQA8QRv
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.
Review finding 7, countered
Confirmed mechanics:
initialize_services()exports keys to env with a set-if-absent guard, so the first exporting manager silently pinned credentials for every later settings instance in the process — whileconfig.pyadvertisedSettingsContextfor "multi-tenant" use.The reviewer's prescription — pass credentials directly to every provider client — fights ADK 1.x:
AnthropicLlm/Gemini construct their SDK clients from env vars internally (our code comments on that reliance), and the LangChain clients that do acceptapi_key=belong to the backend slated for retirement. Injecting keys would mean subclassing ADK's LLM classes for a multi-tenant scenario this single-user CLI framework doesn't have.Change
export_api_keys_to_env()now overwrites env from the settings instance. Precedence-consistent: the key fields bind only via their env alias (validation_alias, nopopulate_by_name— constructor kwargs and settings.json never populate them, verified empirically), so settings and env diverge only when the process env changed after this instance loaded — e.g. an earlier manager's export, or a class-specificenv_file. In both cases this instance's configured value must win. Unset keys still leave external env vars untouched.config.pymodule docs:SettingsContextis for isolated settings lookup (tests, per-request overrides); explicitly documents that credentials become process-global env vars at manager init.Discovered while verifying (not addressed here)
validation_aliaswithoutpopulate_by_namemeansBaseSettings(anthropic_api_key=...)kwargs and~/.{app}/settings.jsonkeys silently never bind — only the aliased env var or a.envfile does. Several tests/fixtures pass such kwargs believing they work. Fixing that (e.g.AliasChoices(alias, field_name)orpopulate_by_name=True) intersects the P0-1 trust filters and deserves its own reviewed change.Tests
TDD: overwrite test watched fail against the old guard via stash A/B (env mutated after load → old code kept the stale key), plus a pin that unset keys never clobber external env. Full offline suite: 1983 passed.
https://claude.ai/code/session_01SwkKXQpy3JLEqrPkQA8QRv