← Back to Pull requests

fix(cli): preserve terminal env values omitted from config #129422

Open
dskwe opened this pull request with 48 lines diff across 2 files
View on GitHub
dskwe dskwe commented on Sep 30, 2026 15:54 UTC
Author

What does this PR do

Preserves terminal environment values from .env when config.yaml contains only a partial terminal section. The CLI config bridge now overwrites an existing TERMINAL_* 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

  • Bug fix
  • Changes Made

  • hermes_cli/cli_config_load.py: track raw terminal keys from config.yaml and 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 -q

  • Result: 3 passed in 38.84s
  • Checklist

  • The change is limited to the reported behavior.

  • Tests cover the regression.

  • No documentation changes are required.
  • Diff: 48 lines (+31 / -17) across 2 files Reviewer: arkheioncorp Review duration: 90265m
    All Vouch review confidence checks passed
    Residual risk 0.07 = Change Risk (0.58) × (1 − Review Confidence (0.88)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.58 · 48 lines diff across 2 files
    0.58
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.91 · 1 substantive comment(s)
    0.91
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    87%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.233
    Sensitive Paths sensitive_paths
    0.058
    Real PR Conversation Timeline
    3 items
    arkheioncorp arkheioncorp commented on Sep 30, 2026 16:01 UTC
    Reviewer

    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).

  • The comment on _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.

  • Test uses 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.

    dskwe dskwe commented on Sep 30, 2026 16:32 UTC
    Author

    @arkheioncorp Thanks for the review. I addressed both non-blocking suggestions:

  • Updated the _mirror_config_to_env docstring to clarify that environment variables win unless the config file explicitly provides that key (66224fb325).

  • Isolated the env-bridge map test with pytest's 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.

    Reviewers
    Assignees
    dskwe dskwe
    Labels
    risk: low confidence: 87.9% reviewed sensitive_module
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 57.9% (MEDIUM) · Higher = larger blast radius
    57.9%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 87.9% · Lower = rushed or shallow review
    87.9%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 7% · Safe to merge
    7%