Skip to content

feat: Decouple chat execution from WebSocket (Phase A) #759

Description

@up-guillaume

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

  • Unit tests for chat_executor service
  • Integration test: close browser during execution
  • Verify execution continues in background
  • Verify results are visible after reconnect

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

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