The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(browser): keep bound controller routing authoritative
abundantbeing2039b572f5ea
diff --git a/tests/tools/test_browser_extension_router.py b/tests/tools/test_browser_extension_router.pyindex 9d7d69b1e46..ea796beec7c 100644--- a/tests/tools/test_browser_extension_router.py+++ b/tests/tools/test_browser_extension_router.py@@ -51,23 +51,27 @@ def test_feature_off_calls_existing_backend_once_without_touching_broker():"scope,selected",[(None, None), ("scope-fixture", None)],)-def test_no_exact_capable_controller_preserves_existing_backend(scope, selected):+def test_bound_request_without_exact_capable_controller_fails_closed(scope, selected):+ from gateway.browser_control_broker import ControllerUnavailable+broker = FakeBroker(scope=scope, selected=selected)fallbacks = []- result = route_browser_tool(- "browser_navigate",- {"url": "https://example.test"},- fallback=lambda: fallbacks.append(True) or "legacy-result",- broker=broker,- enabled=True,- session_id="session-fixture",- task_id="task-fixture",- tool_call_id="tool-call-fixture",- )+ with pytest.raises(ControllerUnavailable, match="browser_navigate"):+ route_browser_tool(+ "browser_navigate",+ {"url": "https://example.test"},+ fallback=lambda: fallbacks.append(True) or "unsafe-legacy-result",+ broker=broker,+ enabled=True,+ session_id="session-fixture",+ task_id="task-fixture",+ principal_id="principal-fixture",+ transport_family="local-api",+ tool_call_id="tool-call-fixture",+ )- assert result == "legacy-result"- assert fallbacks == [True]+ assert fallbacks == []assert not any(call[0] == "dispatch" for call in broker.calls)@@ -267,6 +271,58 @@ def test_extension_availability_requires_exact_scope_and_capability(monkeypatch)]+def test_bound_controller_disappearing_after_schema_build_never_falls_back(monkeypatch):+ from gateway.browser_control_broker import (+ BrowserControlBroker,+ ControllerScope,+ ControllerUnavailable,+ )+ from gateway.session_context import clear_session_vars, set_session_vars+ from tools import browser_extension_router++ broker = BrowserControlBroker(command_timeout=0.1)+ scope = ControllerScope(+ principal_id="principal-fixture",+ profile_id="default",+ session_id="session-fixture",+ controller_id="controller-fixture",+ browser_profile_id="browser-profile-fixture",+ transport_family="local-api",+ capabilities=frozenset({"browser_snapshot"}),+ )+ broker.attach(scope, lambda _frame: None, owner="socket-fixture")+ monkeypatch.setattr(+ "gateway.browser_control_broker.browser_control_enabled",+ lambda: True,+ )+ monkeypatch.setattr(+ "gateway.browser_control_broker.get_browser_control_broker",+ lambda: broker,+ )+ tokens = set_session_vars(+ session_id="session-fixture",+ browser_control_principal="principal-fixture",+ browser_control_transport_family="local-api",+ )+ fallbacks = []+ try:+ assert browser_extension_router.extension_controller_available(+ "browser_snapshot"+ ) is True+ assert broker.disconnect_owner("socket-fixture") == 1+ with pytest.raises(ControllerUnavailable, match="browser_snapshot"):+ routed_browser_handler(+ "browser_snapshot",+ {},+ fallback=lambda: fallbacks.append(True) or "unsafe-legacy-result",+ )+ finally:+ clear_session_vars(tokens)+ broker.reset()++ assert fallbacks == []++def test_routeable_browser_tools_preserve_legacy_gate_without_bound_identity(monkeypatch):"""A feature flag alone must not advertise tools outside a bound request."""from gateway import browser_control_brokerdiff --git a/tools/browser_extension_router.py b/tools/browser_extension_router.pyindex 34e1aa59182..7c4cc6cbc63 100644--- a/tools/browser_extension_router.py+++ b/tools/browser_extension_router.py@@ -13,15 +13,13 @@ Routing contract (exercised by ``tests/tools/test_browser_extension_router.py``)default: ``browser.extension_control.enabled`` is false unless explicitlyconfigured, so every real browser action keeps its exact legacy path.-- **No exact server-bound scope ⇒ legacy.** ``broker.scope_for_session(...)``- must return exactly one attached controller scope for the caller's session,- authenticated principal, and transport family. Missing identity, no match,- or ambiguity preserves the existing backend.+- **No server-bound identity ⇒ legacy.** Generic Hermes callers keep the+ existing backend when no authenticated browser-controller identity is bound.-- **No exact capable controller ⇒ legacy.** ``broker.select(scope, action)``- must return a controller whose capability set contains the action.- Controllers currently register with only ``controller.noop``, so real- browser actions never match and always fall back.+- **Bound identity ⇒ authoritative extension lane.** Once the gateway binds a+ browser-controller principal and transport family, missing/ambiguous scope,+ disconnect, or capability mismatch fail closed. A "control this tab" turn+ must never jump to an unrelated local/cloud browser backend.- **Selected controller ⇒ authoritative.** Once a controller is selected thecommand is dispatched to it and its result returned; the legacy backend@@ -111,9 +109,9 @@ def route_browser_tool(args:Tool arguments as received from the model. Never mutated.fallback:- The existing backend handler, called exactly once when the router- decides the extension path must not run (feature off, no scope, or- no capable controller). Must be a zero-argument callable.+ The existing backend handler, called exactly once when the feature is+ off or no server-bound controller identity exists. Must be a+ zero-argument callable.broker:Object exposing ``scope_for_session(**identity) -> scope|None``,``select(scope, capability) -> controller|None`` and@@ -125,7 +123,8 @@ def route_browser_tool(Caller session hints forwarded to ``scope_for_session``.principal_id/transport_family:Server-bound caller identity. Both are mandatory when the feature is- enabled; missing values fail closed to the existing backend.+ enabled; missing values preserve the existing backend for generic+ Hermes callers.tool_call_id:Caller tool-call id forwarded verbatim to ``dispatch``.@@ -148,13 +147,19 @@ def route_browser_tool(transport_family=transport_family,)if scope is None:- # No unambiguous attached session scope: preserve existing backend.- return fallback()+ from gateway.browser_control_broker import ControllerUnavailable++ raise ControllerUnavailable(+ f"bound browser controller unavailable for {action}"+ )controller = broker.select(scope, action)if controller is None:- # No controller capable of this exact action: preserve existing backend.- return fallback()+ from gateway.browser_control_broker import ControllerUnavailable++ raise ControllerUnavailable(+ f"bound browser controller cannot execute {action}"+ )# A controller was selected: it is authoritative. Never retry through the# existing backend, whatever happens here. Registry handlers must return adiff --git a/website/docs/user-guide/features/api-server.md b/website/docs/user-guide/features/api-server.mdindex 18dd5f4e622..9d0d587ca4b 100644--- a/website/docs/user-guide/features/api-server.md+++ b/website/docs/user-guide/features/api-server.md@@ -298,6 +298,14 @@ Requested capabilities outside that list are filtered out. Raw CDP, arbitraryscript evaluation, console access, uploads, image extraction, and vision are notpart of the controller protocol.+When a request has no bound controller identity, or when the feature is disabled,+Hermes preserves the existing browser backend. Once the gateway binds a+controller principal and transport family to the request, that extension lane+is authoritative: missing, ambiguous, disconnected, or incapable controllers+fail closed instead of silently switching to a different local/cloud browser.+After an exact controller is selected, its result or error is authoritative and+Hermes never retries the same action through another backend.+### Local API registration1. Send an authenticated `POST /v1/browser-control/register` with