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:
- Persist events in MongoDB (heavy, but survives server restart)
- IndexedDB on frontend (client-side only, doesn't survive incognito)
- In-memory ReplaySubject + poll endpoint (chosen — minimal, leverages existing infra)
- 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
APIs/backend-vitto-api/src/app/module-generation/session/module-gen-session.manager.tsAPIs/backend-vitto-api/src/app/module-generation/module-generation.service.tsAPIs/backend-vitto-api/src/app/module-generation/module-generation.controller.ts
🔗 Related
- Decision ID:
dev_1773169095533_26foj7b - Session: 199
- Workspace: gspace1
Auto-generated by MCP Smart Consolidation