feat(gateway): inbound message debounce to merge rapid messages into one turn - #2484
feat(gateway): inbound message debounce to merge rapid messages into one turn#2484teyrebaz33 wants to merge 2 commits into
Conversation
…one turn Adds configurable inbound_debounce_ms to GatewayConfig. When set, rapid consecutive text messages from the same sender are buffered and merged into a single agent turn after the debounce window expires. Fixes Discord auto-split messages and rapid-fire corrections being processed as separate agent turns — reducing API costs and improving context coherence. Implementation: - GatewayConfig.inbound_debounce_ms (default 0 = disabled) - Loaded from config.yaml inbound_debounce_ms key - GatewayRunner._debounce_tasks / _debounce_buffers per session - _flush_debounce_buffer(): merges buffered events, dispatches once - Only applies to TEXT messages; photo/voice pass through immediately - Only when no agent is running (priority interrupt path takes precedence) - Debounce tasks cancelled on /new, /reset, and gateway shutdown Usage: inbound_debounce_ms: 3000 # in config.yaml Closes NousResearch#2434
…ntiation in tests
|
I tested this PR locally and can confirm it solves a real issue I encountered. Problem: When sending multiple messages in quick succession (before the agent finishes responding to the first), the gateway queues the second message and signals an interrupt to the running agent. However, the agent pivots to the new message without completing the first response. The first question is abandoned mid-task. Example flow:
What this PR does: Buffers rapid messages and merges them into a single turn: Testing: I ran the test suite locally — all 10 tests pass: Issue with PR: The branch appears to be based on an outdated main. Git diff shows -4,507 lines including deleted test files that exist in current main. Rebase needed: git fetch origin main
git rebase origin/main
git push --force-with-leaseThis feature is valuable for multi-message workflows on messaging platforms. The implementation is clean — config-driven, backward compatible (disabled by default), and limited to text messages (photos/voice pass through immediately). |
|
Thanks for the patch @teyrebaz33 — closing as superseded. The same capability already landed on
Key differences from this PR:
Closing #2434 in parallel. Appreciate the clean implementation — apologies we didn't catch this overlap sooner. |
Closes #2434
Problem
Discord auto-splits messages >2000 chars into multiple rapid-fire updates. Each fragment triggers a separate agent turn — causing fragmented responses, wasted API calls, and lost context.
Solution
Configurable
inbound_debounce_msthat buffers rapid consecutive text messages from the same sender and merges them into a single turn after the window expires.Implementation
GatewayConfig.inbound_debounce_ms(default 0 = disabled, backward compatible)GatewayRunner._debounce_tasks/_debounce_buffers— per session key_flush_debounce_buffer()— merges event texts with newline, dispatches once/new,/reset, and gateway shutdownNot included (V2)
Per-platform config (
discord.debounce_ms,telegram.debounce_ms) — global setting covers the main use case.