fix: Python 3.14 compatibility for asyncio in CLI entry points#4629
fix: Python 3.14 compatibility for asyncio in CLI entry points#4629passionworkeer wants to merge 1 commit intobrowser-use:mainfrom
Conversation
….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
There was a problem hiding this comment.
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 withasyncio.run(...)in CLImain()forsetup,doctor, andtunnelsubcommands. - Add CI tests that invoke the CLI
main()entry point for key commands and assertasyncio.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. |
There was a problem hiding this comment.
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.
| 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. |
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:
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
Testing
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 acrosssetup,doctor, andtunnelcommands.asyncio.get_event_loop().run_until_complete(...)withasyncio.run(...)inbrowser_use/skill_cli/main.pyforsetup,doctor, andtunnel(start/stop/--all).tests/ci/test_cli_entry_points.pycovering CLI entry points and assertingasyncio.get_event_loop()is never called.Written for commit 15f0298. Summary will update on new commits.