From eebe0b5f748ba7532c2dbfb6b89048aa73ba300e Mon Sep 17 00:00:00 2001 From: rcourtman Date: Sat, 27 Jun 2026 00:00:10 +0100 Subject: [PATCH] Clear AI intelligence state on org switch to prevent data bleed The aiIntelligence store (findings, patrol findings, remediation plans, pending approvals, circuit breaker, correlations) was not reset when switching organizations. Findings from the previous org would remain visible until the next polling cycle refreshed them. Added org_switched event listener that resets all signals and clears the pending approval expiry timer. --- frontend-modern/src/stores/aiIntelligence.ts | 23 ++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/frontend-modern/src/stores/aiIntelligence.ts b/frontend-modern/src/stores/aiIntelligence.ts index 6650fb3fb..df483182a 100644 --- a/frontend-modern/src/stores/aiIntelligence.ts +++ b/frontend-modern/src/stores/aiIntelligence.ts @@ -40,6 +40,7 @@ import { logger } from '@/utils/logger'; import type { CorrelationsResponse, IntelligenceSummary } from '@/types/aiIntelligence'; import { normalizeIntelligenceSummary } from './aiIntelligenceSummaryModel'; import { presentationPolicyIsDemoMode } from './sessionPresentationPolicy'; +import { eventBus } from './events'; // ============================================ // Enum validation helpers @@ -425,6 +426,28 @@ const [intelligenceSummary, setIntelligenceSummary] = createSignal(null); +// ============================================ +// Org Switch Reset +// ============================================ + +eventBus.on('org_switched', () => { + setUnifiedFindings([]); + setFindingsLoading(false); + setFindingsError(null); + setPatrolFindings([]); + setPatrolFindingsLoading(false); + setPatrolFindingsError(null); + patrolFindingsIncludeResolvedPreference = false; + setRemediationPlans([]); + setPlansLoading(false); + setPlansError(null); + setPendingApprovalsWithExpiryTracking([]); + setApprovalsError(null); + setCircuitBreakerStatus(null); + setIntelligenceSummary(null); + setCorrelations(null); +}); + // ============================================ // Store API // ============================================