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.
This commit is contained in:
kshitijk4poor
2026-08-31 20:32:50 +05:30
committed by kshitij
parent 8bdf8836e6
commit 936b970e28
4 changed files with 27 additions and 15 deletions
+3 -5
View File
@@ -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:
+13
View File
@@ -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
+3 -6
View File
@@ -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:
+8 -4
View File
@@ -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"