Architecture: How should the frontend recover SSE state after a page refre...

Documentation for Sessions

🏗️ Architecture: How should the frontend recover SSE state after a page refre...

Date: 2026-03-10
Time: 18:58:15 UTC
Session: gspace1-199.7
Agent: backend
Confidence: 90%
Status: ✅ Documented


📋 Decision Context

Question:

How should the frontend recover SSE state after a page refresh during generation?

Task: S199: SSE refresh resilience for generation pipeline


🎯 Decision Made

Chosen:

Backend endpoint GET /module-generation/active/:spaceId finds running sessions. ReplaySubject(50) buffers last 50 events for late-joiners. Frontend polls on page load and reconnects.

Options Considered:

  1. Persist events in MongoDB (heavy, but survives server restart)
  2. IndexedDB on frontend (client-side only, doesn't survive incognito)
  3. In-memory ReplaySubject + poll endpoint (chosen — minimal, leverages existing infra)
  4. WebSocket reconnection (more complex, SSE is simpler)

💭 Reasoning

ROOT CAUSE: SSE connections are stateless — page refresh kills the EventSource and all accumulated state. The user sees nothing after refresh even if generation is still running. The fix has three parts: (1) SessionManager.getActiveSessionBySpace() finds running sessions by spaceId, (2) controller endpoint exposes this for frontend polling, (3) ReplaySubject(50) already buffers events so reconnecting clients get the recent history. This is minimal infrastructure — no new database, no IndexedDB, just leveraging the existing in-memory session state and RxJS buffering.


📁 Files Involved


🔗 Related


Auto-generated by MCP Smart Consolidation