From 0a89eaf25567b7abe40233cdfe124ef02ca2aa01 Mon Sep 17 00:00:00 2001 From: dirwin31 <83434411+dirwin31@users.noreply.github.com> Date: Thu, 20 Aug 2026 15:28:54 -0700 Subject: [PATCH] Oops a Comma and RF Timeout (cherry picked from commit 1f0b1e2cbc09beeccbb8814bc1fe9591883cd33b) --- .../the_galaxy/assets/components/home/home.js | 33 ++++++++++++++----- starpilot/system/the_galaxy/utilities.py | 2 +- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/starpilot/system/the_galaxy/assets/components/home/home.js b/starpilot/system/the_galaxy/assets/components/home/home.js index e603a8a0d..324819160 100644 --- a/starpilot/system/the_galaxy/assets/components/home/home.js +++ b/starpilot/system/the_galaxy/assets/components/home/home.js @@ -587,6 +587,16 @@ function renderDashboard(state) { scheduleDashboardRefresh(dashboard); } +const STATS_ATTEMPT_TIMEOUTS_MS = [5000, 20000]; + +async function fetchDashboardStats(timeoutMs) { + const statsResponse = await withTimeout(fetch("/api/stats"), timeoutMs, "stats request"); + + if (!statsResponse.ok) throw new Error(`stats API error: ${statsResponse.status}`); + + return withTimeout(statsResponse.json(), timeoutMs, "stats JSON parse"); +} + async function initializeHome(force = false) { if (force) { clearDashboardRefreshTimer(); @@ -594,20 +604,27 @@ async function initializeHome(force = false) { renderDashboard(HOME_STATE); } - try { - const statsResponse = await withTimeout(fetch("/api/stats"), 5000, "stats request"); + let statsJson = null; + let lastError = null; + for (const timeoutMs of STATS_ATTEMPT_TIMEOUTS_MS) { + try { + statsJson = await fetchDashboardStats(timeoutMs); + lastError = null; + break; + } catch (err) { + lastError = err; + } + } - if (!statsResponse.ok) throw new Error(`stats API error: ${statsResponse.status}`); - - const statsJson = await withTimeout(statsResponse.json(), 5000, "stats JSON parse"); + if (lastError) { + HOME_STATE.status = "error"; + HOME_STATE.error = lastError?.message || String(lastError); + } else { const payloadUnit = statsJson?.dashboard?.week?.distanceUnit || statsJson?.driveStats?.all?.unit; HOME_STATE.data = statsJson; HOME_STATE.unit = payloadUnit || HOME_STATE.unit || "miles"; HOME_STATE.status = "ready"; - } catch (err) { - HOME_STATE.status = "error"; - HOME_STATE.error = err?.message || String(err); } renderDashboard(HOME_STATE); diff --git a/starpilot/system/the_galaxy/utilities.py b/starpilot/system/the_galaxy/utilities.py index 0aeef3a87..db0a97d0f 100644 --- a/starpilot/system/the_galaxy/utilities.py +++ b/starpilot/system/the_galaxy/utilities.py @@ -2863,7 +2863,7 @@ def get_dashboard_stats(footage_paths, params_obj=None, now=None): _DASHBOARD_CACHE.update({ "key": cache_key, - "updated_at": time.monotonic(),, + "updated_at": time.monotonic(), "value": copy.deepcopy(dashboard), }) return dashboard