Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

Distinguish alert History read failures from empty results

pulse-triage[bot]eaa51d38fe2c
diff --git a/docs/release-control/v6/internal/subsystems/alerts.md b/docs/release-control/v6/internal/subsystems/alerts.md
index 848557fdba..def6dc41b6 100644
--- a/docs/release-control/v6/internal/subsystems/alerts.md
+++ b/docs/release-control/v6/internal/subsystems/alerts.md
@@ -4313,6 +4313,30 @@ and unified alert synchronisation, including absence of duplicate parent alerts.
### Alert history clear/read ordering
+History read failure is not an empty result. The existing History tab announces
+an error and offers an explicit read-only retry. Pending or failed reads expose
+neither the frequency chart nor severity totals, and failure suppresses the
+ordinary empty-result claim. Same-range saved entries remain available with an
+incomplete/out-of-date warning, alongside live alerts. A snapshot loaded for
+another range is retained internally but excluded from that range's rows;
+switching range is not deletion. Search, severity and range remain URL-owned.
+
+Only the latest request may settle rows, failure or loading. An explicit retry
+admits one pending logical read; existing API transport policy is unchanged.
+Organisation replacement clears the saved snapshot and read error; retired
+reads and clears cannot change the replacement view. Disposal prevents another
+retry or a late completion from modifying view state. An already-dispatched
+clear is not cancelled, and deletion/retention, active alerts, acknowledgement
+and notification delivery are unchanged.
+
+`useAlertHistoryState.test.tsx` and `HistoryTab.loadFailure.test.tsx` exercise
+initial failure, retry, pending/accepted empty results, same-range retention,
+range isolation with live alerts, obsolete replies, context replacement and
+disposal. The parent-bound browser receipt exercises the real existing tab,
+hook, API adapter and stylesheet at desktop and phone widths with synthetic
+HTTP failures and deferred replies. These are source presentation/ownership
+controls, not installed backend recovery or destination delivery.
+
A successful history clear invalidates reads started before its completion and
settles their loading state, so delayed responses cannot repopulate deleted
history rows. Failed clearing leaves the pending read valid; later range
diff --git a/docs/release-control/v6/internal/subsystems/frontend-primitives.md b/docs/release-control/v6/internal/subsystems/frontend-primitives.md
index b8b4dafc21..b8501dd016 100644
--- a/docs/release-control/v6/internal/subsystems/frontend-primitives.md
+++ b/docs/release-control/v6/internal/subsystems/frontend-primitives.md
@@ -20,6 +20,23 @@
## Purpose
+### Existing alert History distinguishes failed reads from empty results
+
+The History tab renders fixed non-provider error copy in a `role="alert"`
+region and keeps its native Retry history button busy/disabled during the
+logical read. Loading is announced with `role="status"`. Frequency and severity
+totals are hidden until a read is accepted; failed reads do not render the
+ordinary empty-history claim. Same-range saved rows and live alerts can remain
+under the warning, without presenting a different range's saved rows.
+
+The connected History tab/state tests and parent-bound browser receipt cover
+deferred/synthetic failed reads, keyboard retry, accepted recovery and empty
+results, retained entries, range/context replacement and disposal. Desktop
+1280px and phone 390px layouts fit without page-level horizontal overflow;
+the phone retry control preserves the shared 44px target and the desktop
+control keeps shared compact density. No new primitive, route, feature,
+permission, notification replay or backend recovery claim is introduced.
+
### Existing webhook list controls expose pending acknowledgement
The webhook section shares pending admission across form saves, list toggles,
diff --git a/frontend-modern/browser-verification/584c98c5d96bfcec.json b/frontend-modern/browser-verification/584c98c5d96bfcec.json
new file mode 100644
index 0000000000..4ef41c492e
--- /dev/null
+++ b/frontend-modern/browser-verification/584c98c5d96bfcec.json
@@ -0,0 +1,50 @@
+{
+ "version": 1,
+ "result": "passed",
+ "base_sha": "c37248a9f5adec25f8e717fbf9c9e4d1e4c967a5",
+ "changed_paths": [
+ "frontend-modern/src/features/alerts/AlertHistoryFiltersCard.tsx",
+ "frontend-modern/src/features/alerts/AlertHistoryTableSection.tsx",
+ "frontend-modern/src/features/alerts/tabs/HistoryTab.tsx",
+ "frontend-modern/src/features/alerts/useAlertHistoryState.ts",
+ "frontend-modern/src/utils/alertOverviewPresentation.ts"
+ ],
+ "content_sha256": {
+ "frontend-modern/src/features/alerts/AlertHistoryFiltersCard.tsx": "6c741b568a576640a1d589c2b39a630dcb59c69433664edb500d92eed5378a80",
+ "frontend-modern/src/features/alerts/AlertHistoryTableSection.tsx": "1255494d0e46111f0818dab6759a5c687b95f8ac01d9e86c7200476e02e0d120",
+ "frontend-modern/src/features/alerts/useAlertHistoryState.ts": "6fdfd7d71214558875b193d5c21d699317f74e2a3d7e4ec04f8a40e7b9def15e",
+ "frontend-modern/src/features/alerts/tabs/HistoryTab.tsx": "e46d6f64a62f1decdc3c26ab3696d5891e8bdfa12b7bc6b9d4522b585319edea",
+ "frontend-modern/src/utils/alertOverviewPresentation.ts": "281a9bdbfbd1f3f0a53cf2bfdc1130f6ba19ae64c8293a496b08181c552200f6"
+ },
+ "routes": [
+ "/alerts/history"
+ ],
+ "states": [
+ "Real existing History tab, hook, API adapter and stylesheet inside an offline context fixture; synthetic local HTTP503 and deferred reads",
+ "Initial pending/failure, read-only retry, accepted result, same-range retained entries, larger-range failure alongside live alert",
+ "Obsolete reply, organisation replacement, pending unmount"
+ ],
+ "interactions": [
+ "Keyboard Retry history admits one logical pending read; duplicate activation while busy sends no second application read",
+ "Range change does not relabel another range snapshot; same-range retained entries carry visible incomplete/out-of-date guidance",
+ "Failed reads suppress frequency chart, severity totals and ordinary empty claim; accepted reads restore them, including genuine empty result",
+ "Range URL remains unchanged by retry; organisation replacement discards old entries/errors; disposed hook cannot apply late failure"
+ ],
+ "viewports": [
+ {
+ "width": 1280,
+ "height": 900
+ },
+ {
+ "width": 390,
+ "height": 900
+ }
+ ],
+ "verified_at": "2026-10-10T12:59:50.957461Z",
+ "browser": {
+ "client": "1.56.1",
+ "engine": "Chromium",
+ "version": "141.0.7390.37"
+ },
+ "scope": "Source-isolated existing page fixture and synthetic endpoints, not full authenticated app, ordinary backend/notification delivery or installed recovery."
+}
diff --git a/frontend-modern/src/features/alerts/AlertHistoryFiltersCard.tsx b/frontend-modern/src/features/alerts/AlertHistoryFiltersCard.tsx
index e1d6272828..24a54705d7 100644
--- a/frontend-modern/src/features/alerts/AlertHistoryFiltersCard.tsx
+++ b/frontend-modern/src/features/alerts/AlertHistoryFiltersCard.tsx
@@ -24,7 +24,9 @@ export function AlertHistoryFiltersCard(props: AlertHistoryFiltersCardProps) {
deserialize: deserializePlatformEstateCountsVisibility,
});
const severityCount = (value: AlertSeverityFilter): number | undefined =>
- countsVisible() ? props.state.countForSeverity(value) : undefined;
+ countsVisible() && !props.state.loading() && !props.state.historyLoadError()
+ ? props.state.countForSeverity(value)
+ : undefined;
const buildFilters = (): FilterDef[] => [
{
id: 'alert-period',
diff --git a/frontend-modern/src/features/alerts/AlertHistoryTableSection.tsx b/frontend-modern/src/features/alerts/AlertHistoryTableSection.tsx
index 15af42fcad..2eb607281e 100644
--- a/frontend-modern/src/features/alerts/AlertHistoryTableSection.tsx
+++ b/frontend-modern/src/features/alerts/AlertHistoryTableSection.tsx
@@ -44,10 +44,12 @@ export function AlertHistoryTableSection(props: AlertHistoryTableSectionProps) {
<Show
when={props.state.alertData().length > 0}
fallback={
- <div class="py-12 text-center text-muted">
- <p class="text-sm">{getAlertHistoryEmptyState().title}</p>
- <p class="mt-1 text-xs">{getAlertHistoryEmptyState().description}</p>
- </div>
+ <Show when={!props.state.historyLoadError()}>
+ <div class="py-12 text-center text-muted">
+ <p class="text-sm">{getAlertHistoryEmptyState().title}</p>
+ <p class="mt-1 text-xs">{getAlertHistoryEmptyState().description}</p>
+ </div>
+ </Show>
}
>
<>
@@ -132,7 +134,7 @@ export function AlertHistoryTableSection(props: AlertHistoryTableSectionProps) {
</Show>
}
>
- <div class="py-12 text-center text-muted">
+ <div class="py-12 text-center text-muted" role="status">
<p class="text-sm">{getAlertHistoryLoadingState().text}</p>
</div>
</Show>
diff --git a/frontend-modern/src/features/alerts/__tests__/HistoryTab.loadFailure.test.tsx b/frontend-modern/src/features/alerts/__tests__/HistoryTab.loadFailure.test.tsx
new file mode 100644
index 0000000000..d2824e171a
--- /dev/null
+++ b/frontend-modern/src/features/alerts/__tests__/HistoryTab.loadFailure.test.tsx
@@ -0,0 +1,121 @@
+import { cleanup, fireEvent, render, screen, waitFor, within } from '@solidjs/testing-library';
+import { createSignal } from 'solid-js';
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
+
+import { AlertsAPI } from '@/api/alerts';
+import type { Alert } from '@/types/api';
+import { HistoryTab } from '../tabs/HistoryTab';
+
+const [search, setSearch] = createSignal('');
+let liveAlerts: Record<string, Alert> = {};
+
+vi.mock('@solidjs/router', () => ({
+ useLocation: () => ({
+ pathname: '/alerts/history',
+ hash: '',
+ get search() {
+ return search();
+ },
+ }),
+ useNavigate: () => (path: string) =>
+ setSearch(path.includes('?') ? path.slice(path.indexOf('?')) : ''),
+}));
+vi.mock('@/contexts/appRuntime', () => ({
+ useWebSocket: () => ({ activeAlerts: liveAlerts }),
+}));
+vi.mock('@/hooks/useBreakpoint', () => ({ useBreakpoint: () => ({ isMobile: () => false }) }));
+vi.mock('@/api/alerts', () => ({ AlertsAPI: { getHistory: vi.fn(), clearHistory: vi.fn() } }));
+vi.mock('@/utils/logger', () => ({ logger: { error: vi.fn() } }));
+
+type History = Awaited<ReturnType<typeof AlertsAPI.getHistory>>;
+const deferred = () => {
+ let resolve!: (value: History) => void;
+ const promise = new Promise<History>((yes) => {
+ resolve = yes;
+ });
+ return { promise, resolve };
+};
+const row = (id: string) =>
+ ({
+ id,
+ type: 'cpu',
+ level: 'warning',
+ resourceId: id,
+ resourceName: id,
+ startTime: new Date(Date.now() - 60000).toISOString(),
+ lastSeen: new Date().toISOString(),
+ message: `Recorded ${id}`,
+ acknowledged: false,
+ }) as Alert;
+const mount = () =>
+ render(() => <HistoryTab getResource={() => undefined} allResources={() => []} />);
+
+afterEach(cleanup);
+beforeEach(() => {
+ vi.mocked(AlertsAPI.getHistory).mockReset();
+ vi.mocked(AlertsAPI.clearHistory).mockReset();
+ liveAlerts = {};
+ setSearch('');
+ localStorage.clear();
+});
+
+describe('existing History page read failure', () => {
+ it('announces a safe error, not an empty result; explicit retry is single-flight and read-only', async () => {
+ vi.mocked(AlertsAPI.getHistory).mockRejectedValueOnce(new Error('secret-provider-body'));
+ const retry = deferred();
+ vi.mocked(AlertsAPI.getHistory).mockReturnValueOnce(retry.promise);
+ const { container } = mount();
+ await screen.findByRole('alert');
+ expect(screen.getByText('Could not load alert history')).toBeInTheDocument();
+ expect(container).not.toHaveTextContent('secret-provider-body');
+ expect(screen.queryByText('No alerts found')).not.toBeInTheDocument();
+ expect(screen.queryByText('Alert frequency')).not.toBeInTheDocument();
+ expect(
+ within(screen.getByRole('group', { name: 'Severity' })).getByRole('button', { name: 'All' }),
+ ).toBeInTheDocument();
+ const button = screen.getByRole('button', { name: 'Retry history' });
+ fireEvent.click(button);
+ fireEvent.click(button);
+ expect(AlertsAPI.getHistory).toHaveBeenCalledTimes(2);
+ expect(button).toBeDisabled();
+ expect(button).toHaveAttribute('aria-busy', 'true');
+ expect(button).toHaveTextContent('Retrying…');
+ expect(screen.getByRole('status')).toHaveTextContent('Loading alert history');
+ retry.resolve([]);
+ await waitFor(() => expect(screen.queryByRole('alert')).not.toBeInTheDocument());
+ expect(screen.getByText('No alerts found')).toBeInTheDocument();
+ expect(screen.getByText('Alert frequency')).toBeInTheDocument();
+ expect(AlertsAPI.clearHistory).not.toHaveBeenCalled();
+ });
+
+ it('does not present zero totals before the first read has completed', async () => {
+ const initial = deferred();
+ vi.mocked(AlertsAPI.getHistory).mockReturnValueOnce(initial.promise);
+ mount();
+ expect(screen.getByRole('status')).toHaveTextContent('Loading alert history');
+ expect(screen.queryByText('No alerts found')).not.toBeInTheDocument();
+ expect(screen.queryByText('Alert frequency')).not.toBeInTheDocument();
+ initial.resolve([]);
+ await screen.findByText('No alerts found');
+ });
+
+ it('keeps live alerts visible but does not relabel saved rows after a larger-range failure', async () => {
+ liveAlerts = { live: row('live') };
+ vi.mocked(AlertsAPI.getHistory).mockResolvedValueOnce([row('old-range')]);
+ mount();
+ await screen.findAllByText('Recorded old-range');
+ vi.mocked(AlertsAPI.getHistory).mockRejectedValueOnce(new Error('Unavailable'));
+ fireEvent.click(screen.getByRole('button', { name: 'Last 30d' }));
+ await screen.findByRole('alert');
+ expect(screen.queryByText('Recorded old-range')).not.toBeInTheDocument();
+ expect(screen.getAllByText('Recorded live').length).toBeGreaterThan(0);
+ expect(screen.queryByText('Alert frequency')).not.toBeInTheDocument();
+ expect(search()).toBe('?period=30d');
+ vi.mocked(AlertsAPI.getHistory).mockResolvedValueOnce([row('new-range')]);
+ fireEvent.click(screen.getByRole('button', { name: 'Retry history' }));
+ await screen.findAllByText('Recorded new-range');
+ expect(screen.queryByRole('alert')).not.toBeInTheDocument();
+ expect(search()).toBe('?period=30d');
+ expect(AlertsAPI.clearHistory).not.toHaveBeenCalled();
+ });
+});
diff --git a/frontend-modern/src/features/alerts/__tests__/HistoryTab.test.tsx b/frontend-modern/src/features/alerts/__tests__/HistoryTab.test.tsx
index 90ccc74cfb..70fecc3fa6 100644
--- a/frontend-modern/src/features/alerts/__tests__/HistoryTab.test.tsx
+++ b/frontend-modern/src/features/alerts/__tests__/HistoryTab.test.tsx
@@ -24,6 +24,8 @@ vi.mock('@/hooks/useBreakpoint', () => ({
vi.mock('../useAlertHistoryState', () => ({
useAlertHistoryState: () => ({
alertData: () => [],
+ loading: () => false,
+ historyLoadError: () => false,
}),
}));
diff --git a/frontend-modern/src/features/alerts/__tests__/useAlertHistoryState.test.tsx b/frontend-modern/src/features/alerts/__tests__/useAlertHistoryState.test.tsx
index 2fa454ee6e..6f1552b32d 100644
--- a/frontend-modern/src/features/alerts/__tests__/useAlertHistoryState.test.tsx
+++ b/frontend-modern/src/features/alerts/__tests__/useAlertHistoryState.test.tsx
@@ -1,6 +1,6 @@
-import { renderHook, waitFor } from '@solidjs/testing-library';
+import { cleanup, renderHook, waitFor } from '@solidjs/testing-library';
import { createSignal } from 'solid-js';
-import { beforeEach, describe, expect, it, vi } from 'vitest';
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { AlertsAPI } from '@/api/alerts';
import { eventBus } from '@/stores/events';
@@ -71,6 +71,8 @@ vi.mock('@/utils/logger', () => ({
},
}));
+afterEach(cleanup);
+
describe('useAlertHistoryState', () => {
beforeEach(() => {
vi.mocked(AlertsAPI.getHistory).mockReset();
@@ -86,6 +88,172 @@ describe('useAlertHistoryState', () => {
localStorage.clear();
});
+ type History = Awaited<ReturnType<typeof AlertsAPI.getHistory>>;
+ const row = (id: string): History[number] =>
+ ({
+ id,
+ type: 'cpu',
+ level: 'warning',
+ startTime: new Date(Date.now() - 60000).toISOString(),
+ lastSeen: new Date().toISOString(),
+ resourceId: `host-${id}`,
+ resourceName: id,
+ message: `Reading for ${id}`,
+ acknowledged: false,
+ }) as History[number];
+ const deferred = <T,>() => {
+ let resolve!: (value: T) => void;
+ let reject!: (reason: Error) => void;
+ const promise = new Promise<T>((yes, no) => {
+ resolve = yes;
+ reject = no;
+ });
+ return { promise, resolve, reject };
+ };
+ const mount = () =>
+ renderHook(() =>
+ useAlertHistoryState({
+ activeAlerts: () => ({}),
+ getResource: () => undefined,
+ allResources: () => [],
+ }),
+ );
+ const switchOrg = () => {
+ const onSwitch = vi
+ .mocked(eventBus.on)
+ .mock.calls.find(([event]) => event === 'org_switched')![1];
+ onSwitch('replacement');
+ };
+
+ it('exposes initial failure and admits only one explicit current-range retry', async () => {
+ vi.mocked(AlertsAPI.getHistory).mockRejectedValueOnce(new Error('Private provider body'));
+ const retry = deferred<History>();
+ vi.mocked(AlertsAPI.getHistory).mockReturnValueOnce(retry.promise);
+ const { result } = mount();
+ await waitFor(() => expect(result.historyLoadError()).toBe(true));
+ expect(result.loading()).toBe(false);
+ const pending = result.retryHistory();
+ result.retryHistory();
+ expect(AlertsAPI.getHistory).toHaveBeenCalledTimes(2);
+ expect(result.loading()).toBe(true);
+ expect(result.historyLoadError()).toBe(true);
+ retry.resolve([]);
+ await pending;
+ expect(result.historyLoadError()).toBe(false);
+ expect(result.loading()).toBe(false);
+ expect(result.alertData()).toEqual([]);
+ expect(AlertsAPI.clearHistory).not.toHaveBeenCalled();
+ });
+
+ it('keeps same-range entries after a failed read without losing URL filters', async () => {
+ setMockLocation('?period=30d&severity=warning&q=retained');
+ vi.mocked(AlertsAPI.getHistory).mockResolvedValueOnce([row('retained')]);
+ const { result } = mount();
+ await waitFor(() => expect(result.loading()).toBe(false));
+ vi.mocked(AlertsAPI.getHistory).mockRejectedValueOnce(new Error('Unavailable'));
+ await result.retryHistory();
+ expect(result.historyLoadError()).toBe(true);
+ expect(result.alertData().map(({ id }) => id)).toEqual(['retained']);
+ expect(result.searchTerm()).toBe('retained');
+ expect(result.severityFilter()).toBe('warning');
+ expect(result.timeFilter()).toBe('30d');
+ expect(navigateSpy).not.toHaveBeenCalled();
+ });
+
+ it('does not reuse saved rows after a different-range read fails; live alerts remain', async () => {
+ vi.mocked(AlertsAPI.getHistory).mockResolvedValueOnce([row('old-range')]);
+ const live = row('live');
+ const { result } = renderHook(() =>
+ useAlertHistoryState({
+ activeAlerts: () => ({ live }),
+ getResource: () => undefined,
+ allResources: () => [],
+ }),
+ );
+ await waitFor(() => expect(result.loading()).toBe(false));
+ vi.mocked(AlertsAPI.getHistory).mockRejectedValueOnce(new Error('Unavailable'));
+ result.setTimeFilter('30d');
+ await waitFor(() => expect(result.historyLoadError()).toBe(true));
+ expect(result.alertHistory().map(({ id }) => id)).toEqual(['old-range']);
+ expect(result.alertData().map(({ id }) => id)).toEqual(['live']);
+ vi.mocked(AlertsAPI.getHistory).mockResolvedValueOnce([row('new-range')]);
+ await result.retryHistory();
+ expect(result.alertData().map(({ id }) => id)).toEqual(
+ expect.arrayContaining(['live', 'new-range']),
+ );
+ expect(result.historyLoadError()).toBe(false);
+ });
+
+ it.each(['obsolete-success', 'obsolete-failure'] as const)(
+ 'ignores %s after a newer range result',
+ async (kind) => {
+ const old = deferred<History>();
+ vi.mocked(AlertsAPI.getHistory)
+ .mockReturnValueOnce(old.promise)
+ .mockResolvedValueOnce([row('latest')]);
+ const { result } = mount();
+ result.setTimeFilter('30d');
+ await waitFor(() => expect(result.alertHistory()[0]?.id).toBe('latest'));
+ if (kind === 'obsolete-success') old.resolve([row('obsolete')]);
+ else old.reject(new Error('Obsolete failure'));
+ await old.promise.catch(() => {});
+ expect(result.alertHistory()[0]?.id).toBe('latest');
+ expect(result.historyLoadError()).toBe(false);
+ expect(result.loading()).toBe(false);
+ },
+ );
+
+ it('invalidates old-context entries and errors when the organisation changes', async () => {
+ vi.mocked(AlertsAPI.getHistory).mockResolvedValueOnce([row('previous-org')]);
+ const { result } = mount();
+ await waitFor(() => expect(result.loading()).toBe(false));
+ const oldRetry = deferred<History>();
+ vi.mocked(AlertsAPI.getHistory)
+ .mockReturnValueOnce(oldRetry.promise)
+ .mockResolvedValueOnce([row('replacement-org')]);
+ const pending = result.retryHistory();
+ switchOrg();
+ expect(result.alertHistory()).toEqual([]);
+ await waitFor(() => expect(result.alertHistory()[0]?.id).toBe('replacement-org'));
+ oldRetry.reject(new Error('Old org unavailable'));
+ await pending;
+ expect(result.historyLoadError()).toBe(false);
+ expect(result.alertHistory()[0]?.id).toBe('replacement-org');
+ });
+
+ it.each([true, false])(
+ 'does not settle a retired-context clear (success=%s) into new history',
+ async (success) => {
+ vi.mocked(AlertsAPI.getHistory)
+ .mockResolvedValueOnce([row('previous-org')])
+ .mockResolvedValueOnce([row('replacement-org')]);
+ const clear = deferred<Awaited<ReturnType<typeof AlertsAPI.clearHistory>>>();
+ vi.mocked(AlertsAPI.clearHistory).mockReturnValueOnce(clear.promise);
+ const { result } = mount();
+ await waitFor(() => expect(result.loading()).toBe(false));
+ const pending = result.clearAlertHistory();
+ switchOrg();
+ await waitFor(() => expect(result.alertHistory()[0]?.id).toBe('replacement-org'));
+ if (success) clear.resolve(undefined as never);
+ else clear.reject(new Error('Previous org unavailable'));
+ await pending;
+ expect(result.alertHistory()[0]?.id).toBe('replacement-org');
+ expect(result.historyLoadError()).toBe(false);
+ },
+ );
+
+ it('does not apply a late failure or dispatch another retry after disposal', async () => {
+ const old = deferred<History>();
+ vi.mocked(AlertsAPI.getHistory).mockReturnValueOnce(old.promise);
+ const { result, cleanup: dispose } = mount();
+ dispose();
+ old.reject(new Error('Disposed read'));
+ await old.promise.catch(() => {});
+ result.retryHistory();
+ expect(AlertsAPI.getHistory).toHaveBeenCalledTimes(1);
+ expect(result.historyLoadError()).toBe(false);
+ });
+
it('owns alert history fetch, filters, resource incidents, and clear behavior outside the render tab', async () => {
const [activeAlerts] = createSignal({});
const now = Date.now();
diff --git a/frontend-modern/src/features/alerts/tabs/HistoryTab.tsx b/frontend-modern/src/features/alerts/tabs/HistoryTab.tsx
index 00997614b2..8b1e177015 100644
--- a/frontend-modern/src/features/alerts/tabs/HistoryTab.tsx
+++ b/frontend-modern/src/features/alerts/tabs/HistoryTab.tsx
@@ -1,9 +1,11 @@
-import { createSignal, onCleanup, createEffect } from 'solid-js';
+import { Show, createSignal, onCleanup, createEffect } from 'solid-js';
import { useLocation } from '@solidjs/router';
import type { Resource } from '@/types/resource';
import { useWebSocket } from '@/contexts/appRuntime';
import { useBreakpoint } from '@/hooks/useBreakpoint';
+import { Button } from '@/components/shared/Button';
+import { getAlertHistoryLoadFailure } from '@/utils/alertOverviewPresentation';
import { AlertHistoryAdministrationCard } from '../AlertHistoryAdministrationCard';
import { AlertHistoryFiltersCard } from '../AlertHistoryFiltersCard';
@@ -67,7 +69,33 @@ export function HistoryTab(props: HistoryTabProps) {
return (
<div class="space-y-4">
- <AlertHistoryFrequencyCard state={historyState} />
+ <Show when={historyState.historyLoadError()}>
+ <div
+ class="flex flex-col gap-3 rounded-md border border-border bg-surface-alt p-4 sm:flex-row sm:items-center sm:justify-between"
+ role="alert"
+ >
+ <div class="min-w-0">
+ <p class="text-sm font-medium text-base-content">
+ {getAlertHistoryLoadFailure().title}
+ </p>
+ <p class="mt-1 text-sm text-muted">{getAlertHistoryLoadFailure().description}</p>
+ </div>
+ <Button
+ size="sm"
+ class="min-h-11 shrink-0 self-start"
+ disabled={historyState.loading()}
+ aria-busy={historyState.loading()}
+ onClick={() => void historyState.retryHistory()}
+ >
+ {historyState.loading()
+ ? getAlertHistoryLoadFailure().retryingLabel
+ : getAlertHistoryLoadFailure().retryLabel}
+ </Button>
+ </div>
+ </Show>
+ <Show when={!historyState.loading() && !historyState.historyLoadError()}>
+ <AlertHistoryFrequencyCard state={historyState} />
+ </Show>
<AlertHistoryFiltersCard state={historyState} isMobile={isMobile()} />
<AlertHistoryTableSection state={historyState} />
<AlertHistoryAdministrationCard state={historyState} />
diff --git a/frontend-modern/src/features/alerts/useAlertHistoryState.ts b/frontend-modern/src/features/alerts/useAlertHistoryState.ts
index 88d5d64381..474f1768e5 100644
--- a/frontend-modern/src/features/alerts/useAlertHistoryState.ts
+++ b/frontend-modern/src/features/alerts/useAlertHistoryState.ts
@@ -1,4 +1,4 @@
-import { createEffect, createMemo, createSignal, onCleanup, onMount } from 'solid-js';
+import { batch, createEffect, createMemo, createSignal, onCleanup, onMount } from 'solid-js';
import type { Accessor } from 'solid-js';
import { useLocation, useNavigate } from '@solidjs/router';
@@ -103,7 +103,9 @@ export function useAlertHistoryState(props: UseAlertHistoryStateProps) {
};
const [alertHistory, setAlertHistory] = createSignal<Alert[]>([]);
+ const [loadedHistoryRange, setLoadedHistoryRange] = createSignal<AlertHistoryRange | null>(null);
const [loading, setLoading] = createSignal(true);
+ const [historyLoadError, setHistoryLoadError] = createSignal(false);
const [selectedBarIndex, setSelectedBarIndex] = createSignal<number | null>(null);
const resourceIncidentsState = useAlertResourceIncidentsState();
@@ -161,17 +163,28 @@ export function useAlertHistoryState(props: UseAlertHistoryStateProps) {
});
let fetchRequestId = 0;
+ let historyContextVersion = 0;
+ let disposed = false;
+ let requestedRange: AlertHistoryRange | null = null;
const fetchHistory = async (range: AlertHistoryRange) => {
+ if (disposed) return;
const requestId = ++fetchRequestId;
+ if (requestedRange !== range) setHistoryLoadError(false);
+ requestedRange = range;
setLoading(true);
try {
const alertHistoryData = await AlertsAPI.getHistory(buildAlertHistoryParams(range));
if (requestId === fetchRequestId) {
- setAlertHistory(alertHistoryData);
+ batch(() => {
+ setAlertHistory(alertHistoryData);
+ setLoadedHistoryRange(range);
+ setHistoryLoadError(false);
+ });
}
} catch (error) {
if (requestId === fetchRequestId) {
+ setHistoryLoadError(true);
logger.error('Failed to load history:', error);
}
} finally {
@@ -181,6 +194,12 @@ export function useAlertHistoryState(props: UseAlertHistoryStateProps) {
}
};
+ // An explicit retry is a read, not history deletion or notification replay.
+ const retryHistory = () => {
+ if (loading() || disposed) return;
+ return fetchHistory(timeFilter());
+ };
+
let lastTimeFilterValue: string | null = null;
createEffect(() => {
const current = timeFilter();
@@ -233,7 +252,11 @@ export function useAlertHistoryState(props: UseAlertHistoryStateProps) {
void fetchHistory(timeFilter());
const unsubscribeOrgSwitched = eventBus.on('org_switched', () => {
+ historyContextVersion++;
setAlertHistory([]);
+ setLoadedHistoryRange(null);
+ setHistoryLoadError(false);
+ requestedRange = null;
setSelectedBarIndex(null);
resourceIncidentsState.resetResourceIncidentsState();
resetState();
@@ -241,6 +264,7 @@ export function useAlertHistoryState(props: UseAlertHistoryStateProps) {
});
onCleanup(() => {
+ disposed = true;
unsubscribeOrgSwitched();
fetchRequestId++;
});
@@ -259,7 +283,9 @@ export function useAlertHistoryState(props: UseAlertHistoryStateProps) {
const allHistoryData = createMemo<HistoryItem[]>(() => {
return buildAlertHistoryItems({
activeAlerts: props.activeAlerts() || {},
- alertHistory: alertHistory(),
+ // A failed larger-range read must not label a smaller snapshot as complete.
+ // Keep the last snapshot for same-range retry, but never reuse it in another range.
+ alertHistory: loadedHistoryRange() === timeFilter() ? alertHistory() : [],
getResource: props.getResource,
allResources: props.allResources(),
});
@@ -307,17 +333,23 @@ export function useAlertHistoryState(props: UseAlertHistoryStateProps) {
);
const clearAlertHistory = async () => {
+ if (disposed) return;
if (!confirm(getAlertAdministrationClearHistoryConfirmation())) {
return;
}
+ const contextVersion = historyContextVersion;
try {
await AlertsAPI.clearHistory();
+ if (disposed || contextVersion !== historyContextVersion) return;
// Reads started before the clear completed may still contain deleted rows.
fetchRequestId++;
setLoading(false);
setAlertHistory([]);
+ setLoadedHistoryRange(timeFilter());
+ setHistoryLoadError(false);
} catch (error) {
+ if (disposed || contextVersion !== historyContextVersion) return;
logger.error(getAlertAdministrationClearHistoryError(), error);
notificationStore.error(getAlertAdministrationClearHistoryError());
}
@@ -333,6 +365,8 @@ export function useAlertHistoryState(props: UseAlertHistoryStateProps) {
setSearchTerm,
alertHistory,
loading,
+ historyLoadError,
+ retryHistory,
selectedBarIndex,
setSelectedBarIndex,
resourceIncidentPanel: resourceIncidentsState.resourceIncidentPanel,
diff --git a/frontend-modern/src/utils/__tests__/alertOverviewPresentation.test.ts b/frontend-modern/src/utils/__tests__/alertOverviewPresentation.test.ts
index acbc4530c4..37cef7e259 100644
--- a/frontend-modern/src/utils/__tests__/alertOverviewPresentation.test.ts
+++ b/frontend-modern/src/utils/__tests__/alertOverviewPresentation.test.ts
@@ -65,6 +65,7 @@ import {
getAlertOverviewTimelineActionLabel,
getAlertHistoryEmptyState,
getAlertHistoryLoadingState,
+ getAlertHistoryLoadFailure,
getAlertHistorySearchPlaceholder,
getAlertBucketCountLabel,
getAlertFilteredEmptyState,
@@ -404,6 +405,17 @@ describe('alertOverviewPresentation', () => {
expect(getAlertTimelineEventTypeLabel('alert_resolved')).toBe('Behoben');
});
+ it('describes a failed History read as incomplete evidence with a read-only retry', () => {
+ expect(getAlertHistoryLoadFailure()).toEqual({
+ title: 'Could not load alert history',
+ description:
+ 'Any entries shown may be incomplete or out of date. Retry to refresh saved history.',
+ retryLabel: 'Retry history',
+ retryingLabel: 'Retrying…',
+ });
+ expect(getAlertHistoryLoadFailure().title).not.toBe(getAlertHistoryEmptyState().title);
+ });
+
it('says how long ago an alert started in the active locale and moves with the clock', () => {
const start = '2026-10-04T12:00:00Z';
const at = (minutes: number) => Date.parse(start) + minutes * 60_000;
diff --git a/frontend-modern/src/utils/alertOverviewPresentation.ts b/frontend-modern/src/utils/alertOverviewPresentation.ts
index c165f6ca4d..1c0c3bd361 100644
--- a/frontend-modern/src/utils/alertOverviewPresentation.ts
+++ b/frontend-modern/src/utils/alertOverviewPresentation.ts
@@ -420,6 +420,16 @@ export function getAlertHistoryLoadingState() {
} as const;
}
+export function getAlertHistoryLoadFailure() {
+ return {
+ title: 'Could not load alert history',
+ description:
+ 'Any entries shown may be incomplete or out of date. Retry to refresh saved history.',
+ retryLabel: 'Retry history',
+ retryingLabel: 'Retrying…',
+ } as const;
+}
+
export function getAlertBucketCountLabel(count: number) {
return count === 0 ? ALERT_BUCKET_EMPTY_LABEL : `${count} alert${count === 1 ? '' : 's'}`;
}