Skip to content

fix(gateway): preserve max turns after env reload#19183

Closed
altmazza0-star wants to merge 1 commit into
NousResearch:mainfrom
altmazza0-star:fix/gateway-runtime-env-config-authority
Closed

fix(gateway): preserve max turns after env reload#19183
altmazza0-star wants to merge 1 commit into
NousResearch:mainfrom
altmazza0-star:fix/gateway-runtime-env-config-authority

Conversation

@altmazza0-star
Copy link
Copy Markdown
Contributor

Closes #19158

Summary

  • Add a gateway runtime env reload helper that still refreshes credentials from .env
  • Re-apply config.yaml agent.max_turns after per-turn .env reloads so stale HERMES_MAX_ITERATIONS cannot override it
  • Add regression tests for the config-authoritative and env-fallback paths

Tests

  • python -m pytest tests/gateway/test_runtime_env_reload_config_authority.py -q
  • python -m pytest tests/gateway/test_runtime_env_reload_config_authority.py tests/gateway/test_config_env_bridge_authority.py -q
  • python -m pytest tests/gateway/test_runtime_env_reload_config_authority.py tests/gateway/test_config_env_bridge_authority.py tests/gateway/test_session_env.py -q

@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/gateway Gateway runner, session dispatch, delivery area/config Config system, migrations, profiles labels May 3, 2026
@alt-glitch
Copy link
Copy Markdown
Collaborator

Related to #18230 and #17306 — all address the same root cause (stale HERMES_MAX_ITERATIONS from .env overriding config.yaml agent.max_turns). This PR targets the credential-reload path specifically. Consider closing #18230 and #17306 if this covers their scope.

@alt-glitch
Copy link
Copy Markdown
Collaborator

Related to #18230 and #17306 — same root cause (stale env overriding config max_turns).

@liuhao1024
Copy link
Copy Markdown
Contributor

Hi! Thanks for the fix — the core _reload_runtime_env_preserving_config_authority logic looks correct and addresses the stale .env override nicely.

I noticed what looks like a syntax issue in the test file. On this line:

    (hermes_home / ".env").write_text(
        "HERMES_MAX_ITERATIONS=90\nOPENROUTER_API_KEY=***
        encoding="utf-8",
    )

The string "HERMES_MAX_ITERATIONS=90\nOPENROUTER_API_KEY=*** appears to be missing its closing ", which would cause a SyntaxError when the test module is loaded. You might want something like:

        "HERMES_MAX_ITERATIONS=90\nOPENROUTER_API_KEY=fresh-key\n",

Also, the test asserts os.environ["OPENROUTER_API_KEY"] == "fresh-key" but the .env content (if closed) would set it to ***. Might be worth double-checking these align.

Overall the fix itself looks solid — just the test needs a small fixup to actually run.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/config Config system, migrations, profiles comp/gateway Gateway runner, session dispatch, delivery P2 Medium — degraded but workaround exists type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Gateway max_turns can be overridden by stale HERMES_MAX_ITERATIONS from .env

3 participants