← Back to PRs

#6518: feat(matrix): add inbound message debouncing

by Klowalski open 2026-02-01 19:02 View on GitHub →
channel: matrix
## Summary Add inbound debouncer to Matrix monitor to batch rapid messages from the same sender, matching Telegram's behavior. ## Problem Matrix events are processed immediately without debouncing (issue #6507). When users send multiple rapid messages, each one triggers a separate agent turn, unlike Telegram which batches them together. ## Solution Wrap the Matrix message handler with `createInboundDebouncer` (the same system Telegram uses): - **Debounce key**: `matrix:accountId:roomId:senderId` - **Combines text**: Multiple messages joined with newlines - **Uses last event ID**: For reply targeting - **Skips debouncing for**: Media-only messages and control commands ## Changes - `extensions/matrix/src/matrix/monitor/index.ts`: - Import `MatrixRawEvent`, `RoomMessageEventContent`, and `EventType` from types - Create debouncer using `core.channel.debounce.createInboundDebouncer` - Wrap handler with debouncer before passing to `registerMatrixMonitorEvents` - On flush: combine text, use last event ID, call handler once ## Testing Tested by examining the code structure against Telegram's working implementation. The debouncer pattern is identical to what Telegram and other channels use. ## Related Fixes #6507 --- *Co-authored-by: Klowalski <klowalski@semmy.dev>* *Guided-by: SeMmy <semmy@semmy.dev>* <!-- greptile_comment --> <h2>Greptile Overview</h2> <h3>Greptile Summary</h3> This PR adds inbound message debouncing to the Matrix monitor by wrapping the existing `handleRoomMessage` callback with a `core.channel.debounce.createInboundDebouncer` instance. The debouncer groups rapid `m.room.message` events from the same sender in the same room, concatenates their text bodies with newlines, and then invokes the Matrix room message handler once using a synthetic combined event (with the last event’s `event_id` for reply targeting). Overall this aligns Matrix behavior with other channels (Telegram/MSTeams/Mattermost) that use the shared inbound debounce infrastructure, reducing excess agent turns for message bursts. <h3>Confidence Score: 3/5</h3> - This PR is likely safe to merge, but debouncing correctness depends on the exact `createInboundDebouncer.enqueue()` semantics and Matrix event metadata handling. - The change is localized and follows existing channel patterns, but the wrapper currently enqueues every event (including ones intended to bypass debouncing) which could introduce unintended delays if non-debounced entries aren’t flushed immediately. Also, the synthetic event combines only `body` while mixing first/last event metadata, which can cause reply/thread mismatches in some Matrix message bursts. - extensions/matrix/src/matrix/monitor/index.ts <!-- greptile_other_comments_section --> <sub>(2/5) Greptile learns from your feedback when you react with thumbs up/down!</sub> <!-- /greptile_comment -->

Most Similar PRs