Skip to content

fix: Clean up acknowledged messages in message routing loop#342

Open
aronchick wants to merge 1 commit intodlorenc:mainfrom
aronchick:work/zealous-rabbit
Open

fix: Clean up acknowledged messages in message routing loop#342
aronchick wants to merge 1 commit intodlorenc:mainfrom
aronchick:work/zealous-rabbit

Conversation

@aronchick
Copy link
Contributor

Problem

Messages were piling up in the filesystem because acknowledged messages were never deleted. The messages.Manager had a DeleteAcked() method, but it was never called by the daemon's message routing loop.

Evidence:

  • 128 message files accumulated in production
  • 17 acked messages that should have been deleted
  • 111 delivered messages never acknowledged

Root Cause

The messageRouterLoop delivered messages and marked them as "delivered", but had no cleanup mechanism. The DeleteAcked() method existed but was only used in tests.

Solution

Added automatic cleanup of acknowledged messages to the routeMessages() function in internal/daemon/daemon.go:423-429. After delivering pending messages to each agent, the loop now calls DeleteAcked() to remove any messages that have been acknowledged.

The cleanup:

  • Runs every 2 minutes as part of the normal message routing cycle
  • Only deletes messages with status "acked"
  • Logs cleanup activity at debug level for visibility
  • Handles errors gracefully without disrupting message delivery

Testing

  • ✅ Added TestMessageRoutingCleansUpAckedMessages to verify cleanup works
  • ✅ All existing daemon tests pass (9.9s)
  • ✅ Full test suite passes (71s for CLI tests)
  • ✅ Verified in production: 17 acked messages cleaned up after daemon restart

Files Changed

  • internal/daemon/daemon.go - Added cleanup call in routeMessages() (8 lines)
  • internal/daemon/daemon_test.go - Added test for message cleanup (76 lines)

Impact

  • ✅ Prevents unbounded growth of message files
  • ✅ Reduces filesystem clutter
  • ✅ Makes the message system more reliable
  • ✅ No breaking changes to message API or behavior

Future Opportunities

While this PR fixes the acked message accumulation, there are still 111 delivered messages that were never acknowledged. These could be addressed in a future PR by:

  • Adding automatic cleanup of old delivered messages (e.g., >24 hours old)
  • Improving agent message acknowledgment workflow
  • Adding metrics for message queue health

🤖 Generated with Claude Code

## Problem Messages were piling up in the filesystem because acknowledged messages were never deleted. The messages.Manager had a DeleteAcked() method, but it was never called by the daemon's message routing loop. Evidence: - 128 message files accumulated in production - 17 acked messages that should have been deleted - 111 delivered messages never acknowledged ## Root Cause The messageRouterLoop delivered messages and marked them as "delivered", but had no cleanup mechanism. The DeleteAcked() method existed but was only used in tests. ## Solution Added automatic cleanup of acknowledged messages to the routeMessages() function. After delivering pending messages to each agent, the loop now calls DeleteAcked() to remove any messages that have been acknowledged. The cleanup: - Runs every 2 minutes as part of the normal message routing cycle - Only deletes messages with status "acked" - Logs cleanup activity at debug level for visibility - Handles errors gracefully without disrupting message delivery ## Testing - Added TestMessageRoutingCleansUpAckedMessages to verify cleanup works - All existing daemon tests pass - Verified in production: 17 acked messages cleaned up after daemon restart ## Impact - Prevents unbounded growth of message files - Reduces filesystem clutter - Makes the message system more reliable - No breaking changes to message API or behavior Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@aronchick
Copy link
Contributor Author

Merge Queue: READY TO MERGE

  • CI: All 6 checks passing
  • Merge status: Checking...
  • Size: +84 additions, 2 files
  • Purpose: Fix message routing loop cleanup (addresses piling message queue issue)

This PR is ready for maintainer merge.

whitmo added a commit to whitmo/multiclaude that referenced this pull request Feb 28, 2026
whitmo added a commit to whitmo/multiclaude that referenced this pull request Feb 28, 2026
…nc#336, dlorenc#340, dlorenc#342 Add 659 lines of tests covering: - All 18 structured error constructors from PR dlorenc#340 (individual + bulk format test) - JSON CLI output edge cases from PR dlorenc#335 (empty/nested/all-internal subcommands) - Structured CLIError validation for workspace names from PR dlorenc#340 integration - Message routing edge cases from PR dlorenc#342 (no acked, mixed ack status) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
whitmo added a commit to whitmo/multiclaude that referenced this pull request Mar 1, 2026
whitmo added a commit to whitmo/multiclaude that referenced this pull request Mar 1, 2026
…nc#336, dlorenc#340, dlorenc#342 Add 659 lines of tests covering: - All 18 structured error constructors from PR dlorenc#340 (individual + bulk format test) - JSON CLI output edge cases from PR dlorenc#335 (empty/nested/all-internal subcommands) - Structured CLIError validation for workspace names from PR dlorenc#340 integration - Message routing edge cases from PR dlorenc#342 (no acked, mixed ack status) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant