Fix race condition causing duplicate message processing
- Add processing_queue flag to prevent concurrent queue processing
- Check processing flag before attempting to process queue
- Cancel and clear flush task when processing begins
- Add proper cleanup in finally block to always reset flag
- Improve shutdown handling to cancel pending tasks
- Process remaining messages on shutdown before exit
Fixes issue where multiple timeout flushes would trigger simultaneously,
causing the same batch of messages to be sent to the agent multiple times.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>