Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions gateway/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,18 @@ def to_dict(self) -> Dict[str, Any]:

@classmethod
def from_dict(cls, data: Dict[str, Any]) -> "SessionResetPolicy":
# Use explicit None checks — dict.get() returns None for keys
# with null/None values, bypassing the default parameter.
at_hour = data.get("at_hour")
if at_hour is None:
at_hour = 4
idle_minutes = data.get("idle_minutes")
if idle_minutes is None:
idle_minutes = 1440
return cls(
mode=data.get("mode", "both"),
at_hour=data.get("at_hour", 4),
idle_minutes=data.get("idle_minutes", 1440),
at_hour=at_hour,
idle_minutes=idle_minutes,
)


Expand Down
26 changes: 26 additions & 0 deletions tests/gateway/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,32 @@ def test_defaults(self):
assert policy.at_hour == 4
assert policy.idle_minutes == 1440

def test_from_dict_explicit_null_values(self):
"""Explicit null values in YAML config should fall back to defaults.

dict.get() returns None (not the default) when the key exists with
a None value, so from_dict must handle this explicitly.
See: https://github.com/NousResearch/hermes-agent/issues/1119
"""
data = {"mode": "both", "at_hour": None, "idle_minutes": None}
policy = SessionResetPolicy.from_dict(data)
assert policy.at_hour == 4
assert policy.idle_minutes == 1440

def test_from_dict_missing_keys(self):
"""Missing keys should also fall back to defaults."""
policy = SessionResetPolicy.from_dict({})
assert policy.mode == "both"
assert policy.at_hour == 4
assert policy.idle_minutes == 1440

def test_from_dict_partial_null(self):
"""Only one field null, the other present with a valid value."""
data = {"at_hour": None, "idle_minutes": 60}
policy = SessionResetPolicy.from_dict(data)
assert policy.at_hour == 4
assert policy.idle_minutes == 60


class TestGatewayConfigRoundtrip:
def test_full_roundtrip(self):
Expand Down