Skip to content

The agent that grows with you

fix(gateway): a null config section reads as absent in the frozen policy

teknium1638feb84cb01
diff --git a/gateway/session_policy.py b/gateway/session_policy.py
index 89a774fe71a..5aa15e8e8fc 100644
--- a/gateway/session_policy.py
+++ b/gateway/session_policy.py
@@ -33,7 +33,7 @@ class LocalSessionPolicy:
ignore_user_config: bool = False
def config(self, authority=None):
- config = json.loads(self.config_json)
+ config = present_sections(json.loads(self.config_json))
if self.config_secret_ref is not None and authority is not None:
from gateway.session_policy_credentials import recover_config_secrets
secrets = recover_config_secrets(authority, self)
@@ -76,6 +76,12 @@ class LocalSessionPolicy:
return resolve_reasoning_config(self.config(), self.model or '')
+def present_sections(config):
+ """A bare ``gateway:`` key parses as YAML null; like load_config's merge (#58277), treat it as absent so
+ ``cfg.get('gateway', {}).get(...)`` reads the default instead of crashing a fresh install's first turn."""
+ return {key: value for key, value in config.items() if value is not None}
+
+
def build_policy(params, config, *, private_secrets=None, profile_terminal=True):
from hermes_cli.tools_config import _get_platform_tools
from toolsets import validate_toolset
@@ -103,7 +109,7 @@ def build_policy(params, config, *, private_secrets=None, profile_terminal=True)
raise RuntimeStoreError('invalid_params')
from gateway.session_local_editor import validate_editor
validate_editor(source, params.get('editor'))
- config = json.loads(json.dumps(config))
+ config = present_sections(json.loads(json.dumps(config)))
from urllib.parse import urlsplit
from hermes_constants import parse_reasoning_effort
for key in ('provider', 'base_url'):
diff --git a/tests/gateway/test_session_policy.py b/tests/gateway/test_session_policy.py
index 0bba0e93688..bfe3843cdde 100644
--- a/tests/gateway/test_session_policy.py
+++ b/tests/gateway/test_session_policy.py
@@ -121,3 +121,17 @@ def test_ordinary_daemon_cli_launch_policy(tmp_path):
print(json.dumps(json.loads(result.stdout.splitlines()[-1])))
+def test_null_config_sections_read_as_absent(tmp_path):
+ # A fresh install's config.yaml carries a bare ``gateway:`` (YAML null); the managed-worker gate chains
+ # ``.get('gateway', {}).get(...)`` on the frozen policy and must read the default, not crash the turn.
+ from gateway.session_policy import build_policy, LocalSessionPolicy
+ from dataclasses import replace
+ import json
+
+ cfg = {'gateway': None, 'display': None, 'platform_toolsets': {'cli': ['terminal']}}
+ policy = build_policy({'source': 'cli', 'cwd': str(tmp_path)}, cfg)
+ assert policy.config().get('gateway', {}).get('managed_workers') is None
+ legacy = replace(policy, config_json=json.dumps(cfg)) # persisted before normalization
+ assert isinstance(legacy, LocalSessionPolicy)
+ assert legacy.config().get('display', {}).get('busy_input_mode', 'interrupt') == 'interrupt'
+