Architecture: How to prevent page refresh/tab crash from losing 8-10 minut...

Documentation for Sessions

🏗️ Architecture: How to prevent page refresh/tab crash from losing 8-10 minut...

Date: 2026-02-23
Time: 21:06:45 UTC
Session: gspace1-139.3
Agent: backend
Confidence: 94%
Status: ✅ Documented


📋 Decision Context

Question:

How to prevent page refresh/tab crash from losing 8-10 minutes of generation work?

Task: S138.6 generation process persistence and recovery


🎯 Decision Made

Chosen:

URL-based persistence: Added process/:processId route, activeSessionId signal in WorkflowStateService, URL auto-update via effect when sessionId received, reconnectToGeneration() in ngOnInit that checks backend status then reconnects to SSE stream or restores completed state

Options Considered:

  1. Only use sessionStorage (current approach — doesn't survive tab crash)
  2. Add processId to URL + backend reconnection via existing SSE stream endpoint
  3. Use IndexedDB for full state persistence

💭 Reasoning

The backend already has 80% of the infrastructure built: GET /stream/:sessionId for SSE reconnection, GET /status/:sessionId for state check, POST /resume/:sessionId for checkpoint resume, ReplaySubject(50) for late-join event replay, and MongoDB checkpoints per-phase. The frontend was missing three things: (1) a route with processId, (2) capturing the sessionId from SSE events and pushing it to the URL, (3) checking the route on init and reconnecting. This approach makes generation bookmarkable and shareable, survives page refresh and tab crash (URL persists in browser history), and uses the existing backend infrastructure without new endpoints. localStorage backup ensures the processId is recoverable even without the URL (e.g., reopening browser).


📁 Files Involved


🔗 Related


Auto-generated by MCP Smart Consolidation