The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(gateway): coerce profile route IDs to str for YAML ints
Fangliquandf50b5287e8e
diff --git a/gateway/profile_routing.py b/gateway/profile_routing.pyindex 9c265a4d004..897587f365d 100644--- a/gateway/profile_routing.py+++ b/gateway/profile_routing.py@@ -157,6 +157,18 @@ class ProfileRoute:return True+def _coerce_route_id(value: Any) -> Optional[str]:+ """Normalize a route discriminator to str for strict equality matching.++ PyYAML loads unquoted numeric IDs (Discord snowflakes, Telegram negative+ chat ids) as ``int``. Inbound ``SessionSource`` fields are always ``str``+ via ``build_source``, so leaving ints here makes ``matches()`` fail silently.+ """+ if value is None:+ return None+ return str(value)++def parse_profile_routes(raw: Optional[List[Dict[str, Any]]]) -> List[ProfileRoute]:"""Parse profile_routes from config.yaml into ProfileRoute objects.@@ -194,9 +206,9 @@ def parse_profile_routes(raw: Optional[List[Dict[str, Any]]]) -> List[ProfileRouname=name,platform=platform,profile=profile,- guild_id=entry.get("guild_id"),- chat_id=entry.get("chat_id"),- thread_id=entry.get("thread_id"),+ guild_id=_coerce_route_id(entry.get("guild_id")),+ chat_id=_coerce_route_id(entry.get("chat_id")),+ thread_id=_coerce_route_id(entry.get("thread_id")),enabled=entry.get("enabled", True),))diff --git a/tests/gateway/test_profile_routing.py b/tests/gateway/test_profile_routing.pyindex 727831dffa4..45a0d680362 100644--- a/tests/gateway/test_profile_routing.py+++ b/tests/gateway/test_profile_routing.py@@ -52,6 +52,54 @@ class TestParseProfileRoutes:assert parse_profile_routes(None) == []assert parse_profile_routes([]) == []+ def test_coerces_yaml_native_int_ids_to_str(self):+ # PyYAML loads unquoted snowflakes as int; inbound SessionSource IDs are str.+ raw = [+ {+ "name": "server",+ "platform": "discord",+ "profile": "p",+ "guild_id": 111,+ "chat_id": 222,+ "thread_id": 333,+ },+ ]+ routes = parse_profile_routes(raw)+ assert routes[0].guild_id == "111"+ assert routes[0].chat_id == "222"+ assert routes[0].thread_id == "333"+ assert all(isinstance(v, str) for v in (+ routes[0].guild_id, routes[0].chat_id, routes[0].thread_id,+ ))+ matched = match_profile_route(+ routes, "discord", guild_id="111", chat_id="222", thread_id="333",+ )+ assert matched is not None+ assert matched.name == "server"++ def test_coerces_negative_telegram_chat_id(self):+ raw = [+ {+ "name": "tg",+ "platform": "telegram",+ "profile": "p",+ "chat_id": -1001234567890,+ },+ ]+ routes = parse_profile_routes(raw)+ assert routes[0].chat_id == "-1001234567890"+ matched = match_profile_route(routes, "telegram", chat_id="-1001234567890")+ assert matched is not None+ assert matched.name == "tg"++ def test_omitted_ids_remain_none(self):+ routes = parse_profile_routes([+ {"name": "platform-only", "platform": "discord", "profile": "p"},+ ])+ assert routes[0].guild_id is None+ assert routes[0].chat_id is None+ assert routes[0].thread_id is None+class TestMatchProfileRoute: