The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(config): validate the timezone key so a bad IANA name is reported, not silently ignored
John Paul Soliva7af3515c57eb
diff --git a/hermes_cli/config.py b/hermes_cli/config.pyindex e46f602e4dc..caccbb71b17 100644--- a/hermes_cli/config.py+++ b/hermes_cli/config.py@@ -1138,6 +1138,39 @@ def _validate_voice(config: Dict[str, Any], issues: List[ConfigIssue]) -> None:"Set voice.submit_mode to direct (submit immediately) or draft (edit before sending)")+def _validate_timezone(config: Dict[str, Any], issues: List[ConfigIssue]) -> None:+ """``timezone`` must be an IANA name the runtime can load.++ ``hermes_time._get_zoneinfo()`` swallows an invalid name behind a single WARNING in the+ gateway log, then runs the agent clock AND every cron schedule on server-local time.+ Surface it here, where doctor and the startup check both look. Silent when the+ interpreter has no tz database at all (bare Windows without ``tzdata``) — nothing can be+ judged there.+ """+ if "timezone" not in config:+ return+ tz = config.get("timezone")+ hint = ("Use an IANA zone name such as America/New_York or Asia/Tokyo (see "+ "`timedatectl list-timezones`). With an invalid value the agent clock and cron "+ "schedules silently fall back to server-local time. HERMES_TIMEZONE overrides "+ "this key when set.")+ if tz is not None and not isinstance(tz, str):+ _issue(issues, "error", f"timezone must be an IANA zone name string, got {tz!r}", hint)+ return+ if not (isinstance(tz, str) and tz.strip()):+ return+ name = tz.strip()+ try:+ import zoneinfo+ zoneinfo.ZoneInfo("UTC") # is a tz database available at all?+ except Exception:+ return+ try:+ zoneinfo.ZoneInfo(name)+ except Exception:+ _issue(issues, "error", f"timezone {name!r} is not a valid IANA zone name", hint)++def _validate_entry_list(entries: list, label: str, issues: List[ConfigIssue], fields, *, non_dict: Tuple[str, str, str],) -> None:@@ -1220,6 +1253,7 @@ def validate_config_structure(config: Optional[Dict[str, Any]] = None) -> List["issues: List[ConfigIssue] = []_validate_voice(config, issues)+ _validate_timezone(config, issues)cp = config.get("custom_providers")fb = config.get("fallback_model")for value, validator in ((cp, _validate_custom_providers), (fb, _validate_fallback_model)):diff --git a/tests/hermes_cli/test_config_validation.py b/tests/hermes_cli/test_config_validation.pyindex 8f5746eda29..41321337d7b 100644--- a/tests/hermes_cli/test_config_validation.py+++ b/tests/hermes_cli/test_config_validation.py@@ -1,6 +1,8 @@"""Tests for config.yaml structure validation (validate_config_structure)."""+import pytest+from hermes_cli.config import (DEFAULT_CONFIG,_EXTRA_KNOWN_ROOT_KEYS,@@ -111,6 +113,59 @@ class TestVoiceSubmitModeValidation:)+def _tz_issues(config):+ return [i for i in validate_config_structure(config) if "timezone" in i.message]+++def _has_tz_database() -> bool:+ try:+ import zoneinfo+ zoneinfo.ZoneInfo("UTC")+ return True+ except Exception:+ return False+++class TestTimezoneValidation:+ """An invalid ``timezone`` silently puts the agent clock and every cron+ schedule on server-local time (hermes_time._get_zoneinfo falls back with+ one log warning). validate_config_structure must report it."""++ def test_valid_zone_passes(self):+ assert _tz_issues({"timezone": "Asia/Tokyo", "model": {"provider": "nous"}}) == []++ def test_missing_or_blank_is_not_reported(self):+ assert _tz_issues({"model": {"provider": "nous"}}) == []+ assert _tz_issues({"timezone": "", "model": {"provider": "nous"}}) == []+ assert _tz_issues({"timezone": " ", "model": {"provider": "nous"}}) == []+ assert _tz_issues({"timezone": None, "model": {"provider": "nous"}}) == []++ @pytest.mark.skipif(not _has_tz_database(), reason="no tz database in this interpreter")+ def test_invalid_zone_is_reported(self):+ [issue] = _tz_issues({"timezone": "Asia/Tokio", "model": {"provider": "nous"}})+ assert issue.severity == "error"+ assert "Asia/Tokio" in issue.message+ assert "IANA" in issue.hint+ assert "HERMES_TIMEZONE" in issue.hint++ def test_non_string_is_reported(self):+ [issue] = _tz_issues({"timezone": 9, "model": {"provider": "nous"}})+ assert issue.severity == "error"+ assert "string" in issue.message++ def test_silent_without_a_tz_database(self, monkeypatch):+ # Bare Windows without tzdata: ZoneInfo cannot load anything, including+ # UTC. A valid name must not be flagged just because it cannot be checked.+ import zoneinfo++ def no_db(_key):+ raise zoneinfo.ZoneInfoNotFoundError("no tz database")++ monkeypatch.setattr(zoneinfo, "ZoneInfo", no_db)+ assert _tz_issues({"timezone": "Asia/Tokyo", "model": {"provider": "nous"}}) == []+ assert _tz_issues({"timezone": "Asia/Tokio", "model": {"provider": "nous"}}) == []++class TestUnknownTopLevelKeys:"""Arbitrary top-level keys must NOT warn — they are bridged to os.environ.