Skip to content

fix: lazy-load CLI execution helpers#340

Open
honor2030 wants to merge 1 commit into
browser-use:mainfrom
honor2030:fix/cli-lazy-agent-helpers
Open

fix: lazy-load CLI execution helpers#340
honor2030 wants to merge 1 commit into
browser-use:mainfrom
honor2030:fix/cli-lazy-agent-helpers

Conversation

@honor2030
Copy link
Copy Markdown

@honor2030 honor2030 commented May 12, 2026

Summary

  • Lazy-load browser_harness.helpers only when executing browser-harness -c ...
  • Keep maintenance commands such as --version and --help from importing user-editable BH_AGENT_WORKSPACE/agent_helpers.py
  • Preserve -c helper availability, including agent workspace helpers, via a dedicated execution namespace

Root cause

run.py imported from .helpers import * at module import time. Since helpers.py immediately loads BH_AGENT_WORKSPACE/agent_helpers.py, even safe maintenance commands could fail or trigger user helper side effects before main() handled --version/--help.

Test Plan

  • RED: uv run --with pytest --with-editable . python -m pytest tests/unit/test_run.py::test_maintenance_commands_do_not_load_agent_helpers tests/unit/test_run.py::test_execution_globals_load_agent_workspace_helpers -q failed before the fix because --version loaded the raising agent_helpers.py and _execution_globals did not exist.
  • GREEN: uv run --with pytest --with-editable . python -m pytest tests/unit/test_run.py::test_maintenance_commands_do_not_load_agent_helpers tests/unit/test_run.py::test_execution_globals_load_agent_workspace_helpers -q2 passed
  • uv run --with pytest --with-editable . python -m pytest tests/unit/test_run.py -q14 passed
  • uv run --with pytest --with-editable . python -m pytest tests -q96 passed
  • uv run --with-editable . python -m compileall -q src tests
  • uv run --with pip --with-editable . python -m pip checkNo broken requirements found.
  • uv run --with pip-audit --with-editable . pip-auditNo known vulnerabilities found (local package skipped because it is not on PyPI)
  • uv run --with ruff --with-editable . ruff check --select B src/browser_harness/run.py tests/unit/test_run.pyAll checks passed!

Summary by cubic

Lazy-load CLI helpers so --help and --version run without importing user workspace code. Scripts run via stdin or -c still get access to browser_harness.helpers and workspace helpers.

  • Bug Fixes
    • Load helpers inside _execution_globals() only during code execution.
    • Keep maintenance commands from importing BH_AGENT_WORKSPACE/agent_helpers.py.
    • Execute code with a namespace exposing public names from browser_harness.helpers.

Written for commit 3f7116d. Summary will update on new commits.

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 2 files

@honor2030 honor2030 force-pushed the fix/cli-lazy-agent-helpers branch from e59a2b1 to 4a38ed6 Compare May 13, 2026 08:32
@honor2030 honor2030 force-pushed the fix/cli-lazy-agent-helpers branch from 4a38ed6 to 3f7116d Compare May 15, 2026 06:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant