Skip to content

fix(gateway): guard HERMES_MAX_ITERATIONS in run.py against malformed env var - #48740

Closed
vanthinh6886 wants to merge 1 commit into
NousResearch:mainfrom
vanthinh6886:fix/run-env-int-guard
Closed

fix(gateway): guard HERMES_MAX_ITERATIONS in run.py against malformed env var#48740
vanthinh6886 wants to merge 1 commit into
NousResearch:mainfrom
vanthinh6886:fix/run-env-int-guard

Conversation

@vanthinh6886

Copy link
Copy Markdown
Contributor

Summary

Replace bare int(os.getenv("HERMES_MAX_ITERATIONS", "90")) with env_int("HERMES_MAX_ITERATIONS", 90) at two call sites in gateway/run.py (lines 10636 and 14586).

A malformed HERMES_MAX_ITERATIONS env var (e.g. "abc") causes a ValueError crash. The env_int() helper in utils.py catches ValueError/TypeError and returns the default value.

Note: Line 4965 already has a try/except guard so it is left as-is.

Changes

  • gateway/run.py: Add env_int to existing utils import, replace 2 bare int(os.getenv(...)) calls

Test Plan

  • pytest passes (unrelated failure in test_copilot_acp_client is pre-existing)
  • Lint clean

Context

This is part of a systemic issue with ~25 bare int(os.getenv)/float(os.getenv) calls across the gateway. Related: PR #48735 (api_server.py + env_float addition to utils.py).

@alt-glitch alt-glitch added type/bug Something isn't working P3 Low — cosmetic, nice to have comp/gateway Gateway runner, session dispatch, delivery duplicate This issue or pull request already exists labels Jun 19, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Duplicate of #48298 — both guard the HERMES_MAX_ITERATIONS env-var cast in gateway/run.py with the same env_int(...) mechanism at the same two sites. #48298 (and #48365) already cover these exact gateway/run.py sites plus additional files (api_server.py / utils.py / feishu.py), so this PR is a strict subset. Related: #48365, #48735.

@tonydwb tonydwb left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review Summary

Verdict: Approved

Consistent env_int guard application for HERMES_MAX_ITERATIONS in two locations within gateway/run.py. Prevents crashes from malformed env var values. Follows established pattern from other guard fixes in the same codebase.


Reviewed by Hermes Agent

…n run.py

Replace bare int(os.getenv("HERMES_MAX_ITERATIONS", "90")) with
env_int("HERMES_MAX_ITERATIONS", 90) at two call sites in gateway/run.py
(lines 10636 and 14586).

A malformed HERMES_MAX_ITERATIONS env var (e.g. "abc") causes a
ValueError crash. The env_int() helper in utils.py catches
ValueError/TypeError and returns the default value.

Note: Line 4965 already has a try/except guard so it is left as-is.
@vanthinh6886
vanthinh6886 force-pushed the fix/run-env-int-guard branch from 4f74c0f to 9b6aceb Compare June 19, 2026 03:00
@kshitijk4poor

Copy link
Copy Markdown
Collaborator

Closing as already resolved on main.

The HERMES_MAX_ITERATIONS casts this PR targets are already guarded on current main via the _current_max_iterations() helper in gateway/run.py, which wraps the parse in try/except (TypeError, ValueError) and is wired into all three gateway/run.py sites plus api_server.py. The malformed-value crash this PR fixes no longer reproduces there.

The remaining malformed-env-var crash sites across the rest of the gateway/agent were just swept up in #49558 (canonical utils.env_int/env_float conversion):
#49558

Thanks for the fix — appreciated.

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

Labels

comp/gateway Gateway runner, session dispatch, delivery duplicate This issue or pull request already exists P3 Low — cosmetic, nice to have type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants