fix: guard int(os.getenv()) casts against malformed env vars (#40598)

A non-numeric value in env vars like HERMES_STREAM_RETRIES,
HERMES_KANBAN_SPECIFY_MAX_TOKENS, GOOGLE_CHAT_MAX_BYTES, IRC_PORT, etc.
raised ValueError at import/init and crashed startup. Parse them safely,
falling back to the default.

Unified onto the existing utils.env_int(key, default) helper for core/
hermes_cli/tools modules instead of the original PR's three duplicate
local helpers; plugins keep minimal inline guards (no core-utils import).
All existing max()/min()/`or extra.get()` wrappers preserved.

Co-authored-by: annguyenNous <annguyenNous@users.noreply.github.com>
This commit is contained in:
Teknium
2026-06-07 06:14:24 -07:00
committed by GitHub
co-authored by annguyenNous
parent e2cc24e331
commit 2912d94370
8 changed files with 29 additions and 13 deletions
+3 -1
View File
@@ -40,9 +40,11 @@ from typing import Optional
from hermes_cli import kanban_db as kb
from utils import env_int
HERMES_KANBAN_SPECIFY_MAX_TOKENS = max(
1500,
int(os.getenv("HERMES_KANBAN_SPECIFY_MAX_TOKENS", "6000")),
env_int("HERMES_KANBAN_SPECIFY_MAX_TOKENS", 6000),
)
logger = logging.getLogger(__name__)
+3 -3
View File
@@ -31,7 +31,7 @@ from hermes_cli.auth import (
)
from hermes_cli.config import get_compatible_custom_providers, load_config
from hermes_constants import OPENROUTER_BASE_URL
from utils import base_url_host_matches, base_url_hostname
from utils import base_url_host_matches, base_url_hostname, env_int
def _normalize_custom_provider_name(value: str) -> str:
@@ -1144,7 +1144,7 @@ def _resolve_explicit_runtime(
str(state.get("agent_key") or "").strip()
if _agent_key_is_usable(
state,
max(60, int(os.getenv("HERMES_NOUS_MIN_KEY_TTL_SECONDS", "1800"))),
max(60, env_int("HERMES_NOUS_MIN_KEY_TTL_SECONDS", 1800)),
)
else ""
)
@@ -1343,7 +1343,7 @@ def resolve_runtime_provider(
# expired, clear pool_api_key so we fall through to
# resolve_nous_runtime_credentials() which handles refresh.
if provider == "nous" and entry is not None and pool_api_key:
min_ttl = max(60, int(os.getenv("HERMES_NOUS_MIN_KEY_TTL_SECONDS", "1800")))
min_ttl = max(60, env_int("HERMES_NOUS_MIN_KEY_TTL_SECONDS", 1800))
nous_state = {
"agent_key": getattr(entry, "agent_key", None),
"agent_key_expires_at": getattr(entry, "agent_key_expires_at", None),