Real-Time Auto-Update Architecture (SSE)
Generated artifact. Do not edit manually.
Generated by:
scripts/build_compendia.pyRegenerate with:python3 scripts/build_compendia.py --compendium dev-handbook --web-and-texSource of truth:docs/dev/source/
Language / Sprache: English (EN) · Deutsch (DE) | PDF: English PDF · Deutsches PDF
Compendium: §1 Documentation Guidelines · §2 Landscape JSON Reference · §3 Minimal Schema & Fallback · §4 Authoring Editors · §5 Graph Editor · §6 Flashcard Editor · §7 Node Ordering · §8 Liquibase · §9 Auto-Update (SSE)
9. Real-Time Auto-Update Architecture (SSE)
When an external AI coach (via MCP or REST) persists mastery or switches the active goal, the Cockpit WebGUI updates immediately without manual page reloads through Server-Sent Events (SSE) (Client-State Sync).
9.1. Backend Event Bus, SSE Endpoint, and React Reconnection Hook
LearnerService write -> LearnerStateChangedEvent
-> SseService (SseEmitter map + ~25s heartbeat)
-> GET /api/ui/updates/{skillpilotId} (text/event-stream)
-> useLearnerUpdates(skillpilotId) -> refreshMastery() / state reload
- Spring event publication: State mutations in
LearnerService.javapublishLearnerStateChangedEvent(MASTERY_UPDATE,GOAL_UPDATE/ACTIVE_GOAL_UPDATE). - SSE controller & emitter management:
UpdateControllerexposesGET /api/ui/updates/{skillpilotId}(text/event-stream), backed bySseServicemaintaining per-learnerSseEmitterregistrations, automatic cleanup on completion/timeout/IO error, and periodic~25sheartbeatcomments so reverse proxies (Nginx/Cloudflare) keep idle streams open. - Frontend hook (
useLearnerUpdates): Opens a native browserEventSource, triggersrefreshMastery()and active-goal state reloads on incoming events, and reconnects with bounded exponential backoff on network drops. - Scaling boundary: In-memory NIO
SseEmitterfan-out handles single-node deployments with minimal overhead; horizontal multi-instance deployments require an external pub/sub relay (such as Redis Pub/Sub or PostgreSQLLISTEN/NOTIFY) so events broadcast across all backend replicas.