The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(gateway): a scalar `model:` config no longer crashes session.create
Tekniuma5cf3628e8b0
diff --git a/gateway/session_policy.py b/gateway/session_policy.pyindex 7b9530c85ff..bb36837b292 100644--- a/gateway/session_policy.py+++ b/gateway/session_policy.py@@ -99,7 +99,11 @@ class LocalSessionPolicy: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}+ config = {key: value for key, value in config.items() if value is not None}+ # A scalar ``model: <id>`` (a form every classic loader accepts) is the mapping's ``default``.+ if isinstance(config.get('model'), str):+ config['model'] = {'default': config['model']} if config['model'].strip() else {}+ return configdef build_policy(params, config, *, private_secrets=None, profile_terminal=True):diff --git a/tests/gateway/test_scalar_model_config_policy.py b/tests/gateway/test_scalar_model_config_policy.pynew file mode 100644index 00000000000..06d4345bb2d--- /dev/null+++ b/tests/gateway/test_scalar_model_config_policy.py@@ -0,0 +1,40 @@+"""N46: a scalar ``model: <id>`` config.yaml (a supported form main's loaders accept) must not crash+``session.create``: Desktop's normal create (no explicit model) and a ``--provider`` launch."""+from types import SimpleNamespace++import pytest+++async def test_scalar_model_config_creates_sessions(tmp_path, monkeypatch):+ from gateway import run+ from gateway.config import GatewayConfig+ from gateway.session import SessionStore+ from gateway.session_authority import initialize_session_authority+ from gateway.session_controls import AuthorityConnection+ from gateway.session_policy import restore_policy+ from hermes_state_local import local_receipt++ home = tmp_path / 'home'+ home.mkdir()+ (home / 'config.yaml').write_text('model: scalar-model\nplatform_toolsets:\n cli: []\n')+ monkeypatch.setenv('HERMES_HOME', str(home))+ monkeypatch.setattr(run, '_hermes_home', home)+ store = SessionStore(tmp_path / 'sessions', GatewayConfig())+ runner = SimpleNamespace(session_store=store, _session_db=store._db, adapters={}, _draining=False,+ _cached_agent_for=lambda route: None)+ runner._adapter_for_source = lambda source: runner.adapters.get(source.platform)+ authority = await initialize_session_authority(runner, profile_id=str(home), instance_id='first')+ connection = AuthorityConnection(authority, object(), {'user_id': 'human'})++ async def create(request_id, **params):+ reply = await connection.dispatch({'id': 1, 'method': 'session.create', 'params': {+ 'request_id': request_id, 'source': 'gui', 'cwd': str(tmp_path), **params}})+ assert 'result' in reply, reply+ return restore_policy(local_receipt(authority.db, reply['result']['session_id'])['policy'])++ desktop = await create('desktop')+ assert desktop.model == 'scalar-model' and desktop.config()['model'] == {'default': 'scalar-model'}+ pinned = await create('pinned', provider='custom', base_url='http://127.0.0.1:9/v1')+ assert (pinned.provider, pinned.base_url) == ('custom', 'http://127.0.0.1:9/v1')+ assert pinned.config()['model']['default'] == 'scalar-model'