Make SCUM logs live relay only

This commit is contained in:
npc0-hue
2026-09-01 14:26:00 +08:00
parent 3f348401a9
commit 7d9c1b7e9e
28 changed files with 1011 additions and 175 deletions
+13 -4
View File
@@ -24,13 +24,17 @@ func (h *coreHandlers) serverLogEvents(w http.ResponseWriter, r *http.Request) {
writeMethodNotAllowed(w, http.MethodGet)
return
}
liveBoundary := time.Now().UTC().Add(-liveLogSourceClockSkew)
instance, streams, liveEligible, subscription, err := h.openLogEventSubscription(r)
if err != nil {
writeServiceError(w, err)
return
}
defer subscription.Close()
h.streamCurrentLogEvents(w, r, instance, streams, liveEligible, subscription)
}
func (h *coreHandlers) streamCurrentLogEvents(w http.ResponseWriter, r *http.Request, instance domain.ServerInstance, streams []domain.LogStream, liveEligible bool, subscription service.LogEventSubscription) {
liveBoundary := time.Now().UTC().Add(-liveLogSourceClockSkew)
flusher, ok := w.(http.Flusher)
if !ok {
writeServiceError(w, fmt.Errorf("streaming response unsupported"))
@@ -131,7 +135,7 @@ func (h *coreHandlers) serverLogEvents(w http.ResponseWriter, r *http.Request) {
if !active.contains(event.Stream) {
continue
}
if !sourceLogEntryIsLive(event.Entry, liveBoundary) {
if !subscriptionEvent.Live && !sourceLogEntryIsLive(event.Entry, liveBoundary) {
if event.Entry.Seq > emittedThrough[event.Stream.ID] {
emittedThrough[event.Stream.ID] = event.Entry.Seq
}
@@ -143,7 +147,10 @@ func (h *coreHandlers) serverLogEvents(w http.ResponseWriter, r *http.Request) {
return
}
}
if event.Entry.Seq <= emittedThrough[event.Stream.ID] {
// Live relay traffic is already a current best-effort observation.
// Do not sequence-gate it: a restarted Run intentionally starts with
// fresh in-memory sequence state and must still reach this subscriber.
if !subscriptionEvent.Live && event.Entry.Seq <= emittedThrough[event.Stream.ID] {
continue
}
if err := writeSSEJSON(w, "log", logEventID(event), dto.LogStreamEventFromDomain(event)); err != nil {
@@ -228,7 +235,9 @@ func (h *coreHandlers) writeCurrentLogSession(w http.ResponseWriter, serverInsta
return nil, err
}
for _, stream := range active.streams {
emittedThrough[stream.ID] = stream.LatestSeq
// Stream metadata identifies the current channel only. The platform
// never replays its old body when a live subscriber connects.
emittedThrough[stream.ID] = 0
if err := writeSSEJSON(w, "stream", "", dto.LogStreamFromDomain(stream)); err != nil {
return nil, err
}