From 506ff253ec9ed2ec10913d34459b2817c017ab72 Mon Sep 17 00:00:00 2001 From: momentum dev Date: Fri, 19 Jun 2026 09:56:19 -0400 Subject: [PATCH] Dashboard: make LIVE not depend on the SSE stream MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit LIVE rendered ONLY from the EventSource snapshot handler — and that handler swallowed render/parse errors (catch {}). If EventSource didn't establish in the user's browser (proxy, extension, connection cap), LIVE stayed blank while the date selector — a plain fetch — worked fine. Exactly the reported symptom. - startStream() now does an immediate pollOnce() (the same fetch path the date selector uses) so LIVE shows data even if SSE never connects; SSE then layers on for low-latency pushes, with onerror -> interval polling as before. - Surface render errors (console + conn status) instead of hiding them. - Serve the dashboard HTML with no-store/no-cache so pushed fixes actually reach the browser (a stale cached shell was part of why "I see nothing" persisted). Verified headless: with EventSource forcibly disabled, LIVE still populates (10 armed rows, pnl, risk) via the polling fallback — stamp shows "polling ·". Co-Authored-By: Claude Opus 4.8 --- api/main.py | 5 +++++ api/static/dashboard.html | 9 +++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/api/main.py b/api/main.py index 5b1794f..97a7102 100644 --- a/api/main.py +++ b/api/main.py @@ -257,6 +257,11 @@ class DashboardHandler(BaseHTTPRequestHandler): self.send_response(200) self.send_header("Content-Type", "text/html; charset=utf-8") self.send_header("Content-Length", str(len(body))) + # never cache the dashboard shell — a stale cached page was serving old + # JS/CSS, so pushed fixes (and live-vs-cached behaviour) didn't reach the + # browser. The page is tiny and the data is fetched separately anyway. + self.send_header("Cache-Control", "no-store, no-cache, must-revalidate") + self.send_header("Pragma", "no-cache") self.end_headers() self.wfile.write(body) diff --git a/api/static/dashboard.html b/api/static/dashboard.html index 2d92ec2..a89ddbe 100644 --- a/api/static/dashboard.html +++ b/api/static/dashboard.html @@ -793,13 +793,18 @@ function setConn(ok, msg) { $("stamp").textContent = msg; } function startStream() { + // Render immediately from a plain fetch (the same reliable path the date + // selector uses) so LIVE shows data even if EventSource never connects in + // this browser/proxy. SSE then layers on for low-latency pushes. + pollOnce(); + if (typeof EventSource === "undefined") { startPolling(); return; } try { es = new EventSource("/api/stream"); es.addEventListener("snapshot", (ev) => { try { render(JSON.parse(ev.data)); setConn(true, "live · " + new Date().toLocaleTimeString()); } - catch (e) {} + catch (e) { console.error("render failed:", e); setConn(false, "render error (see console)"); } }); - es.onerror = () => { setConn(false, "stream lost — polling"); es.close(); es = null; startPolling(); }; + es.onerror = () => { setConn(false, "stream lost — polling"); if (es) es.close(); es = null; startPolling(); }; } catch (e) { startPolling(); } } async function pollOnce() {