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.

Bound Patrol refresh state

rcourtman1e33d3089c13
diff --git a/docs/release-control/v6/internal/subsystems/api-contracts.md b/docs/release-control/v6/internal/subsystems/api-contracts.md
index 1976640d0c..f4cb49f858 100644
--- a/docs/release-control/v6/internal/subsystems/api-contracts.md
+++ b/docs/release-control/v6/internal/subsystems/api-contracts.md
@@ -530,6 +530,7 @@ the canonical monitored-system blocked payload.
and the resource-intelligence payload carried by the drawer AI card, so the resource-detail surface stays on one canonical intelligence contract instead of introducing a separate detail endpoint
and the learned-correlation payload loaded into the shared AI intelligence store, so the Patrol intelligence page and the AI summary page consume the same governed correlation slice instead of each page fetching its own copy
and the shared dashboard-load bundle inside `frontend-modern/src/stores/aiIntelligence.ts`, so the page orchestration stays on the store-owned bundle instead of enumerating the AI fetches inline
+ and the Patrol page refresh lifecycle in `frontend-modern/src/features/patrol/usePatrolIntelligenceState.ts`, so slow or stalled secondary reads from that shared dashboard-load bundle may continue resolving in the background while the operator-facing Patrol refresh control remains generation-aware, timeout-bounded, and reusable once Patrol findings and status are already visible
and the shared `frontend-modern/src/components/Infrastructure/ResourcePolicySummary.tsx` card, so the AI summary page renders the governed policy-posture counts while the resource drawer stays on per-resource policy lines instead of carrying duplicate posture UI loops
and the dedicated `frontend-modern/src/features/patrol/patrolInvestigationContextModel.ts` owner, so recent-change, learned-correlation, and policy-coverage summary text stays derived from the canonical AI payload in one place instead of as hook-local count and pluralization logic
and that same Patrol investigation-context owner, so the current Patrol
diff --git a/docs/release-control/v6/internal/subsystems/frontend-primitives.md b/docs/release-control/v6/internal/subsystems/frontend-primitives.md
index cd946eef52..d75e8e4fe4 100644
--- a/docs/release-control/v6/internal/subsystems/frontend-primitives.md
+++ b/docs/release-control/v6/internal/subsystems/frontend-primitives.md
@@ -978,6 +978,11 @@ prompt explain the same operator-facing priority.
that exist on `FindingsTrustSummary`; shared drawer/chrome
primitives stay free of the trust shape so adding new trust signals
goes through the contract first rather than per-shell branching.
+ Patrol header refresh controls stay on that same feature-owned shell
+ boundary: `frontend-modern/src/features/patrol/usePatrolIntelligenceState.ts`
+ must make the refresh affordance generation-aware and timeout-bounded, so
+ a slow supporting intelligence read cannot permanently disable the shared
+ Patrol header control while Patrol findings and status remain visible.
That feature-owned
presentation helper is the single emitter for investigation-record
`impact` and `rollback` fields: when an investigation record exists but those fields
@@ -2506,6 +2511,11 @@ That same run-history ownership applies to assessment caveats: Patrol summary
shells should not present `Recent coverage is incomplete` when the shared
recency/verification helpers already prove a successful full patrol with
non-zero resource coverage.
+That same Patrol shell ownership includes refresh affordance state:
+`frontend-modern/src/features/patrol/usePatrolIntelligenceState.ts` must keep
+operator refresh controls generation-aware and timeout-bounded, so a slow
+supporting intelligence read cannot permanently disable the shared Patrol header
+Refresh button while Patrol findings and status remain visible.
That same Patrol shell should make scoped trigger policy legible without
another navigation step. `frontend-modern/src/features/patrol/PatrolIntelligenceHeader.tsx`
should present alert-triggered and anomaly-triggered Patrol toggles as distinct
diff --git a/docs/release-control/v6/internal/subsystems/patrol-intelligence.md b/docs/release-control/v6/internal/subsystems/patrol-intelligence.md
index 0a657fdec9..32d0ee9cfc 100644
--- a/docs/release-control/v6/internal/subsystems/patrol-intelligence.md
+++ b/docs/release-control/v6/internal/subsystems/patrol-intelligence.md
@@ -86,6 +86,10 @@ Patrol-specific presentation helpers.
mask direct Patrol evidence that has already loaded. Background Patrol
refreshes must preserve already-loaded findings instead of replacing the
workspace with a blocking loading state.
+ Patrol page refresh state must also be generation-aware and timeout-bounded:
+ slow or stalled supporting intelligence reads may continue in the background,
+ but they must not permanently disable the operator's Refresh control once
+ Patrol findings and status remain visible.
2. Keep Patrol-specific copy and badge logic inside the governed Patrol presentation helpers instead of page-local branches
Patrol assessment copy must not present an all-clear health prediction while
active Patrol findings or Patrol runtime issues are still present. The
diff --git a/frontend-modern/src/features/patrol/__tests__/usePatrolIntelligenceState.test.ts b/frontend-modern/src/features/patrol/__tests__/usePatrolIntelligenceState.test.ts
index 03d7bf48b0..f0d141397a 100644
--- a/frontend-modern/src/features/patrol/__tests__/usePatrolIntelligenceState.test.ts
+++ b/frontend-modern/src/features/patrol/__tests__/usePatrolIntelligenceState.test.ts
@@ -1,10 +1,12 @@
import { describe, expect, it } from 'vitest';
import {
+ PATROL_REFRESH_TIMEOUT_MS,
buildPatrolSettingsReadinessFailure,
resolvePatrolAutonomyLevelForSave,
resolvePatrolAutonomySettingsForSave,
} from '../usePatrolIntelligenceState';
+import patrolIntelligenceStateSource from '../usePatrolIntelligenceState.ts?raw';
import type { AISettings, PatrolReadiness } from '@/types/ai';
const settingsWithReadiness = (patrolReadiness: PatrolReadiness): AISettings => ({
@@ -26,6 +28,15 @@ const settingsWithReadiness = (patrolReadiness: PatrolReadiness): AISettings =>
});
describe('usePatrolIntelligenceState', () => {
+ it('bounds refresh UI state with a generation-aware timeout', () => {
+ expect(PATROL_REFRESH_TIMEOUT_MS).toBe(15000);
+ expect(patrolIntelligenceStateSource).toContain('let refreshRequestId = 0;');
+ expect(patrolIntelligenceStateSource).toContain('const requestId = ++refreshRequestId;');
+ expect(patrolIntelligenceStateSource).toContain('if (requestId === refreshRequestId) {');
+ expect(patrolIntelligenceStateSource).toContain('setIsRefreshing(false);');
+ expect(patrolIntelligenceStateSource).toContain('clearRefreshTimeout();');
+ });
+
describe('resolvePatrolAutonomyLevelForSave', () => {
it('clamps stale paid autonomy to monitor when safe remediation is locked', () => {
expect(resolvePatrolAutonomyLevelForSave('full', true, true)).toBe('monitor');
diff --git a/frontend-modern/src/features/patrol/usePatrolIntelligenceState.ts b/frontend-modern/src/features/patrol/usePatrolIntelligenceState.ts
index 1bafdf076f..1143373807 100644
--- a/frontend-modern/src/features/patrol/usePatrolIntelligenceState.ts
+++ b/frontend-modern/src/features/patrol/usePatrolIntelligenceState.ts
@@ -42,6 +42,8 @@ type PatrolAPIError = Error & {
status?: number;
};
+export const PATROL_REFRESH_TIMEOUT_MS = 15000;
+
const patrolErrorMessage = (error: unknown, fallback: string) =>
error instanceof Error && error.message.trim() ? error.message : fallback;
@@ -176,6 +178,8 @@ export function usePatrolIntelligenceState() {
let safetyTimerRef: ReturnType<typeof setTimeout> | undefined;
let scrollToFindingTimerRef: ReturnType<typeof setTimeout> | undefined;
let findingScrollTimerRef: ReturnType<typeof setTimeout> | undefined;
+ let refreshTimeoutRef: ReturnType<typeof setTimeout> | undefined;
+ let refreshRequestId = 0;
let refreshInterval: ReturnType<typeof setInterval>;
let approvalPollInterval: ReturnType<typeof setInterval>;
@@ -201,6 +205,21 @@ export function usePatrolIntelligenceState() {
}
};
+ const clearRefreshTimeout = () => {
+ if (refreshTimeoutRef !== undefined) {
+ clearTimeout(refreshTimeoutRef);
+ refreshTimeoutRef = undefined;
+ }
+ };
+
+ const finishRefresh = (requestId: number) => {
+ if (requestId !== refreshRequestId) {
+ return;
+ }
+ clearRefreshTimeout();
+ setIsRefreshing(false);
+ };
+
const patrolStatusState = createNonSuspendingQuery<PatrolStatus | null, string>({
source: () => 'patrol-status',
cacheKey: () => 'patrol-status',
@@ -782,12 +801,23 @@ export function usePatrolIntelligenceState() {
}
async function loadAllData() {
+ const requestId = ++refreshRequestId;
+ clearRefreshTimeout();
setIsRefreshing(true);
+ refreshTimeoutRef = setTimeout(() => {
+ if (requestId === refreshRequestId) {
+ refreshTimeoutRef = undefined;
+ setIsRefreshing(false);
+ }
+ }, PATROL_REFRESH_TIMEOUT_MS);
+
try {
await Promise.all([aiIntelligenceStore.loadDashboardData(), refetchPatrolStatus()]);
- setActivityRefreshTrigger((prev) => prev + 1);
+ if (requestId === refreshRequestId) {
+ setActivityRefreshTrigger((prev) => prev + 1);
+ }
} finally {
- setIsRefreshing(false);
+ finishRefresh(requestId);
}
}
@@ -876,7 +906,10 @@ export function usePatrolIntelligenceState() {
};
document.addEventListener('visibilitychange', handleVisibility);
- onCleanup(() => document.removeEventListener('visibilitychange', handleVisibility));
+ onCleanup(() => {
+ document.removeEventListener('visibilitychange', handleVisibility);
+ clearRefreshTimeout();
+ });
});
onCleanup(() => {
diff --git a/frontend-modern/src/pages/__tests__/AIIntelligence.test.tsx b/frontend-modern/src/pages/__tests__/AIIntelligence.test.tsx
index f918091206..78fe78cce9 100644
--- a/frontend-modern/src/pages/__tests__/AIIntelligence.test.tsx
+++ b/frontend-modern/src/pages/__tests__/AIIntelligence.test.tsx
@@ -4,6 +4,7 @@ import { Suspense, createSignal } from 'solid-js';
import { resetCreateNonSuspendingQueryCacheForTest } from '@/hooks/createNonSuspendingQuery';
import { resetAIRuntimeState } from '@/stores/aiRuntimeState';
import { getPublicPricingUrl } from '@/utils/pricingHandoff';
+import patrolIntelligenceStateSource from '@/features/patrol/usePatrolIntelligenceState.ts?raw';
import { AIIntelligence } from '../AIIntelligence';
@@ -327,6 +328,12 @@ const defaultAISettings = {
};
describe('AIIntelligence entitlement gating', () => {
+ it('keeps Patrol page refresh affordance bounded when supporting reads stall', () => {
+ expect(patrolIntelligenceStateSource).toContain('PATROL_REFRESH_TIMEOUT_MS');
+ expect(patrolIntelligenceStateSource).toContain('finishRefresh(requestId)');
+ expect(patrolIntelligenceStateSource).toContain('requestId === refreshRequestId');
+ });
+
beforeEach(() => {
resetCreateNonSuspendingQueryCacheForTest();
resetAIRuntimeState();