🐛 Bug: WebSim WebSocket not broadcasting state in Docker (event loop already running)
Environment
- OS: Windows 11 (likely affects other platforms using Docker)
- Docker: Docker Desktop 29.1.3
- Python (container): 3.10.19
- OM1 version:
main branch (2026-01-18)
Steps to Reproduce
-
Start OM1 with Docker Compose:
-
Open the frontend:
-
Observe frontend status:
-
Check container logs:
docker logs om1 | grep -i "websim\|event loop"
Actual Behavior
The container repeatedly logs:
2026-01-18 10:42:09 - WARNING - Websim tick error: This event loop is already running
/app/OM1/src/simulators/plugins/WebSim.py:589: RuntimeWarning: coroutine 'WebSim.broadcast_state' was never awaited
loop.create_task(self.broadcast_state())
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
WebSocket state updates are never delivered to the frontend.
Expected Behavior
Impact
- ✅ Backend core logic, APIs, and AI processing work normally
- ❌ Frontend cannot display real-time agent status
- ❌ WebSocket communication is broken
Root Cause
The issue originates from:
src/simulators/plugins/WebSim.py:589
loop.create_task(self.broadcast_state())
In Docker, the asyncio event loop is already running in another thread.
Calling loop.create_task() in this context raises:
This event loop is already running
As a result, the coroutine is never awaited and WebSocket broadcasting fails.
Suggested Fixes
Option 1: Allow nested event loops with nest_asyncio
import nest_asyncio
nest_asyncio.apply()
Option 2: Use thread-safe coroutine submission
asyncio.run_coroutine_threadsafe(
self.broadcast_state(),
loop
)
Option 3: Safely handle running vs non-running loops
import asyncio
def safe_create_task(coro):
try:
loop = asyncio.get_running_loop()
# Loop already running
return asyncio.ensure_future(coro)
except RuntimeError:
# No running loop
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
return loop.create_task(coro)
Logs
Full error log
2026-01-18 10:42:01 - INFO - Initializing WebSim...
2026-01-18 10:42:01 - INFO - Starting WebSim server thread...
2026-01-18 10:42:02 - INFO - WebSim server started successfully - Open http://localhost:8000 in your browser
2026-01-18 10:42:09 - WARNING - Websim tick error: This event loop is already running
/app/OM1/src/simulators/plugins/WebSim.py:589: RuntimeWarning: coroutine 'WebSim.broadcast_state' was never awaited
loop.create_task(self.broadcast_state())
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
Backend Verification
API calls succeed:
docker logs om1 | grep "HTTP/1.1 200 OK"
Example output:
2026-01-18 10:41:03 - INFO - HTTP Request: POST https://api.openmind.org/api/core/openai/chat/completions "HTTP/1.1 200 OK"
AI agents are processing normally:
docker logs om1 | grep "Spot"
Related Files
src/simulators/plugins/WebSim.py
docker-compose.yml
Dockerfile
Contact
bobcrypto66@gmail.com
🐛 Bug: WebSim WebSocket not broadcasting state in Docker (event loop already running)
Environment
mainbranch (2026-01-18)Steps to Reproduce
Start OM1 with Docker Compose:
Open the frontend:
Observe frontend status:
Check container logs:
Actual Behavior
The container repeatedly logs:
WebSocket state updates are never delivered to the frontend.
Expected Behavior
WebSim should broadcast state updates via WebSocket
Frontend should show:
No asyncio event loop errors should appear
Impact
Root Cause
The issue originates from:
src/simulators/plugins/WebSim.py:589In Docker, the asyncio event loop is already running in another thread.
Calling
loop.create_task()in this context raises:As a result, the coroutine is never awaited and WebSocket broadcasting fails.
Suggested Fixes
Option 1: Allow nested event loops with
nest_asyncioOption 2: Use thread-safe coroutine submission
Option 3: Safely handle running vs non-running loops
Logs
Full error log
Backend Verification
API calls succeed:
Example output:
AI agents are processing normally:
Related Files
src/simulators/plugins/WebSim.pydocker-compose.ymlDockerfileContact
bobcrypto66@gmail.com