#6518: feat(matrix): add inbound message debouncing
channel: matrix
Cluster:
Messaging Platform Improvements
## 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
#15467: feat(messages): add debounceMedia option for inbound debouncing
by tangcruz · 2026-02-13
75.6%
#18718: matrix: add pending group history context for room messages
by pharasyte · 2026-02-17
75.0%
#13057: feat(matrix): add sessionScope=room to route sessions by roomId
by spengrah · 2026-02-10
71.6%
#17435: fix(debounce): retry flush with exponential backoff to prevent sile...
by widingmarcus-cyber · 2026-02-15
71.5%
#19981: feat(matrix): enable block streaming
by alberthild · 2026-02-18
71.3%
#13013: feat(matrix): multi account support
by ti · 2026-02-10
70.8%
#13451: feat(matrix): add forceRoomRouting to bypass DM detection for allow...
by yamoroc · 2026-02-10
70.7%
#20969: Add DeJoy channel extension (Matrix-compatible protocol)
by web3km · 2026-02-19
70.6%
#13832: feat(matrix): add sessionScope and thread-scoped inbound sessions
by yamoroc · 2026-02-11
70.5%
#8166: fix(telegram): lifecycle fixes for duplicate messages and auto-reco...
by cheenu1092-oss · 2026-02-03
69.3%