Skip to content

Fix double notifications from duplicate event dispatch and listener registration#2

Draft
Onr with Copilot wants to merge 5 commits into
mainfrom
copilot/fix-double-notification-issue
Draft

Fix double notifications from duplicate event dispatch and listener registration#2
Onr with Copilot wants to merge 5 commits into
mainfrom
copilot/fix-double-notification-issue

Conversation

Copilot AI commented Jan 14, 2026

Copy link
Copy Markdown

Agent messages triggered duplicate notifications due to three concurrent bugs in the dashboard polling logic.

Root Causes

Duplicate event dispatch - Each message dispatched newAgentMessage event twice:

// Before
data.messages.forEach(message => {
  document.dispatchEvent(new CustomEvent('newAgentMessage', { detail: message }));
  document.dispatchEvent(new CustomEvent('newAgentMessage', { detail: message })); // duplicate
});

// After
data.messages.forEach(message => {
  document.dispatchEvent(new CustomEvent('newAgentMessage', { detail: message }));
});

Unchecked re-initialization - Multiple calls to initializeDashboard() registered duplicate event listeners. Added isInitialized guard.

Interval leak - startMessagePolling() created new intervals without clearing previous ones. Now calls clearInterval() before setInterval().

Changes

  • public/js/dashboard.js - Removed duplicate dispatch, added init guard and interval cleanup
  • __tests__/dashboard.test.js - Test coverage for all three bugs
  • Documentation files for investigation and troubleshooting

Impact

  • Notifications: 2× → 1× per message
  • Eliminated memory leaks from uncleaned intervals and listeners
  • ~50% reduction in event processing overhead
Original prompt

when an agent send a message we get double notifications could find out why is that happens?


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 4 commits January 14, 2026 12:10
Co-authored-by: Onr <8344672+Onr@users.noreply.github.com>
Co-authored-by: Onr <8344672+Onr@users.noreply.github.com>
Co-authored-by: Onr <8344672+Onr@users.noreply.github.com>
Co-authored-by: Onr <8344672+Onr@users.noreply.github.com>
Copilot AI changed the title [WIP] Investigate cause of double notifications for agent messages Fix double notifications from duplicate event dispatch and listener registration Jan 14, 2026
Copilot AI requested a review from Onr January 14, 2026 12:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants