[BUG] Event loop construction under socket-blocking test guards fails on Windows (Network is disabled)
Description
On Windows, every CrewAI test that emits an event (directly or via Flow/Crew construction) dies with RuntimeError: Network is disabled when the test session uses a socket-blocking guard such as pytest-recording's --block-network (which crewAI's own root addopts enable by default) or pytest-socket's --disable-socket.
Root cause
CrewAIEventsBus._ensure_executor_initialized()(lib/crewai/src/crewai/events/event_bus.py) and_run_sync()(lib/crewai/src/crewai/utilities/file_store.py) construct asyncio event loops lazily.- On Windows, asyncio builds every event loop's self-pipe with an emulated
socket.socketpair()that performs a realconnect()to 127.0.0.1 (proactor_events.py:787→socket.py:643 csock.connect(...)). - Socket-blocking guards patch
socket.socket.connectand reject that internal, non-network self-pipe.
On Linux the self-pipe is built via os.socketpair() and never calls connect(), which is why the ubuntu-only CI never sees this.
Evidence
Local Windows 11 run of the full suite (pytest with the repo's own addopts):
- 2224 failures with
RuntimeError: Network is disabled; every traceback passes throughevent_bus.py ... _ensure_executor_initialized→asyncio.new_event_loop()→proactor_events.py: _make_self_pipe→socket.socketpair→pytest_recording/network.py: network_guard. - A further ~441 failures are the cascade (
RuntimeError: no running event loopafter the failed init). - Minimal repro (Windows, with
--block-networkin addopts):pytest lib/crewai/tests/test_flow_conversation.py -q— the first Flow construction fails before any test logic runs.
Expected behavior
CrewAI's own test suite should run on Windows with the repo's default socket-blocking addopts; emitting an event is not network access.
Suggested fix
Temporarily restore the pristine C-level socket.socket.connect only while the event-bus loop is constructed (event bus + file store), then put the guard back exactly as it was, so real network calls stay blocked. Happy to send that change with a regression test.
pytest-recording 0.14.1 (released today) allows socketpair() under --block-network (kiwicom/pytest-recording#213), so the event-loop failure is fixed upstream for that plugin. Once this lands, the guard added in #8051 should no longer be needed. Happy to help simplify it then.