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.
Go aialertsdashboarddockerdocker-monitoringgohomelabinfrastructure-monitoringkubernetesmonitoringmspproxmoxproxmox-backup-serverproxmox-mail-gatewayproxmox-veself-hostedtruenastypescriptvspherewebhooks
Fail closed malformed approval expiry state
rcourtman9cbd3dcbc688
diff --git a/docs/release-control/v6/internal/subsystems/patrol-intelligence.md b/docs/release-control/v6/internal/subsystems/patrol-intelligence.mdindex 2b2acd7c16..454b72c95c 100644--- a/docs/release-control/v6/internal/subsystems/patrol-intelligence.md+++ b/docs/release-control/v6/internal/subsystems/patrol-intelligence.md@@ -37,17 +37,18 @@ Patrol-specific presentation helpers.14. `frontend-modern/src/components/patrol/`15. `frontend-modern/src/utils/aiFindingPresentation.ts`16. `frontend-modern/src/utils/approvalRiskPresentation.ts`-17. `frontend-modern/src/utils/aiPatrolSchedulePresentation.ts`-18. `frontend-modern/src/utils/findingAlertIdentity.ts`-19. `frontend-modern/src/utils/remediationPresentation.ts`-20. `frontend-modern/src/utils/patrolEmptyStatePresentation.ts`-21. `frontend-modern/src/utils/patrolFormat.ts`-22. `frontend-modern/src/utils/patrolRunPresentation.ts`-23. `frontend-modern/src/utils/patrolSummaryPresentation.ts`-24. `frontend-modern/src/utils/patrolRuntimePresentation.ts`-25. `frontend-modern/src/utils/patrolRuntimeActions.ts`-26. `frontend-modern/src/utils/textPresentation.ts`-27. `tests/integration/tests/73-patrol-assistant-operator-briefing.spec.ts`+17. `frontend-modern/src/utils/approvalState.ts`+18. `frontend-modern/src/utils/aiPatrolSchedulePresentation.ts`+19. `frontend-modern/src/utils/findingAlertIdentity.ts`+20. `frontend-modern/src/utils/remediationPresentation.ts`+21. `frontend-modern/src/utils/patrolEmptyStatePresentation.ts`+22. `frontend-modern/src/utils/patrolFormat.ts`+23. `frontend-modern/src/utils/patrolRunPresentation.ts`+24. `frontend-modern/src/utils/patrolSummaryPresentation.ts`+25. `frontend-modern/src/utils/patrolRuntimePresentation.ts`+26. `frontend-modern/src/utils/patrolRuntimeActions.ts`+27. `frontend-modern/src/utils/textPresentation.ts`+28. `tests/integration/tests/73-patrol-assistant-operator-briefing.spec.ts`## Shared Boundaries@@ -781,11 +782,13 @@ approval consumers must treat the approval queue as `soonest expiry first`,then higher risk, then older request time, rather than inheriting raw APIorder. Approval-linked findings must follow that same ordering so multi-approval`Review` actions jump to the most urgent finding instead of an arbitrary one.-Malformed or missing approval timestamps must sort after valid timestamps and-must not produce non-deterministic comparator results in the shared urgency-utility. Patrol approval banners must apply the same fail-closed timestamp-posture to visible countdown copy instead of rendering invalid math such as-`NaN`.+Malformed or missing approval expiry timestamps must fail closed in the shared+approval-state utility: they are not live/actionable pending approvals and the+owning finding must return to the needs-attention path. If malformed approval+records still reach presentation helpers, they must sort after valid timestamps+and must not produce non-deterministic comparator results. Patrol approval+banners must apply the same fail-closed timestamp posture to visible countdown+copy instead of rendering invalid math such as `NaN`.Patrol fix approvals also inherit the unified action-governance preflightcontract: queued fixes must keep their plan-level dry-run availability, safetychecks, verification steps, approval policy, and action id in the shareddiff --git a/docs/release-control/v6/internal/subsystems/registry.json b/docs/release-control/v6/internal/subsystems/registry.jsonindex 5b60c16f3f..68abc15975 100644--- a/docs/release-control/v6/internal/subsystems/registry.json+++ b/docs/release-control/v6/internal/subsystems/registry.json@@ -4073,6 +4073,7 @@"frontend-modern/src/utils/aiFindingPresentation.ts","frontend-modern/src/utils/aiPatrolSchedulePresentation.ts","frontend-modern/src/utils/approvalRiskPresentation.ts",+ "frontend-modern/src/utils/approvalState.ts","frontend-modern/src/utils/findingAlertIdentity.ts","frontend-modern/src/utils/patrolEmptyStatePresentation.ts","frontend-modern/src/utils/patrolFormat.ts",@@ -4153,6 +4154,7 @@"frontend-modern/src/components/patrol/RemediationStatus.tsx","frontend-modern/src/utils/aiFindingPresentation.ts","frontend-modern/src/utils/approvalRiskPresentation.ts",+ "frontend-modern/src/utils/approvalState.ts","frontend-modern/src/utils/findingAlertIdentity.ts","frontend-modern/src/utils/remediationPresentation.ts"],@@ -4163,6 +4165,7 @@"frontend-modern/src/components/patrol/__tests__/ApprovalSection.test.tsx","frontend-modern/src/components/patrol/__tests__/InvestigationSection.test.tsx","frontend-modern/src/utils/__tests__/approvalRiskPresentation.test.ts",+ "frontend-modern/src/utils/__tests__/approvalState.test.ts","frontend-modern/src/utils/__tests__/findingAlertIdentity.test.ts","frontend-modern/src/utils/__tests__/frontendResourceTypeBoundaries.test.ts","frontend-modern/src/utils/__tests__/remediationPresentation.test.ts"diff --git a/frontend-modern/src/stores/__tests__/aiIntelligence.test.ts b/frontend-modern/src/stores/__tests__/aiIntelligence.test.tsindex 85d13998ca..a461174d9c 100644--- a/frontend-modern/src/stores/__tests__/aiIntelligence.test.ts+++ b/frontend-modern/src/stores/__tests__/aiIntelligence.test.ts@@ -495,6 +495,53 @@ describe('aiIntelligenceStore', () => {vi.useRealTimers();});+ it('fails malformed approval expiries closed and restores needs-attention state', async () => {+ vi.mocked(AIAPI.getUnifiedFindings).mockResolvedValueOnce({+ findings: [+ {+ id: 'finding-malformed-approval',+ source: 'ai-patrol',+ severity: 'warning',+ category: 'performance',+ resource_id: 'instance:node:202',+ resource_name: 'node-202',+ resource_type: 'host',+ title: 'Queued remediation with malformed approval',+ description: 'Patrol queued a remediation with malformed approval expiry.',+ detected_at: '2026-03-01T00:00:00Z',+ status: 'active',+ investigation_outcome: 'fix_queued',+ },+ ],+ count: 1,+ });++ vi.mocked(AIAPI.getPendingApprovals).mockResolvedValueOnce([+ {+ id: 'approval-malformed-expiry',+ toolId: 'investigation_fix',+ command: 'systemctl restart pulse-agent',+ targetType: 'host',+ targetId: 'finding-malformed-approval',+ targetName: 'node-202',+ context: 'Restart the agent',+ riskLevel: 'medium',+ status: 'pending',+ requestedAt: '2026-03-01T00:01:00Z',+ expiresAt: 'not-a-date',+ },+ ]);++ await aiIntelligenceStore.loadFindings();+ await aiIntelligenceStore.loadPendingApprovals();++ expect(aiIntelligenceStore.pendingApprovalCount).toBe(0);+ expect(aiIntelligenceStore.findingsWithPendingApprovals).toEqual([]);+ expect(aiIntelligenceStore.findingsNeedingAttention.map((finding) => finding.id)).toEqual([+ 'finding-malformed-approval',+ ]);+ });+it('sorts Patrol runtime findings to the top of the shared needs-attention queue', async () => {vi.mocked(AIAPI.getUnifiedFindings).mockResolvedValueOnce({findings: [diff --git a/frontend-modern/src/utils/__tests__/approvalState.test.ts b/frontend-modern/src/utils/__tests__/approvalState.test.tsnew file mode 100644index 0000000000..ed4775ddc4--- /dev/null+++ b/frontend-modern/src/utils/__tests__/approvalState.test.ts@@ -0,0 +1,36 @@+import { describe, expect, it } from 'vitest';+import { getApprovalExpiryTime, isLivePendingApproval } from '@/utils/approvalState';++describe('approvalState', () => {+ const now = Date.parse('2026-05-07T10:00:00Z');++ it('parses valid approval expiry timestamps', () => {+ expect(getApprovalExpiryTime({ expiresAt: '2026-05-07T10:05:00Z' })).toBe(+ Date.parse('2026-05-07T10:05:00Z'),+ );+ });++ it('treats malformed or missing expiry timestamps as unavailable', () => {+ expect(getApprovalExpiryTime({ expiresAt: 'not-a-date' })).toBeNull();+ expect(getApprovalExpiryTime({ expiresAt: undefined })).toBeNull();+ expect(getApprovalExpiryTime({ expiresAt: null })).toBeNull();+ });++ it('keeps only pending approvals with a future parseable expiry live', () => {+ expect(isLivePendingApproval({ status: 'pending', expiresAt: '2026-05-07T10:05:00Z' }, now)).toBe(+ true,+ );+ expect(isLivePendingApproval({ status: 'pending', expiresAt: '2026-05-07T09:59:00Z' }, now)).toBe(+ false,+ );+ expect(isLivePendingApproval({ status: 'approved', expiresAt: '2026-05-07T10:05:00Z' }, now)).toBe(+ false,+ );+ });++ it('fails closed when a pending approval expiry is malformed or missing', () => {+ expect(isLivePendingApproval({ status: 'pending', expiresAt: 'not-a-date' }, now)).toBe(false);+ expect(isLivePendingApproval({ status: 'pending', expiresAt: undefined }, now)).toBe(false);+ expect(isLivePendingApproval({ status: 'pending', expiresAt: null }, now)).toBe(false);+ });+});diff --git a/frontend-modern/src/utils/approvalState.ts b/frontend-modern/src/utils/approvalState.tsindex 86e17a92ba..ae3bd9bf5e 100644--- a/frontend-modern/src/utils/approvalState.ts+++ b/frontend-modern/src/utils/approvalState.ts@@ -1,14 +1,14 @@import type { ApprovalRequest } from '@/api/ai';export const getApprovalExpiryTime = (- approval: Pick<ApprovalRequest, 'expiresAt'>,+ approval: { expiresAt?: ApprovalRequest['expiresAt'] | null },): number | null => {- const expiry = Date.parse(approval.expiresAt);+ const expiry = Date.parse(approval.expiresAt ?? '');return Number.isFinite(expiry) ? expiry : null;};export const isLivePendingApproval = (- approval: Pick<ApprovalRequest, 'status' | 'expiresAt'>,+ approval: Pick<ApprovalRequest, 'status'> & { expiresAt?: ApprovalRequest['expiresAt'] | null },now = Date.now(),): boolean => {if (approval.status !== 'pending') {@@ -17,7 +17,7 @@ export const isLivePendingApproval = (const expiry = getApprovalExpiryTime(approval);if (expiry === null) {- return true;+ return false;}return expiry > now;diff --git a/scripts/release_control/canonical_completion_guard_test.py b/scripts/release_control/canonical_completion_guard_test.pyindex 53579394d4..30fd4519ce 100644--- a/scripts/release_control/canonical_completion_guard_test.py+++ b/scripts/release_control/canonical_completion_guard_test.py@@ -3108,6 +3108,7 @@ index 1111111..2222222 100644"frontend-modern/src/components/patrol/__tests__/ApprovalSection.test.tsx","frontend-modern/src/components/patrol/__tests__/InvestigationSection.test.tsx","frontend-modern/src/utils/__tests__/approvalRiskPresentation.test.ts",+ "frontend-modern/src/utils/__tests__/approvalState.test.ts","frontend-modern/src/utils/__tests__/findingAlertIdentity.test.ts","frontend-modern/src/utils/__tests__/frontendResourceTypeBoundaries.test.ts","frontend-modern/src/utils/__tests__/remediationPresentation.test.ts",diff --git a/scripts/release_control/subsystem_lookup_test.py b/scripts/release_control/subsystem_lookup_test.pyindex eb2fc643cc..e14057162c 100644--- a/scripts/release_control/subsystem_lookup_test.py+++ b/scripts/release_control/subsystem_lookup_test.py@@ -3831,6 +3831,7 @@ class SubsystemLookupTest(unittest.TestCase):"frontend-modern/src/components/patrol/__tests__/ApprovalSection.test.tsx","frontend-modern/src/components/patrol/__tests__/InvestigationSection.test.tsx","frontend-modern/src/utils/__tests__/approvalRiskPresentation.test.ts",+ "frontend-modern/src/utils/__tests__/approvalState.test.ts","frontend-modern/src/utils/__tests__/findingAlertIdentity.test.ts","frontend-modern/src/utils/__tests__/frontendResourceTypeBoundaries.test.ts","frontend-modern/src/utils/__tests__/remediationPresentation.test.ts",@@ -3861,6 +3862,7 @@ class SubsystemLookupTest(unittest.TestCase):"frontend-modern/src/components/patrol/__tests__/ApprovalSection.test.tsx","frontend-modern/src/components/patrol/__tests__/InvestigationSection.test.tsx","frontend-modern/src/utils/__tests__/approvalRiskPresentation.test.ts",+ "frontend-modern/src/utils/__tests__/approvalState.test.ts","frontend-modern/src/utils/__tests__/findingAlertIdentity.test.ts","frontend-modern/src/utils/__tests__/frontendResourceTypeBoundaries.test.ts","frontend-modern/src/utils/__tests__/remediationPresentation.test.ts",