From 7b2849d16d097ece300a95062ea1c5df98a05fa8 Mon Sep 17 00:00:00 2001 From: rcourtman Date: Fri, 26 Jun 2026 23:25:56 +0100 Subject: [PATCH] Fix NaN propagation in alert grouping window and AI duration display setGroupingWindow stored Number.parseInt result without checking for NaN, while the adjacent setEscalationAfter properly guards against it. If an invalid value reached the parser, NaN would propagate into the grouping config and could cascade into alert delivery issues. formatDuration in AIModelSelectionSection displayed raw NaN/Infinity/ negative values without guarding. Now returns '-' for non-finite or negative inputs. --- .../src/components/Settings/AIModelSelectionSection.tsx | 3 ++- frontend-modern/src/features/alerts/useAlertScheduleState.ts | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/frontend-modern/src/components/Settings/AIModelSelectionSection.tsx b/frontend-modern/src/components/Settings/AIModelSelectionSection.tsx index 3998a85e4..7ce7e46e1 100644 --- a/frontend-modern/src/components/Settings/AIModelSelectionSection.tsx +++ b/frontend-modern/src/components/Settings/AIModelSelectionSection.tsx @@ -126,7 +126,8 @@ export const PatrolPreflightControl: Component<{ state: AISettingsState }> = (co }; const formatDuration = (ms: number) => { - if (ms < 1000) return `${ms}ms`; + if (!Number.isFinite(ms) || ms < 0) return '-'; + if (ms < 1000) return `${Math.round(ms)}ms`; return `${(ms / 1000).toFixed(1)}s`; }; diff --git a/frontend-modern/src/features/alerts/useAlertScheduleState.ts b/frontend-modern/src/features/alerts/useAlertScheduleState.ts index be1be54a3..28297c3fa 100644 --- a/frontend-modern/src/features/alerts/useAlertScheduleState.ts +++ b/frontend-modern/src/features/alerts/useAlertScheduleState.ts @@ -254,9 +254,10 @@ export function useAlertScheduleState(props: UseAlertScheduleStateProps) { }; const setGroupingWindow = (rawValue: string) => { + const parsed = Number.parseInt(rawValue, 10); props.setGrouping({ ...props.grouping(), - window: Number.parseInt(rawValue, 10), + window: Number.isNaN(parsed) ? props.grouping().window : parsed, }); markUnsaved(); };