Skip to content

fix(browser): set event loop on calling thread before nest_asyncio.apply#454

Open
Hweinstock wants to merge 1 commit intostrands-agents:mainfrom
Hweinstock:fix/browser-event-loop-thread-safety
Open

fix(browser): set event loop on calling thread before nest_asyncio.apply#454
Hweinstock wants to merge 1 commit intostrands-agents:mainfrom
Hweinstock:fix/browser-event-loop-thread-safety

Conversation

@Hweinstock
Copy link
Copy Markdown

@Hweinstock Hweinstock commented Apr 16, 2026

Description

Fix a bug in the browser tool that causes it to fail when invoked async. See issue for more information.

The solution is to verify that the event loop is set on the thread that executes the browser tool so that it doesn't matter what thread executes the tool.

Related Issues

Documentation PR

N/A

Type of Change

Bug fix

Testing

How have you tested the change? Verify that the changes do not break functionality or introduce warnings in consuming repositories: agents-docs, agents-tools, agents-cli

  • I ran hatch run prepare

  • Added a unit test to simulate the scenario.

  • Patched the import in agent code using browser, and confirmed it works e2e.

patch code used:


loop = browser_instance._loop
original = browser_instance._execute_async

def _patched(coro):
   asyncio.set_event_loop(loop)
   return original(coro)
 
browser_instance._execute_async = _patched

which is effectively the underlying implementation.

Checklist

  • I have read the CONTRIBUTING document
  • I have added any necessary tests that prove my fix is effective or my feature works
  • I have updated the documentation accordingly
  • I have added an appropriate example to the documentation to outline the feature
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@Hweinstock Hweinstock force-pushed the fix/browser-event-loop-thread-safety branch from 82102bb to 4a3e2b3 Compare April 16, 2026 18:47
@Hweinstock Hweinstock force-pushed the fix/browser-event-loop-thread-safety branch from 4a3e2b3 to 9379ff6 Compare April 16, 2026 18:51
@Hweinstock Hweinstock marked this pull request as ready for review April 16, 2026 22:17
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