Skip to content

The agent that grows with you

fix(browser): lightpanda review follow-ups for #99312

kshitijk4poor936b970e281d
diff --git a/hermes_cli/doctor.py b/hermes_cli/doctor.py
index a958482a31c..1af14d38820 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 8e9d47c44a0..3ba7b5860fd 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 c0b16de2ebf..bb64d2c82a9 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 817881dcdca..560fd937ddf 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"