Skip to content

fix(gateway): keep max iterations config authoritative - #43407

Closed
Soju06 wants to merge 1 commit into
NousResearch:mainfrom
Soju06:fix/gateway-max-iterations-config-authority
Closed

fix(gateway): keep max iterations config authoritative#43407
Soju06 wants to merge 1 commit into
NousResearch:mainfrom
Soju06:fix/gateway-max-iterations-config-authority

Conversation

@Soju06

@Soju06 Soju06 commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Keep gateway max_iterations resolution authoritative to config.yaml agent.max_turns when it is configured
  • Reload .env before resolving the gateway agent budget so stale HERMES_MAX_ITERATIONS values cannot win during gateway turns
  • Cover the stale .env regression with a focused gateway test

Why

A stale HERMES_MAX_ITERATIONS=90 entry in .env can cause gateway sessions to stop with Iteration budget exhausted (90/90) even when config.yaml sets agent.max_turns higher. Removing the .env line is enough as an immediate local mitigation, but the gateway should preserve the existing config-authority contract so stale regenerated env values do not reintroduce the bug.

Test Plan

  • python -m pytest tests/gateway/test_runtime_env_reload_config_authority.py tests/gateway/test_run_cleanup_progress.py -q
  • python -m compileall -q gateway/run.py
  • git diff --check upstream/main..HEAD

@Soju06
Soju06 force-pushed the fix/gateway-max-iterations-config-authority branch from e2d7dc8 to 75ae622 Compare June 10, 2026 07:52
Resolve gateway agent max_iterations from config.yaml agent.max_turns before falling back to HERMES_MAX_ITERATIONS, and reload runtime env before resolving the per-turn cap. This prevents stale .env HERMES_MAX_ITERATIONS=90 from reintroducing 90/90 iteration exhaustion when config.yaml sets a higher budget.

Origin: local-author

Upstream-PR: none

Patch-State: local-only
@Soju06
Soju06 force-pushed the fix/gateway-max-iterations-config-authority branch from 75ae622 to fd59683 Compare June 10, 2026 07:54
@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 Jun 10, 2026
@liuhao1024

Copy link
Copy Markdown
Contributor

Verification Review

Reviewed by: automated PR review cron

Summary: Clean refactor that makes config.yaml the authoritative source for across all three gateway agent-creation paths. The extracted and helpers eliminate the duplicated config-reading logic and ensure stale values cannot override explicit config.

Observations:

  • The precedence chain (config.yaml → .env → default 90) is correctly enforced in all three call sites
  • now only bridges to env when config explicitly sets the value — previously it would set the env var even from a key that was absent, leaving stale .env values in place
  • Test coverage verifies the config-overrides-env-after-reload scenario

LGTM.

@kshitijk4poor

Copy link
Copy Markdown
Collaborator

Closing as already resolved on current main.

The config-authority contract this PR restores is already in place in gateway/run.py:

  • _reload_runtime_env_preserving_config_authority() reloads .env for fresh credentials but explicitly preserves config.yaml's agent.max_turns so a stale HERMES_MAX_ITERATIONS in .env can't override it on later turns.
  • _bridge_max_turns_from_config() bridges config.yaml agent.max_turns into the env var, and the startup bridge guards the "stale 60 vs configured 500" regression.
  • _current_max_iterations() re-reads the budget per turn after that refresh.

So a stale HERMES_MAX_ITERATIONS=90 no longer wins over a higher configured agent.max_turns. Thanks for the fix and the clear write-up of the regression — the contract you wanted is honored on main.

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.

4 participants