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
@@ -60,6 +60,8 @@ from pathlib import Path
from hermes_constants import get_hermes_home
from typing import Dict, List, Optional, Set, Tuple
from utils import env_int
logger = logging.getLogger(__name__)
# ---------------------------------------------------------------------------
@@ -139,7 +141,7 @@ DEFAULT_EXCLUDES = [
]
# Git subprocess timeout (seconds).
_GIT_TIMEOUT: int = max(10, min(60, int(os.getenv("HERMES_CHECKPOINT_TIMEOUT", "30"))))
_GIT_TIMEOUT: int = max(10, min(60, env_int("HERMES_CHECKPOINT_TIMEOUT", 30)))
# Max files to snapshot — skip huge directories to avoid slowdowns.
_MAX_FILES = 50_000