semblance-dev/backend/app
Vadym Samoilenko b4978989a5 Fix AI autonomous mode: cross-loop WebSocket emit + polling fallback
The AI Runner runs on a dedicated background thread with its own asyncio
event loop. When it emitted WebSocket events via sio.emit(), the call
happened on the wrong loop (AI Runner's vs ASGI/Quart's), causing silent
failures — messages were saved to MongoDB but never reached the frontend.

Additionally, the frontend HTTP polling fallback was never enabled when
WebSocket appeared connected, leaving no way to discover missed messages.

- websocket_manager_async.py: store ASGI main loop reference; detect
  cross-loop calls in emit_to_focus_group and use run_coroutine_threadsafe
  to schedule emits on the correct loop
- __init__.py: register the ASGI event loop with the WebSocket manager
  in before_serving hook
- FocusGroupSession.tsx: always poll fetchMessages every 3s during AI mode
  as a reliability fallback regardless of WebSocket status

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-23 18:22:24 +00:00
..
auth Apply Jintech security audit remediation (sprint 3) — 87/92 findings fixed 2026-03-20 12:51:18 +00:00
models Fix focus group create: 500 on update + 400 on autosave 2026-03-23 15:20:40 +00:00
routes Allow document uploads (PDF, DOCX, TXT, etc.) as focus group assets 2026-03-23 17:08:30 +00:00
services Allow document uploads (PDF, DOCX, TXT, etc.) as focus group assets 2026-03-23 17:08:30 +00:00
utils Fix make_serializable import — move to utils/__init__.py (was shadowed by utils/ package) 2026-03-20 13:33:11 +00:00
.DS_Store changed permissions 2025-12-19 19:26:16 +00:00
__init__.py Fix AI autonomous mode: cross-loop WebSocket emit + polling fallback 2026-03-23 18:22:24 +00:00
db.py Apply Jintech security audit remediation (sprint 3) — 87/92 findings fixed 2026-03-20 12:51:18 +00:00
extensions.py changed permissions 2025-12-19 19:26:16 +00:00
websocket_debug_tap.py changed permissions 2025-12-19 19:26:16 +00:00
websocket_manager.py Apply Jintech security audit remediation (sprint 3) — 87/92 findings fixed 2026-03-20 12:51:18 +00:00
websocket_manager_async.py Fix AI autonomous mode: cross-loop WebSocket emit + polling fallback 2026-03-23 18:22:24 +00:00