Skip to content

fix: always fetch live API data in server mode#92

Open
Kampe wants to merge 1 commit into
calesthio:masterfrom
Kampe:fix/always-fetch-live-api-data
Open

fix: always fetch live API data in server mode#92
Kampe wants to merge 1 commit into
calesthio:masterfrom
Kampe:fix/always-fetch-live-api-data

Conversation

@Kampe

@Kampe Kampe commented Apr 11, 2026

Copy link
Copy Markdown

Problem

When running Crucix in Docker/Kubernetes, the dashboard shows stale data from the Docker image build time instead of live intelligence data.

The DOMContentLoaded handler in jarvis.html checks:

if (canProbeApi && !hasInlineData) {

But the inline data variable D is always populated at build time (line 375), so hasInlineData is always true and the /api/data fetch is never executed. The dashboard renders the baked-in snapshot forever.

Fix

Change the condition to just canProbeApi:

if (canProbeApi) {

This makes the dashboard always fetch from /api/data when running on a server (HTTP/HTTPS). File mode (local HTML file) still uses inline data as fallback since canProbeApi is false for file:// protocol.

Impact

  • Docker/K8s deployments now show real-time data instead of build-time snapshot
  • No change to file-mode behavior (offline viewing still works)
  • The connectSSE() call in the fetch handler ensures live updates continue after initial load

🤖 Generated with Claude Code

When running in Docker/Kubernetes, the dashboard serves baked-in data
from the Docker image build time instead of fetching live data from
the API. This is because the DOMContentLoaded handler checks
`canProbeApi && !hasInlineData` — but the inline data `D` variable
is always populated from the build, so `hasInlineData` is always true
and the API fetch is never executed.

The fix changes the condition to just `canProbeApi`, so the dashboard
always fetches from `/api/data` when running on a server (HTTP/HTTPS),
regardless of whether inline data exists. File mode (opened as a local
file) still uses inline data as a fallback.

This caused the dashboard to show data from whenever the Docker image
was built, not live intelligence data.
@Kampe Kampe requested a review from calesthio as a code owner April 11, 2026 22:00
@oxngon

oxngon commented May 9, 2026

Copy link
Copy Markdown

Good fix. We ("we" = me and my agent) hit this exact issue in production. Serving Crucix behind a Cloudflare tunnel at https://intel.zerotomonero.xyz, the dashboard showed stale build-time data indefinitely because SSE couldn't reach the browser, and the inline D variable was never refreshed.

We applied a complementary server-side patch to server.mjs that writes updated data to jarvis.html after each sweep:

// After broadcast({ type: 'update', data: currentData });
try {
  const htmlPath = join(ROOT, 'dashboard/public/jarvis.html');
  let html = readFileSync(htmlPath, 'utf-8');
  const json = JSON.stringify(currentData);
  html = html.replace(/^(let|const) D = .*;\s*$/m, () => 'let D = ' + json + ';');
  writeFileSync(htmlPath, html);
  console.log('[Crucix] jarvis.html updated with fresh sweep data');
} catch (err) {
  console.error('[Crucix] Failed to update jarvis.html:', err.message);
}

The two approaches are complementary:

  • This PR fix: always fetch live API data in server mode #92 (client-side): Dashboard always fetches live data from /api/data on HTTP — the right long-term fix.
  • Server-side write: The HTML file itself stays current as a fallback for CDN caching, offline viewing, or when the API fetch fails for any reason.

Worth noting: this server-side write also means inject.mjs (CLI mode) is no longer the only path to update the dashboard file — which was the root cause of the stale data in the first place (server mode stored data in memory but never persisted it to disk).

Happy to open a separate PR for the server-side patch if there's interest.

@calesthio

Copy link
Copy Markdown
Owner

The issue looks valid: in server mode, baked inline D can prevent the dashboard from fetching fresh /api/data, so Docker/Kubernetes/static-image deployments can show stale build-time data.

I would not approve this exact patch yet because the new path should validate the API response before replacing inline data. As written, if /api/data returns 503 { error: ... }, proxy error JSON, or another non-dashboard payload, this does D = data; init(); and can crash because render code expects D.meta, D.air, etc.

Suggested shape:

fetch('/api/data')
  .then(r => {
    if (!r.ok) throw new Error(`API ${r.status}`);
    return r.json();
  })
  .then(data => {
    if (!data?.meta) throw new Error('Invalid API data');
    D = data;
    init();
    connectSSE();
  })
  .catch(() => {
    if (D && D.meta) { init(); connectSSE(); }
  });

Checks I ran against the simulated merge onto current master:

  • node --check server.mjs dashboard/inject.mjs
  • node apis/briefing.mjs then node dashboard/inject.mjs --no-open
  • node --test — 45 pass, 1 skipped
  • Dashboard critical identifiers still present: three.min.js, WebGLRenderer, starGeom, projToggle, gsap, d3.v7, topojson

So: valid bug, small fix needed before approval.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants