Skip to content

The agent that grows with you

fix(gateway): refuse a Bot Chat create carrying parameters its owner cannot honour

unsupportedpastelsf7b18ebb15f7
diff --git a/gateway/platforms/api_server_bot_chat.py b/gateway/platforms/api_server_bot_chat.py
index c4508e53505..47f216c787e 100644
--- a/gateway/platforms/api_server_bot_chat.py
+++ b/gateway/platforms/api_server_bot_chat.py
@@ -22,6 +22,8 @@ logger = logging.getLogger(__name__)
_PENDING = ('queued', 'claimed')
# Owner of a Bot Chat the gateway mints for a peer's create-if-missing (no native client asked).
_PEER_SUBJECT = 'api-peer'
+# The whole body ``hermes peer dm`` sends (``hermes_cli/subcommands/peer.py::_ensure_bot_chat``).
+_PEER_CREATE_FIELDS = frozenset({'title', 'source'})
def _authority(runner):
@@ -34,7 +36,9 @@ async def create_peer_bot_chat(adapter, body):
authority: the owner mints the chat through the step a first ``bot_relay.deliver`` takes
(``session_bot._create_bot_chat``), so a headless gateway's Bot Chat is a LOCAL session its FIFO
owns, not an API row no remote sender can ever bind (#139370). None when the ordinary handler
- answers: no authority, another title, an explicit id, or the chat exists (its title conflict)."""
+ answers: no authority, another title, an explicit id, or the chat exists (its title conflict).
+ The owner mints on the profile's own policy, so a create carrying anything else (a model
+ lock, route, options, system prompt) is refused by name before anything is written."""
from tools.bot_mode_probe import BOT_CHAT_TITLE
authority = _authority(adapter.gateway_runner)
if (authority is None or str(body.get('title') or '').strip() != BOT_CHAT_TITLE
@@ -42,6 +46,11 @@ async def create_peer_bot_chat(adapter, body):
return None
from aiohttp import web
from gateway.platforms.api_server import _error_response
+ if unsupported := sorted(set(body) - _PEER_CREATE_FIELDS):
+ return _error_response(
+ f"Bot Chat creation refused: bot_chat_parameters_unsupported ({', '.join(unsupported)}); "
+ "the Bot Chat is created with the profile's own model and prompt", 400,
+ code='bot_chat_parameters_unsupported')
from gateway.session_bot import _create_bot_chat
from gateway.session_runtime_workers import track_mutation
actor = Principal(_PEER_SUBJECT, authority.profile_id,
diff --git a/tests/gateway/test_peer_dm_bot_chat_headless.py b/tests/gateway/test_peer_dm_bot_chat_headless.py
index 04444db3ab6..13b43174e40 100644
--- a/tests/gateway/test_peer_dm_bot_chat_headless.py
+++ b/tests/gateway/test_peer_dm_bot_chat_headless.py
@@ -87,6 +87,29 @@ async def test_headless_peer_dm_creates_the_bot_chat_through_its_owner(headless)
assert again.status == 400 and (await again.json())['error']['code'] == 'invalid_title'
+def _sessions(authority):
+ return authority.db._read_all("SELECT id FROM sessions")
+
+
[email protected]('extra, fields', [
+ ({'require_model_lock': True}, 'require_model_lock'),
+ ({'model': 'gpt-x', 'provider': 'openai'}, 'model, provider'),
+ ({'model_options': {'reasoning_effort': 'high'}}, 'model_options'),
+ ({'system_prompt': 'be terse'}, 'system_prompt'),
+ ({'system_prompt': 7}, 'system_prompt'),
+])
+async def test_bot_chat_create_refuses_parameters_its_owner_cannot_honour(headless, extra, fields):
+ # The owner mints the Bot Chat on the profile's own policy; a lock, route or prompt the caller
+ # asked for would be dropped, so the create is refused by name before anything is written.
+ resp = await headless.cli.post("/api/sessions", json={"title": "Bot Chat", "source": "bot_peer_dm", **extra})
+ body = await resp.json()
+ assert resp.status == 400, body
+ assert body['error']['code'] == 'bot_chat_parameters_unsupported', body
+ assert fields in body['error']['message'], body
+ assert _sessions(headless.authority) == []
+
+
@pytest.mark.asyncio
async def test_peer_created_api_bot_chat_is_refused_by_name(headless):
# A row an older gateway minted through the plain API create: no FIFO can own it.