fix(cli): preserve terminal env values omitted from config #129422
PR Reviews — today
[NousResearch/hermes-agent] #129422: fix(cli): preserve terminal env values omitted from config
Author: dskwe | Verdict: APPROVE
Findings
What the change does. The PR tightens the config-to-env mirroring in cli_config_load.py. Previously the function used a boolean _file_has_terminal_config to decide whether to overwrite existing TERMINAL_* env vars. Now it uses terminal_config_keys = frozenset(raw_terminal_config) so only keys actually present in the config file can clobber env values the user set elsewhere (.env, shell exports). A focused regression test (test_cli_config_defaults_do_not_override_unset_terminal_env_values) verifies that a partial terminal section ({backend, docker_volumes}) leaves a pre-existing TERMINAL_DOCKER_VOLUMES env value intact.
Security / quality. No secrets, injection, or dangerous patterns in the diff. The change is minimal and surgical — default argument frozenset(), a single conditional swap, and the test. The old boolean is a coarser contract (two states); the new frozenset is strictly more precise (exact set of keys), so the regression risk is low.
Suggestions (non-blocking).
_mirror_config_to_env still says "Project config.yaml values into the env vars ... Env always wins when already set." That sentence is now slightly imprecise because env only wins for keys absent from the file. Adding one short clause ("unless the file explicitly provides that key") would keep the doc in sync.patch.dict(os.environ, ..., clear=False) then indexes os.environ["TERMINAL_DOCKER_VOLUMES"] — fine, but reading the patched value back is implicitly testing the side effect through the real os.environ. If other tests in the same run mutate that key, isolation is via pytest operand isolation, not a local sandbox. Not a blocker; just noting the test touches real env.Verdict: APPROVE — scoped fix, regression test included, no new attack surface.
@arkheioncorp Thanks for the review. I addressed both non-blocking suggestions:
_mirror_config_to_env docstring to clarify that environment variables win unless the config file explicitly provides that key (66224fb325).monkeypatch fixture instead of mutating the real process environment directly (b675cb5e34).Validation: tests/tools/test_terminal_config_env_sync.py -q — 3 passed; git diff --check passed. Both commits are pushed to the PR branch.
arkheioncorp
dskwe
What does this PR do
Preserves terminal environment values from
.envwhenconfig.yamlcontains only a partialterminalsection. The CLI config bridge now overwrites an existingTERMINAL_*variable only when its corresponding key was explicitly present in the file; merged defaults continue to backfill variables that are unset.Related Issue
Fixes #129418
Type of Change
Changes Made
hermes_cli/cli_config_load.py: track raw terminal keys fromconfig.yamland use them when mirroring merged settings to environment variables.tests/tools/test_terminal_config_env_sync.py: verify omitted Docker volume settings do not erase an existing environment value.How to Test
/Users/liyuan/github/ai/hermes-agent/venv/bin/python3 -m pytest tests/tools/test_terminal_config_env_sync.py -q3 passed in 38.84sChecklist