From 936b970e281d5d28e930c5698f36bc4ebb54c7ba Mon Sep 17 00:00:00 2001 From: kshitijk4poor <82637225+kshitijk4poor@users.noreply.github.com> Date: Mon, 31 Aug 2026 20:32:50 +0530 Subject: [PATCH] fix(browser): lightpanda review follow-ups for #99312 - lightpanda_engine_status: check use_real_profile before the cloud provider, matching browser_exec's actual resolution order (real-profile resolution runs before backend resolution), so /browser status and hermes doctor name the right shadowing setting when both are set. - launch_lightpanda: drop the unreachable Windows popen_kwargs branch (find_lightpanda_binary returns None on nt, launch errors out earlier). - doctor: drop the over-defensive try/except around the cached _using_lightpanda_engine() config read. - Docstring: 'no-I/O gates' -> 'no network I/O (config reads only)'. - New test pinning real-profile-over-cloud-provider reason precedence. --- hermes_cli/doctor.py | 8 +++----- tests/tools/test_browser_lightpanda.py | 13 +++++++++++++ tools/browser_lightpanda.py | 9 +++------ tools/browser_tool.py | 12 ++++++++---- 4 files changed, 27 insertions(+), 15 deletions(-) diff --git a/hermes_cli/doctor.py b/hermes_cli/doctor.py index a958482a31..1af14d3882 100644 --- a/hermes_cli/doctor.py +++ b/hermes_cli/doctor.py @@ -2600,11 +2600,9 @@ def run_doctor(args): except Exception: pass else: - try: - _lp_selected = _using_lightpanda_engine() - except Exception: - _lp_selected = False - if _lp_selected: + # _using_lightpanda_engine() is a cached config read — a failure + # there would be exceptional, not something to silently hide. + if _using_lightpanda_engine(): try: _lp_used, _lp_reason = lightpanda_engine_status() except Exception as e: diff --git a/tests/tools/test_browser_lightpanda.py b/tests/tools/test_browser_lightpanda.py index 8e9d47c44a..3ba7b5860f 100644 --- a/tests/tools/test_browser_lightpanda.py +++ b/tests/tools/test_browser_lightpanda.py @@ -568,6 +568,19 @@ class TestLightpandaEngineStatus: used, reason = bt.lightpanda_engine_status() assert used is False and "use_real_profile" in reason + def test_real_profile_wins_over_cloud_provider(self, monkeypatch): + """browser_exec resolves real-profile before the backend, so with + both set the real-profile toggle is the actual shadow.""" + provider = MagicMock() + provider.provider_name.return_value = "Browserbase" + bt = self._gates( + monkeypatch, + _use_real_profile=lambda: True, + _get_cloud_provider=lambda: provider, + ) + used, reason = bt.lightpanda_engine_status() + assert used is False and "use_real_profile" in reason + # --------------------------------------------------------------------------- # Browser Use mode session lifecycle diff --git a/tools/browser_lightpanda.py b/tools/browser_lightpanda.py index c0b16de2eb..bb64d2c82a 100644 --- a/tools/browser_lightpanda.py +++ b/tools/browser_lightpanda.py @@ -221,12 +221,9 @@ def launch_lightpanda( argv.append("--block-private-networks") log_path = str(_state_dir() / f"{session_name}.log") - if os.name == "nt": # pragma: no cover - no Windows build today - from hermes_cli._subprocess_compat import windows_hide_flags - - popen_kwargs: dict = {"creationflags": windows_hide_flags(), "close_fds": True} - else: - popen_kwargs = {"start_new_session": True} + # No Windows branch here: find_lightpanda_binary() returns None on nt, + # so launch always errors out above before reaching the spawn. + popen_kwargs = {"start_new_session": True} try: with open(log_path, "wb") as log_file: diff --git a/tools/browser_tool.py b/tools/browser_tool.py index 817881dcdc..560fd937dd 100644 --- a/tools/browser_tool.py +++ b/tools/browser_tool.py @@ -1148,8 +1148,9 @@ def lightpanda_engine_status() -> Tuple[bool, str]: CDP override, Browser Use cloud, the real-profile toggle) or, when it is in use, which driver runs it. Mirrors the precedence of ``_should_inject_engine`` (built-in tools) and - ``browser_use_cli._resolve_backend_cdp`` (Browser Use mode) using only - no-I/O gates, so ``/browser status`` and ``hermes doctor`` can call it. + ``browser_use_cli._resolve_backend_cdp`` (Browser Use mode) using gates + that do no network I/O (config reads only), so ``/browser status`` and + ``hermes doctor`` can call it. """ if not _using_lightpanda_engine(): return False, "" @@ -1157,6 +1158,11 @@ def lightpanda_engine_status() -> Tuple[bool, str]: return False, "a CDP override is active (/browser connect or browser.cdp_url)" if _is_camofox_mode(): return False, "Camofox is the selected browser (CAMOFOX_URL)" + # Real-profile is checked before the cloud provider: in browser_exec the + # real-profile resolution runs before backend resolution, so with both + # set it is the real-profile toggle that actually claims the session. + if _use_real_profile(): + return False, "browser.use_real_profile is on (Lightpanda cannot load a Chromium profile)" try: provider = _get_cloud_provider() except Exception: @@ -1182,8 +1188,6 @@ def lightpanda_engine_status() -> Tuple[bool, str]: return False, "Browser Use cloud (BROWSER_USE_API_KEY) is selected" except Exception as e: logger.debug("legacy Browser Use cloud check failed: %s", e) - if _use_real_profile(): - return False, "browser.use_real_profile is on (Lightpanda cannot load a Chromium profile)" if bu_mode: return True, "Browser Use mode: Hermes spawns `lightpanda serve` per session" return True, "built-in browser tools: agent-browser --engine lightpanda"