package gateway import ( "context" ) // wsReplayLimit is the number of most-recent messages replayed to a connecting // client. It is intentionally small so a reconnect is cheap; the frontend pulls // the full active-session history via REST (design/16 §4.1) and the replay is // only there to give a brand-new connection immediate context. const wsReplayLimit = 50 // replayHistory sends the most recent messages for sessionID to a single, // freshly-registered connection as a ws "history" event. It is best-effort: a // nil store or a read error skips the replay silently. Thinking is NOT included // (design/16 §6) so the frame never leaks chain-of-thought to a connection whose // role the gateway did not restrict on upgrade. func (h *hub) replayHistory(c *wsConn, sessionID string) { if h.history == nil { return } msgs, err := h.history.Recent(context.Background(), sessionID, wsReplayLimit) if err != nil { h.log.Warn("history replay", "err", err, "session", sessionID) return } out := make([]historyMessage, 0, len(msgs)) for _, m := range msgs { wire := toHistoryMessage(m) wire.Thinking = "" out = append(out, wire) } c.enqueueJSON(wsEvent{Type: "history", SessionID: sessionID, Data: map[string]any{"messages": out}}) }