Skip to content

fix: chat.py ChatManager stores all state in-memory — messages and escalations lost on restart #124

@BigBen-7

Description

@BigBen-7

Description

src/chat.py holds all conversation history, escalation events, and active connections entirely in instance variables:

self.message_history: Dict[str, List[ChatMessage]] = {}
self.escalations: List[EscalationEvent] = []

A pod restart, dyno cycle, or deployment wipes every conversation. Users lose their support history and any pending escalations silently disappear — a critical reliability gap for a support chat system.

Requirements & context

  • Create a src/chat_store.py module with a ChatStore class that persists messages and escalations to Postgres using the existing SQLAlchemy setup
  • Add two new SQLAlchemy models (or Alembic migrations): chat_messages and chat_escalations tables mirroring the ChatMessage and EscalationEvent Pydantic models
  • Update ChatManager.send_message to persist each message to the DB (async-safe — use asyncio.to_thread if using sync SQLAlchemy)
  • Update ChatManager.get_message_history to fall back to the DB when the in-memory cache is empty (i.e. after a restart)
  • Update ChatManager.escalate_conversation to persist the escalation event
  • Active WebSocket connections remain in-memory (they cannot be persisted) — document this clearly

Suggested execution

git checkout -b feat/chat-persistent-storage
  • Create src/chat_store.py with ChatStore
  • Add SQLAlchemy models and Alembic migration
  • Update ChatManager to call ChatStore for read/write operations
  • Write tests confirming messages survive a simulated manager restart (new instance reads from DB)

Guidelines

  • Do not change the WebSocket or HTTP API contracts
  • PR must include: Closes #[issue_id]
  • Timeframe: 96 hours

Metadata

Metadata

Labels

Stellar WaveIssues in the Stellar wave programbugSomething isn't workingchatChat system and real-time messaging

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions