fix(config): stop _normalize_custom_provider_entry mutating the caller's dict - #881
Open
hashbender wants to merge 1 commit into
Open
fix(config): stop _normalize_custom_provider_entry mutating the caller's dict#881hashbender wants to merge 1 commit into
hashbender wants to merge 1 commit into
Conversation
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 does this PR do?
Stops
_normalize_custom_provider_entry(hermes_cli/config.py) from mutating the dict it is passed.The normalizer builds and returns a fresh
normalizeddict, but on the way it writes alias keys into its input:Two of its three callers —
get_compatible_custom_providersandproviders_dict_to_custom_providers— pass live sub-dicts fromload_config_readonly()'s shared cache, which has an explicit no-mutation contract. (The third caller,_custom_provider_entry_to_provider_config, already defends itself withdict(entry)— evidence the hazard was known but two paths were missed.)Consequences for a config written with the documented camelCase /
api_key_envaliases:baseUrlandbase_url,apiKeyEnvandkey_env), so every laterload_config()deepcopy inherits them, and anysave_config(load_config())flow (setup wizard, dashboard config writes, model persist) writes the duplicates back toconfig.yaml;_resolve_aux_verifyruns it on every auxiliary-client build (compression, vision, title-gen), i.e. an unlocked dict mutation on a shared object from worker threads;load_config_readonly()at 31 read-only call sites inagent/) widens the blast radius further — several of those sites reach this normalizer.Repro on current main:
The fix is a shallow
entry = dict(entry)at the top of the normalizer. The return value is a separately-built dict, so nothing else changes.Related Issue
None filed. Alias handling introduced for NousResearch#9332; the readonly-cache interaction is what makes it bite.
Type of Change
Changes Made
hermes_cli/config.py— shallow-copy the entry before alias normalization (+ comment explaining why).tests/hermes_cli/test_provider_config_validation.py— 3 regression tests: camelCase entry unchanged,api_key_enventry unchanged, andget_compatible_custom_providersleaves the whole config deep-equal to a snapshot.How to Test
All 3 new tests fail on current main and pass with the fix; the file's other 21 tests pass on both. Also green: tests/hermes_cli/test_config.py, test_custom_provider_tls.py, test_runtime_provider_resolution.py, tests/agent/test_auxiliary_named_custom_providers.py (317 tests, macOS 15).
scripts/check-windows-footguns.pyclean.Checklist
Mirror-of: NousResearch#57096
NousResearch#57096