fix(matrix): prevent echo loop by using /whoami user_id for self-message filtering#760
Open
sliverp wants to merge 1 commit intoRightNow-AI:mainfrom
Open
fix(matrix): prevent echo loop by using /whoami user_id for self-message filtering#760sliverp wants to merge 1 commit intoRightNow-AI:mainfrom
sliverp wants to merge 1 commit intoRightNow-AI:mainfrom
Conversation
…age filtering The Matrix adapter used the config-provided user_id for echo filtering instead of the server-validated identity from /whoami. When these differ (wrong casing, empty config, different homeserver), the bot processes its own messages and enters an infinite reply loop. Changes: - Use validated /whoami user_id for the echo guard instead of config value - Warn when config user_id diverges from server-reported identity - Generate unique txn_id per message chunk (fixes silent drop of multi-chunk messages due to Matrix PUT idempotency deduplication) - Add tests for empty user_id handling, echo filter semantics, and txn_id uniqueness Closes RightNow-AI#757
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #757 — Matrix bot gets stuck in an infinite echo loop.
Root Cause
The Matrix adapter's echo guard compared incoming message senders against the config-provided
user_idinstead of the server-validated identity from/whoami. When these differ (wrong casing, empty config value, different homeserver), the bot fails to recognize its own messages and replies to them indefinitely.Changes
1. Echo guard: use server-validated user_id (primary fix)
start()now uses the/whoami-validated user identity for echo filtering instead ofself.user_iduser_iddiverges from the server-reported value2. Fix txn_id reuse across message chunks
uuid::Uuid::new_v4()generation inside the chunk loop inapi_send_message()txn_idwas generated once and reused for all chunks — Matrix's PUT idempotency silently dropped all chunks after the first3. Tests
test_matrix_adapter_empty_user_id: empty config user_id doesn't panic on constructiontest_sender_echo_filter_semantics: case-sensitive exact match verification for the echo guardtest_txn_id_uniqueness: UUID uniqueness across message chunksTesting
All existing tests pass. New tests cover the specific failure modes that caused #757.