Skip to content

fix: prevent duplicate message delivery in communicate service#539

Open
geoffjay wants to merge 2 commits intomainfrom
fix/duplicate-message-delivery
Open

fix: prevent duplicate message delivery in communicate service#539
geoffjay wants to merge 2 commits intomainfrom
fix/duplicate-message-delivery

Conversation

@geoffjay
Copy link
Copy Markdown
Owner

@geoffjay geoffjay commented Mar 20, 2026

Summary

  • Abort orphaned subscription tasks in the communicate WebSocket handler (websocket.rs). When a client resubscribes to a room (e.g. after reconnection), the old forwarding task was silently orphaned and continued delivering messages alongside the new task, causing 4-5x duplicate delivery.
  • Add message ID deduplication in the orchestrator MessageBridge (message_bridge.rs). A seen-message set (capped at 1000 entries) skips messages that have already been processed, providing a second layer of defense against duplicates.

Closes #537

Test plan

  • Verify cargo check -p communicate -p orchestrator passes
  • Verify cargo clippy -p communicate -p orchestrator --no-deps is clean
  • Start services and send messages in a room with multiple agents — each message should be delivered exactly once
  • Simulate reconnection (restart communicate service) and verify no duplicate deliveries after resubscription
  • Verify echo prevention still works (agent responses are not re-delivered as new prompts)

🤖 Generated with Claude Code

geoffjay and others added 2 commits March 19, 2026 23:14
- Add warning admonition to install.md explaining CLI defaults to
  production ports (7xxx); `source .env` needed for dev ports
- Update port reference tables in getting-started.md and install.md
  to include agentd-communicate (17010/7010) and agentd-memory (7008)
- Add troubleshooting entry for "agent status shows services as down"
  with workaround and reference to issue #536
- Fix install.md troubleshooting to use production ports (7xxx) for
  installed services rather than dev ports (17xxx)

Refs #536

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Two fixes for the message duplication bug (#534) where each room message
was delivered 4-5x to agents, creating a compounding echo loop:

1. Communicate WebSocket (websocket.rs): Abort the old subscription task
   before replacing it in the HashMap when a client resubscribes to a
   room. Previously, the old task was silently orphaned and continued
   forwarding messages, causing duplicate deliveries after reconnection.

2. Orchestrator MessageBridge (message_bridge.rs): Add a seen-message
   deduplication set that tracks recently processed message IDs. Messages
   already seen are skipped before delivery to agents. The set is capped
   at 1000 entries to bound memory usage.

Closes #534

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@geoffjay geoffjay added the bug Something isn't working label Mar 20, 2026
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 20, 2026

Codecov Report

❌ Patch coverage is 55.55556% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 55.36%. Comparing base (be8de55) to head (6f9af5b).

Files with missing lines Patch % Lines
crates/orchestrator/src/message_bridge.rs 57.14% 3 Missing ⚠️
crates/communicate/src/websocket.rs 50.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #539      +/-   ##
==========================================
- Coverage   55.36%   55.36%   -0.01%     
==========================================
  Files         126      126              
  Lines       13505    13513       +8     
==========================================
+ Hits         7477     7481       +4     
- Misses       6028     6032       +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@geoffjay
Copy link
Copy Markdown
Owner Author

pretty sure this is a duplicate from multiple work streams trying to fix the same problem. need to confirm then close.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(communicate): deduplicate message delivery to agents via MessageBridge

1 participant