fix(gateway): cut api-server startup cost Closes #79047

This commit is contained in:
finn763
2026-09-04 01:37:57 +08:00
committed by kshitij
parent b7d7d2929a
commit 501d8ba4e0
2 changed files with 28 additions and 2 deletions

View File

@@ -425,10 +425,12 @@ def test_routeable_browser_tools_preserve_legacy_gate_without_bound_identity(mon
assert browser_tool.check_browser_snapshot_requirements() is False
def test_bound_browser_request_bypasses_availability_caches():
def test_bound_browser_request_bypasses_availability_caches(monkeypatch):
from gateway import browser_control_broker
from gateway.session_context import clear_session_vars, set_session_vars
from tools.registry import CHECK_FN_CACHE_BYPASS, check_fn_cache_scope
monkeypatch.setattr(browser_control_broker, "browser_control_enabled", lambda: True)
tokens = set_session_vars(
session_id="session-fixture",
browser_control_principal="principal-fixture",
@@ -440,6 +442,25 @@ def test_bound_browser_request_bypasses_availability_caches():
clear_session_vars(tokens)
def test_bound_identity_without_extension_control_keeps_cache_scope(monkeypatch):
"""api_server binds a principal on every request; without the feature flag
that identity must not bypass the availability caches (#79047)."""
from gateway import browser_control_broker
from gateway.session_context import clear_session_vars, set_session_vars
from tools.registry import CHECK_FN_CACHE_BYPASS, check_fn_cache_scope
monkeypatch.setattr(browser_control_broker, "browser_control_enabled", lambda: False)
tokens = set_session_vars(
session_id="session-fixture",
browser_control_principal="principal-fixture",
browser_control_transport_family="local-api",
)
try:
assert check_fn_cache_scope() != CHECK_FN_CACHE_BYPASS
finally:
clear_session_vars(tokens)
def test_registry_advertises_snapshot_through_extension_when_legacy_backend_is_down(
monkeypatch,
):

View File

@@ -269,7 +269,12 @@ def check_fn_cache_scope() -> Optional[str]:
try:
from gateway.session_context import get_session_env
if all(str(get_session_env(k, "") or "").strip() for k in _BROWSER_IDENTITY_KEYS):
return CHECK_FN_CACHE_BYPASS
# api_server binds a server-derived principal + transport family on EVERY request, so
# identity-present != controller-attached; only bypass when the extension-control
# feature is actually on (#79047).
from gateway.browser_control_broker import browser_control_enabled
if browser_control_enabled():
return CHECK_FN_CACHE_BYPASS
except Exception:
pass
try: