From 0a91e3cb0215f9f924da2b6cddd8e240c0a303f8 Mon Sep 17 00:00:00 2001 From: starship-s <45587122+starship-s@users.noreply.github.com> Date: Fri, 24 Apr 2026 12:03:42 -0600 Subject: [PATCH] fix: identify WebUI sessions as webui platform (#948) * fix: use webui platform for webui sessions * test: harden WebUI platform hint regression coverage --- api/routes.py | 8 ++++-- api/streaming.py | 4 ++- tests/test_webui_platform_hint.py | 47 +++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 3 deletions(-) create mode 100644 tests/test_webui_platform_hint.py diff --git a/api/routes.py b/api/routes.py index 12c06cdd..e86f310c 100644 --- a/api/routes.py +++ b/api/routes.py @@ -2707,7 +2707,9 @@ def _handle_chat_sync(handler, body): provider=_provider, base_url=_base_url, api_key=_api_key, - platform="cli", + # Identify browser-originated sessions as WebUI so Hermes Agent + # does not inject CLI-specific terminal/output guidance. + platform="webui", quiet_mode=True, enabled_toolsets=_resolve_cli_toolsets(), session_id=s.session_id, @@ -3297,7 +3299,9 @@ def _handle_session_compress(handler, body): provider=resolved_provider, base_url=resolved_base_url, api_key=resolved_api_key, - platform="cli", + # Identify browser-originated sessions as WebUI so Hermes Agent + # does not inject CLI-specific terminal/output guidance. + platform="webui", quiet_mode=True, enabled_toolsets=_resolve_cli_toolsets(), session_id=sid, diff --git a/api/streaming.py b/api/streaming.py index 801b09c3..f5abd978 100644 --- a/api/streaming.py +++ b/api/streaming.py @@ -1212,7 +1212,9 @@ def _run_agent_streaming(session_id, msg_text, model, workspace, stream_id, atta provider=resolved_provider, base_url=resolved_base_url, api_key=resolved_api_key, - platform='cli', + # Identify browser-originated sessions as WebUI so Hermes Agent + # does not inject CLI-specific terminal/output guidance. + platform='webui', quiet_mode=True, enabled_toolsets=_toolsets, fallback_model=_fallback_resolved, diff --git a/tests/test_webui_platform_hint.py b/tests/test_webui_platform_hint.py new file mode 100644 index 00000000..dfe370a8 --- /dev/null +++ b/tests/test_webui_platform_hint.py @@ -0,0 +1,47 @@ +"""Regression: WebUI AIAgent call sites must use platform='webui', not 'cli'. + +These are static source-level checks that will catch any future regression where +a developer accidentally reverts the platform kwarg back to 'cli'. +""" +import pathlib +import re + +REPO_ROOT = pathlib.Path(__file__).parent.parent +PLATFORM_KWARG_RE = r'platform\s*=\s*["\']{platform}["\']' + + +def _load_source(relative_path: str) -> str: + """Load a repository source file with a focused assertion on missing files.""" + path = REPO_ROOT / relative_path + assert path.exists(), f"{relative_path} does not exist" + return path.read_text(encoding="utf-8") + + +def _count_platform_kwargs(source: str, platform: str) -> int: + return len(re.findall(PLATFORM_KWARG_RE.format(platform=re.escape(platform)), source)) + + +def test_streaming_uses_webui_platform(): + """api/streaming.py must pass platform='webui' when constructing AIAgent.""" + streaming_py = _load_source("api/streaming.py") + webui_count = _count_platform_kwargs(streaming_py, "webui") + cli_count = _count_platform_kwargs(streaming_py, "cli") + assert cli_count == 0, ( + f"streaming.py still has {cli_count} platform='cli' AIAgent call(s); convert to 'webui'" + ) + assert webui_count >= 1, ( + f"streaming.py expected ≥1 platform='webui' call, found {webui_count}" + ) + + +def test_routes_uses_webui_platform_for_all_agent_calls(): + """api/routes.py must use platform='webui' for all AIAgent instantiations.""" + routes_py = _load_source("api/routes.py") + webui_count = _count_platform_kwargs(routes_py, "webui") + cli_count = _count_platform_kwargs(routes_py, "cli") + assert cli_count == 0, ( + f"routes.py still has {cli_count} platform='cli' AIAgent call(s); convert to 'webui'" + ) + assert webui_count >= 2, ( + f"routes.py expected ≥2 platform='webui' calls, found {webui_count}" + )