1a3c405345
Fixes Copilot audit issues #2 and #4 (code we added): Issue #2 - Multiple Event Emissions (MEDIUM severity): - Changed: Collect all merge notifications in array - Emit: Single batched event instead of multiple separate events - Impact: Better performance, fewer DB transactions, no UI flickering Issue #4 - Storage Validation (MEDIUM severity): - Added: Warning log when LID-PN mappings fail to store - Tracks: errors count vs notifications sent for debugging - Improves: Observability of partial storage failures Technical changes: - Declared mergeNotifications array before loop - Compute mergedAt timestamp once (not per iteration) - Push notifications to array instead of emitting in loop - Emit single chats.update with all notifications - Log warning with detailed counts if result.errors > 0 Benefits: ✅ 100x fewer events for 100 mappings (1 vs 100) ✅ Better consumer performance (ZPRO) ✅ Improved observability of storage failures ✅ Zero breaking changes (backward compatible) Note: Did NOT fix Issue #3 (Prototype Pollution) as it's in pre-existing code (event-buffer.ts), not code we added. https://claude.ai/code/session_01SoNUGBEWbJwWWws3F2fuzh