The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(api-server): trim RequestKey fallback comment, add import-isolation test
teknium121bc1d377545
diff --git a/gateway/platforms/api_server_runs.py b/gateway/platforms/api_server_runs.pyindex 3873c768899..3976ff02de2 100644--- a/gateway/platforms/api_server_runs.py+++ b/gateway/platforms/api_server_runs.py@@ -13,16 +13,13 @@ from typing import Any, Callable, Dict, List, Optionaltry:from aiohttp import web-except ImportError: # pragma: no cover+except ImportError:web = None # type: ignore[assignment]try:from aiohttp.web_request import RequestKey-except ImportError: # pragma: no cover- # aiohttp < 3.14 does not export RequestKey. Import it separately so its- # absence does not clobber the already-imported ``web`` module: sharing- # one try/except turned ``web`` into None on older aiohttp, making every- # non-streaming ``POST /v1/runs`` reply crash with ``AttributeError:- # 'NoneType' object has no attribute 'json_response'``.+except ImportError:+ # Separate block: aiohttp < 3.14 lacks RequestKey, and a shared except+ # would reset the already-imported ``web`` to None (500 on POST /v1/runs).RequestKey = None # type: ignore[assignment,misc]from gateway.platforms.api_server_room_grants import _json_error, _room_grant_error_responsediff --git a/tests/gateway/test_api_server_runs_import_isolation.py b/tests/gateway/test_api_server_runs_import_isolation.pynew file mode 100644index 00000000000..6de96e0ece2--- /dev/null+++ b/tests/gateway/test_api_server_runs_import_isolation.py@@ -0,0 +1,25 @@+"""Import-time invariant: a missing ``RequestKey`` must not take ``web`` down with it."""++import importlib+import sys+import types++import aiohttp.web_request+from aiohttp import web+++def test_missing_requestkey_keeps_web_module_bound():+ import gateway.platforms.api_server_runs as api_server_runs++ stub = types.ModuleType("aiohttp.web_request")+ real = sys.modules["aiohttp.web_request"]+ sys.modules["aiohttp.web_request"] = stub+ try:+ importlib.reload(api_server_runs)+ assert api_server_runs.web is web+ assert api_server_runs.RequestKey is None+ finally:+ sys.modules["aiohttp.web_request"] = real+ importlib.reload(api_server_runs)++ assert api_server_runs.RequestKey is aiohttp.web_request.RequestKey