Dashboard's WelcomeHost card repeats 'vitals taking longer than expected' toast indefinitely
Fleet versions
- Discovered: main (current dev branch, 4.90.0-ish)
- Reproduced: main
Web browser and operating system: Chrome, macOS
💥 Actual behavior
In frontend/pages/DashboardPage/cards/WelcomeHost/WelcomeHost.tsx, once a host's refetch_requested flag stays true for an extended period (e.g., the host stops checking in after a refetch is requested), the "Vitals are taking longer than expected to load." toast — and the disabled/spinner state on the Refetch button — can repeat indefinitely instead of settling into a single terminal state.
Root cause: the useQuery onSuccess handler's give-up branch (elapsed time >= 60000ms) only calls setShowRefetchLoadingSpinner(false). It never resets refetchStartTime back to null. Compare this to the equivalent give-up branches in frontend/pages/hosts/details/HostDetailsPage/HostDetailsPage.tsx and frontend/pages/hosts/details/DeviceUserPage/DeviceUserPage.tsx, which both call a resetHostRefetchStates() helper that resets both the spinner and refetchStartTime.
Because refetchStartTime is left pinned to the original stale timestamp, any later refetch of the ["host"] query (e.g., React Query's default refetchOnWindowFocus, a tab switch, or any other trigger that re-runs the query while refetch_requested is still true server-side) immediately recomputes totalElapsedTime as far past the 60s threshold and fires the toast again — repeatedly, without the user doing anything.
Separately, the very first line of that onSuccess handler unconditionally does setShowRefetchLoadingSpinner(returnedHost.refetch_requested), so the Refetch button can appear disabled/"actively refetching" on every render as long as the flag stays true, even outside an active polling window.
🛠️ Expected behavior
The toast should fire once per stalled refetch attempt, not repeatedly on every incidental re-fetch of host data. After giving up, the component's refetch-timer state should fully reset (mirroring resetHostRefetchStates() in HostDetailsPage.tsx/DeviceUserPage.tsx) so a later, unrelated re-fetch of the host doesn't immediately re-trigger the give-up path.
🧑💻 Steps to reproduce
These steps:
- [ ] Have been confirmed to consistently lead to reproduction in multiple Fleet instances.
- [x] Describe the workflow that led to the error, but have not yet been reproduced in multiple Fleet instances.
- In a local dev instance with exactly one host (id 1) and at least one policy result recorded for it, load the Dashboard so the
WelcomeHost"Welcome to Fleet" card renders with the Refetch button. - Click Refetch, then stop the host's agent process (or otherwise ensure it can never submit another distributed write) while keeping the host's
seen_timefresh enough that Fleet still reports it as "online" (e.g. viahosts.distributed_interval/hosts.config_tls_refreshin the dev DB). - Wait ~60 seconds — the "Vitals are taking longer than expected to load." toast fires and the Refetch button re-enables, as expected.
- Leave
refetch_requestedstucktruein the DB (agent still stopped) and switch away from/back to the browser tab (or otherwise trigger React Query'srefetchOnWindowFocus). - Observe the toast fires again immediately, and this repeats on every subsequent window focus / re-fetch, indefinitely.
🕯️ More info (optional)
Likely fix: add a resetHostRefetchStates()-equivalent call (resetting both showRefetchLoadingSpinner and refetchStartTime) to WelcomeHost.tsx's give-up branch, matching the pattern already used in HostDetailsPage.tsx and DeviceUserPage.tsx. Worth considering whether WelcomeHost.tsx should get its own small resetHostRefetchStates helper for consistency, since it currently resets spinner/timer state inline in several places.
I'd like to take a shot at this; opened a fix here: #53824. Added resetHostRefetchStates() matching the pattern already in HostDetailsPage.tsx/DeviceUserPage.tsx, plus a regression test that simulates the window-focus re-fetch from the repro steps and fails without the fix (toast fires twice) / passes with it.
Welcome card refetch toast loop (#49381) — fixed on main ✅
Environment: main @ 04a85078f0 (includes #53824) vs 3514dd5f6a (before #53824), Premium, two fresh single-host instances. Host 1 is an osquery-perf Mac that stays online but doesn't answer the refetch. Driven in the dashboard UI, with toasts and host re-fetches counted. #53824 is on main only, so this lands in 4.94.0.
1. Window focus after the give-up toast — ✅ no new toast. Before: every focus fired "Refetch sent but vitals are taking longer than expected to load" again right away (3 focuses = 3 more toasts).
2. Give-up — ✅ unchanged: one toast about 60s after clicking Refetch, then the button re-enables and polling stops.
3. Focus while the host is still stuck — ✅ the card now behaves like Host details: the focus starts a new 60s refetch window and shows one toast when that window ends, then goes quiet. Over 3 focuses plus 5 minutes idle: 2 toasts on the fix vs 4 before.
4. Responsive host — ✅ unchanged: Refetch clears in about 4s with no toast, and a later focus does nothing.
5. Dashboard opened while the refetch is already stuck — ✅ unchanged: the button stays disabled for 60s, one toast, then it re-enables.
Ready to close ✅
Stale timer haunts each window focus restarts reset clears the fog