Skip to content

fix: Python 3.14 compatibility for asyncio in CLI entry points#4629

Closed
passionworkeer wants to merge 1 commit intobrowser-use:mainfrom
passionworkeer:fix/python314-v3
Closed

fix: Python 3.14 compatibility for asyncio in CLI entry points#4629
passionworkeer wants to merge 1 commit intobrowser-use:mainfrom
passionworkeer:fix/python314-v3

Conversation

@passionworkeer
Copy link
Copy Markdown

@passionworkeer passionworkeer commented Apr 7, 2026

Summary

Replace deprecated asyncio.get_event_loop().run_until_complete(coro) with asyncio.run(coro) in CLI entry points (browser-use skill-cli main entry).

Problem

Issue #4626 / #4447: browser-use fails on Python 3.14 because asyncio.get_event_loop() raises RuntimeError when called outside an async context (behavior was removed/changed in Python 3.14).

Fix

In browser_use/skill_cli/main.py, replace all 5 occurrences of:

  • loop = asyncio.get_event_loop(); loop.run_until_complete(...) with asyncio.run(...)
  • asyncio.get_event_loop().run_until_complete(...) with asyncio.run(...)

asyncio.run() is the recommended approach since Python 3.7 and works correctly on Python 3.14. Compatible with Python 3.11+ (repo requires Python >=3.11,<4.0).

Changes

  • browser_use/skill_cli/main.py: 5 occurrences fixed (setup, doctor, tunnel stop --all, tunnel stop , tunnel start)
  • tests/ci/test_cli_entry_points.py: NEW - 169 lines of tests covering setup, doctor, tunnel entry points + regression tests verifying get_event_loop() is NOT called

Testing

  • All tests pass on Python 3.11+
  • Added regression tests to ensure asyncio.get_event_loop() is never called during CLI execution

Fixes #4626
Fixes #4447


Summary by cubic

Fix CLI crashes on Python 3.14 by replacing deprecated event loop calls with asyncio.run. Adds tests to prevent regressions across setup, doctor, and tunnel commands.

  • Bug Fixes
    • Replaced all asyncio.get_event_loop().run_until_complete(...) with asyncio.run(...) in browser_use/skill_cli/main.py for setup, doctor, and tunnel (start/stop/--all).
    • Added tests/ci/test_cli_entry_points.py covering CLI entry points and asserting asyncio.get_event_loop() is never called.

Written for commit 15f0298. Summary will update on new commits.

….14 compatibility

Fixes browser-use CLI failing on Python 3.14 with:
RuntimeError: There is no current event loop in thread 'MainThread'

Replace all deprecated asyncio.get_event_loop().run_until_complete(coro)
with the modern asyncio.run(coro) which works correctly on Python 3.14.

Changes:
- setup command: loop = asyncio.get_event_loop(); loop.run_until_complete(...) -> asyncio.run(...)
- doctor command: same pattern
- tunnel stop --all: asyncio.get_event_loop().run_until_complete(...) -> asyncio.run(...)
- tunnel stop <port>: same
- tunnel start: same

Added tests/ci/test_cli_entry_points.py with:
- Tests for setup, doctor, tunnel entry points
- Regression tests verifying get_event_loop() is NOT called

Fixes browser-use#4626
Fixes browser-use#4447
Copilot AI review requested due to automatic review settings April 7, 2026 09:46
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

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates the browser-use CLI entry point to avoid asyncio.get_event_loop() usage that breaks on Python 3.14, aligning CLI coroutine execution with modern asyncio.run() semantics and adding regression coverage.

Changes:

  • Replace asyncio.get_event_loop().run_until_complete(...) patterns with asyncio.run(...) in CLI main() for setup, doctor, and tunnel subcommands.
  • Add CI tests that invoke the CLI main() entry point for key commands and assert asyncio.get_event_loop() is not called.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
browser_use/skill_cli/main.py Switch CLI async execution from get_event_loop().run_until_complete(...) to asyncio.run(...) for Python 3.14 compatibility.
tests/ci/test_cli_entry_points.py Add coverage for CLI entry points and runtime regression checks to ensure asyncio.get_event_loop() is not invoked.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

"""Regression tests to ensure asyncio.get_event_loop() is NOT called during CLI execution.

These tests verify that the deprecated asyncio.get_event_loop() API is absent
in all CLI commands, preventing Python 3.14+ DeprecationWarning issues.
Copy link

Copilot AI Apr 7, 2026

Choose a reason for hiding this comment

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

The docstring says these tests prevent Python 3.14+ "DeprecationWarning" issues, but the reported 3.14 failure mode is a RuntimeError (no current event loop). Consider updating the wording to reflect the actual behavior being guarded against (RuntimeError / removed get_event_loop behavior) to avoid misleading future readers.

Suggested change
in all CLI commands, preventing Python 3.14+ DeprecationWarning issues.
in all CLI commands, preventing Python 3.14+ RuntimeError failures when
no current event loop exists.

Copilot uses AI. Check for mistakes.
@laithrw laithrw closed this Apr 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants