Summary
Implement background chat execution that continues even when the browser is closed or WebSocket disconnects.
Changes
New Files
backend/app/models/chat_execution.py — ChatExecution model for persisting chat state
backend/app/services/chat_executor.py — Background execution service
backend/alembic/versions/202607130808_add_chat_executions_table.py — DB migration
Modified Files
backend/app/api/websocket.py — Modified to create background tasks instead of direct execution
backend/app/models/__init__.py — Added ChatExecution import
Architecture
Before:
WebSocket → Execution → Response
After:
WebSocket → Create Task → Background Executor → DB
↑ ↓
└──────────── Stream Results ←─────────────────┘
Benefits
✅ Chat execution continues when browser is closed
✅ WebSocket can reconnect and resume viewing results
✅ Execution survives network interruptions
✅ Results are persisted in database
Testing
Phase B (Future)
- Heartbeat WebSocket (ping/pong)
- Backoff exponentiel frontend
- Grace window pour reconnexion
Commits
d8aeebb9 — feat: decouple chat execution from WebSocket
03a15169 — fix: set migration down_revision and resolve stash conflicts
Related
- Analysis: OpenClaw and Hermes Agent architectures
- Issue: WebSocket disconnects during long executions
Summary
Implement background chat execution that continues even when the browser is closed or WebSocket disconnects.
Changes
New Files
backend/app/models/chat_execution.py— ChatExecution model for persisting chat statebackend/app/services/chat_executor.py— Background execution servicebackend/alembic/versions/202607130808_add_chat_executions_table.py— DB migrationModified Files
backend/app/api/websocket.py— Modified to create background tasks instead of direct executionbackend/app/models/__init__.py— Added ChatExecution importArchitecture
Before:
After:
Benefits
✅ Chat execution continues when browser is closed
✅ WebSocket can reconnect and resume viewing results
✅ Execution survives network interruptions
✅ Results are persisted in database
Testing
Phase B (Future)
Commits
d8aeebb9— feat: decouple chat execution from WebSocket03a15169— fix: set migration down_revision and resolve stash conflictsRelated