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.
This commit is contained in:
rcourtman 2026-06-27 00:00:10 +01:00
parent fa3f57e6ba
commit eebe0b5f74

View file

@ -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<IntelligenceS
const [correlations, setCorrelations] = createSignal<CorrelationsResponse | null>(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
// ============================================