Skip to content

[BUG]WebSim state broadcasting fails inside Docker containers due to an event loop conflict, preventing the frontend from receiving real-time status updates #1620

@Gkkkk

Description

@Gkkkk

🐛 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

  1. Start OM1 with Docker Compose:

    docker-compose up om1 -d
  2. Open the frontend:

    http://localhost:8000/
    
  3. Observe frontend status:

    OM Agent Status: OFF
    
  4. 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

  • WebSim should broadcast state updates via WebSocket

  • Frontend should show:

    OM Agent Status: ON
    
  • No asyncio event loop errors should appear


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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions