Personal_AI_Infrastructure icon indicating copy to clipboard operation
Personal_AI_Infrastructure copied to clipboard

Algorithm SSE stream sends one frame then goes silent, and that frame drops the client poll from 2s to 30s with no way back

Open jacobo-ortiz opened this issue 3 months ago • 3 comments

Summary

GET /api/algorithm/stream opens, sends one frame, and then goes silent. It never pushes again, even when work.json changes.

On its own that would be a degraded-but-harmless realtime channel. What makes it worse is the client: the first frame is treated as proof the stream works, and the poll interval drops from 2s to 30s on the strength of it. Since a silent-but-open EventSource never fires onerror, the client never returns to the fast poll. The dashboard ends up refreshing 15× slower precisely because the realtime channel connected successfully.

The visible symptom is "the Algorithm board isn't updating", which is what sent me looking.

Measurement

T+0s    listener opened:  curl -sN --max-time 90 http://localhost:31337/api/algorithm/stream
T+14s   work.json rewritten by ISASync (ISA edit)   <-- inside the listener window
T+79s   captured log: 3 lines total (one `event:`, one `data:`, one blank)

No push, no keepalive, in ~80s. A first attempt was discarded on method: that curl could have expired at the same moment the change landed, so it was repeated with a longer window before concluding anything.

The client half

LIFEOS/PULSE/Observability/src/hooks/useAlgorithmState.ts:

  • :19-20 — FAST_POLL_INTERVAL = 2000 (SSE unavailable) and STALE_POLL_INTERVAL = 30_000 (SSE connected).
  • :100-104 — the first frame sets sseConnectedRef = true and calls restartPolling(STALE_POLL_INTERVAL).
  • :111 — es.onerror only fires on connection errors. An open, mute stream produces none, so the fallback never re-engages.

Server-side: three candidates, none confirmed

The route lives in LIFEOS/PULSE/Observability/observability.ts (handleAlgorithmStreamApi, poller + fs.watch on the STATE directory). I did not attribute a root cause, because I could not discriminate between:

  1. The poller or watcher not starting for the subscriber.
  2. The debounce at :804, which compares now (wall clock) against lastBroadcastMtimeMs (a file mtime). Those are different magnitudes; the intent reads like "time since last broadcast" but the value is "age of the file version".
  3. MEMORY_DIR resolving to a path where statSync throws, making the tick return silently on every pass.

Discriminating probe: log one line per tick inside ensureAlgorithmStreamPoller and broadcastAlgorithmState and see which branch dies.

Suggested fix, two independent halves

  • Server: make the push work (depends on which of the three it is).
  • Client: require more than the opening frame before declaring SSE healthy, and degrade back to the fast poll after N seconds of silence. Worth doing even if the server is fixed: today a server-side failure turns into a silently slow dashboard with no error anywhere.

Both files are stock v7.28.3 here, so this should reproduce on any install with the Algorithm board open.

jacobo-ortiz avatar Aug 13 '26 15:08 jacobo-ortiz

Thanks @jacobo-ortiz — the SSE-frame-then-silence issue and the client trusting the opening frame as proof of health is confirmed, and it's tracked as a queued improvement along your suggested direction (require sustained silence before falling back to fast polling). Slated for an upcoming release, not v7.40.4.

danielmiessler avatar Aug 14 '26 21:08 danielmiessler

Fixed in source: the debounce now tracks last-broadcast wall-clock time in its own variable (the mtime-vs-now comparison you flagged as candidate 2 was real). The server push path was rebuilt separately since your report (watcher + 100ms poller + keepalive + initial snapshot), which resolves the frame-then-silence half. Thanks.

danielmiessler avatar Aug 17 '26 23:08 danielmiessler

Reopening request — same shape as #1881, and this one has no local mitigation.

The 2026-08-17T23:28:01Z close states: "Fixed in source: the debounce now tracks last-broadcast wall-clock time in its own variable (the mtime-vs-now comparison you flagged as candidate 2 was real). The server push path was rebuilt separately since your report (watcher + 100ms poller + keepalive + initial snapshot), which resolves the frame-then-silence half."

Measured today (2026-09-12) against origin/main at HEAD 5e2f2e8, seven commits past the v7.40.4 tag:

  • git diff v7.40.4..origin/main -- LIFEOS/PULSE/Observability/observability.ts → 0 lines.
  • git diff v7.40.4..origin/main -- LIFEOS/PULSE/Observability/src/hooks/useAlgorithmState.ts → 0 lines.
  • git diff v7.40.4..origin/main across the whole tree → 5 files, all documentation: README.md, Releases/v7.40.4/README.md, Releases/v7.40.4/art/release-art.png, and two .github/ISSUE_TEMPLATE/*.yml. Zero source files changed.
  • Candidate 2 is still there verbatim at observability.ts:846 — now - lastBroadcastMtimeMs > SSE_DEBOUNCE_MS, comparing a wall-clock Date.now() against a file mtime.
  • The "watcher + 100ms poller + keepalive + initial snapshot" described as rebuilt since the report predates it: the file's own comment dates that push path to 2026-06-10, two months before the issue.
  • gh pr list --repo danielmiessler/LifeOS --search "1837" --state all → []. No PR, no commit, no branch touching Observability.

This is the same pattern I reported on #1881 on 2026-08-27 (closed 23:27:09Z, one minute apart, same batch that evening), which is still closed and still has no code behind it. There it didn't matter much downstream because I'd already patched my fork independently two days earlier. Here there is no patch: the defect is live.

Happy to be shown the commit if it exists on a branch I can't see — that would settle it in one line. Otherwise this is a reopen.

jacobo-ortiz avatar Sep 12 '26 15:09 jacobo-ortiz