Skip to content

Conversation

@sampaiodiego
Copy link
Member

@sampaiodiego sampaiodiego commented Oct 1, 2025

Proposed changes (including videos or screenshots)

Issue(s)

FDR-181

Steps to test or reproduce

Further comments

Summary by CodeRabbit

  • Bug Fixes
    • Activity notifications are now confined to the current server instance, reducing cross-instance noise and improving real-time feedback in rooms.
    • Typing indicators in federated Matrix rooms now use the correct user identifier, preventing phantom typing events and improving bridge consistency.

@sampaiodiego sampaiodiego requested a review from a team as a code owner October 1, 2025 20:13
Copilot AI review requested due to automatic review settings October 1, 2025 20:13
@dionisio-bot
Copy link
Contributor

dionisio-bot bot commented Oct 1, 2025

Looks like this PR is ready to merge! 🎉
If you have any trouble, please check the PR guidelines

@changeset-bot
Copy link

changeset-bot bot commented Oct 1, 2025

⚠️ No Changeset found

Latest commit: 04eb044

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 1, 2025

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Walkthrough

Restricts user-activity notifications to the local instance and simplifies federation typing handling by using the incoming Matrix user_id directly, removing a bridged-user lookup. No public API changes.

Changes

Cohort / File(s) Summary
User activity notification scoping
apps/meteor/server/modules/listeners/listeners.module.ts
Replaced notifyRoom with notifyRoomInThisInstance for the user.activity handler, keeping the same arguments to confine notifications to the current instance.
Federation typing payload adjustment
ee/packages/federation-matrix/src/events/edu.ts
Removed Users.findOne lookup for bridged Matrix user and the username guard; now uses data.user_id directly when broadcasting typing events; presence handling unchanged.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant EB as EventBus
  participant L as UserActivityListener
  participant N as Notifier
  participant C as RoomClients

  EB->>L: "user.activity"(roomId, user, isTyping)
  rect rgb(230,245,255)
  note right of L: Changed — notify only current instance
  L->>N: notifyRoomInThisInstance(roomId, 'user-activity', user, tags)
  end
  N-->>C: deliver event locally
Loading
sequenceDiagram
  autonumber
  participant MX as MatrixEDU
  participant H as EduHandler
  participant B as TypingBroadcaster
  participant RC as RCClients

  MX->>H: typing { user_id, room_id, typing }
  rect rgb(240,255,240)
  note right of H: Changed — use incoming data.user_id directly
  H->>B: broadcastTyping(room_id, user_id, typing)
  end
  B-->>RC: typing indicator update
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • MartinSchoeler

Poem

I twitch my whiskers, ears alert,
Local pings now stay inert,
Matrix names no longer chased,
Typing signs show just the place.
Hop, thump—this rabbit’s mildly pleased. 🐇✨

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title clearly summarizes the primary change by indicating a regression fix in the native-federation typing loop between instances, matching the PR’s main objective of resolving the typing indicator loop in federated chats.
Linked Issues Check ✅ Passed The changes adjust the notification path to restrict events to the current instance, preventing typing loops, and update the typing event payload to use the correct remote user identifier, which directly addresses preventing self-typing indicators and stabilizing remote typing display as described in FDR-181.
Out of Scope Changes Check ✅ Passed All modifications are focused on federation typing and user activity handling, specifically within the listeners and matrix EDU event modules, and there are no unrelated or extraneous changes outside the linked issue’s scope.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-federation-typing

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR addresses a typing loop issue in the native federation system by modifying the user activity notification mechanism. The fix prevents infinite loops by changing how typing notifications are broadcasted between federated instances.

Key changes:

  • Modified user activity event to use Matrix user ID directly instead of looking up local username
  • Changed notification method to restrict broadcasting to current instance only

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
ee/packages/federation-matrix/src/events/edu.ts Removed Matrix user lookup and uses raw user_id for activity events
apps/meteor/server/modules/listeners/listeners.module.ts Changed notification method to instance-specific broadcasting

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

return;
}

const matrixUser = await Users.findOne({ 'federation.mui': data.user_id });
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this find was useless since data.user_id is the same as matrixUser.username .. we also don't need to check if it exists since this comes from homeserver which already has done validations

@sampaiodiego sampaiodiego added the stat: QA assured Means it has been tested and approved by a company insider label Oct 1, 2025
@sampaiodiego sampaiodiego added this to the 7.11.0 milestone Oct 1, 2025
@dionisio-bot dionisio-bot bot added the stat: ready to merge PR tested and approved waiting for merge label Oct 1, 2025
@codecov
Copy link

codecov bot commented Oct 1, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 67.37%. Comparing base (ec81ab4) to head (04eb044).
⚠️ Report is 1 commits behind head on release-7.11.0.

Additional details and impacted files

Impacted file tree graph

@@                Coverage Diff                 @@
##           release-7.11.0   #37115      +/-   ##
==================================================
- Coverage           67.39%   67.37%   -0.02%     
==================================================
  Files                3328     3328              
  Lines              113353   113353              
  Branches            20565    20564       -1     
==================================================
- Hits                76389    76368      -21     
- Misses              34359    34383      +24     
+ Partials             2605     2602       -3     
Flag Coverage Δ
unit 71.12% <ø> (-0.04%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@sampaiodiego sampaiodiego force-pushed the fix-federation-typing branch from 03cf03a to 04eb044 Compare October 1, 2025 21:56
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Jira integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 03cf03a and 04eb044.

📒 Files selected for processing (2)
  • apps/meteor/server/modules/listeners/listeners.module.ts (1 hunks)
  • ee/packages/federation-matrix/src/events/edu.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/meteor/server/modules/listeners/listeners.module.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: 📦 Build Packages
  • GitHub Check: Builds matrix rust bindings against alpine
  • GitHub Check: CodeQL-Build
  • GitHub Check: CodeQL-Build
🔇 Additional comments (1)
ee/packages/federation-matrix/src/events/edu.ts (1)

33-82: Presence handler looks correct.

The presence event handler properly validates that the user exists and is federated before processing, maps Matrix presence states to Rocket.Chat statuses, avoids redundant updates, and includes appropriate error handling.

Comment on lines 23 to 27
void api.broadcast('user.activity', {
user: matrixUser.username,
user: data.user_id,
isTyping: data.typing,
roomId: matrixRoom._id,
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

Verify downstream consumers and local user filtering.

The typing handler now uses data.user_id directly without validating that the user exists or is federated, unlike the presence handler (lines 39-48) which performs these checks. This raises two concerns:

  1. Inconsistent validation pattern: The presence handler validates the user is federated before processing, but typing does not. If Matrix sends typing events for local users back to the local instance, this could cause the self-typing issue described in the PR objectives.

  2. Downstream consumer compatibility: The previous code used matrixUser.username (a local username), now it uses data.user_id (a Matrix user ID). Verify that consumers of the user.activity broadcast can handle Matrix user ID format.

Run the following script to check how user.activity events are consumed:

Additionally, clarify:

  • Does the Matrix homeserver send typing events for local users back to the local instance, or only for remote users?
  • Is the filtering of local users handled by the notifyRoomInThisInstance change mentioned in the AI summary?

🏁 Script executed:

#!/bin/bash
# Find all consumers of 'user.activity' broadcast events
rg -n -C5 "on\('user\.activity'" --type=ts --type=js

# Also search for any user.activity string references
rg -n -C3 "'user\.activity'|\"user\.activity\"" --type=ts --type=js

Length of output: 1732


🏁 Script executed:

#!/bin/bash
set -e
# Show context around the onEvent handler in listeners.module.ts
sed -n '150,230p' apps/meteor/server/modules/listeners/listeners.module.ts

# Find import of notifications
grep -R "import .*notifications" -n apps/meteor/server/modules/listeners/listeners.module.ts

# Search for definition of notifyRoomInThisInstance
rg -n "notifyRoomInThisInstance" -C5 apps/meteor/server/modules

Length of output: 9073


Restore user validation and map data.user_id to a local user ID before broadcasting (ee/packages/federation-matrix/src/events/edu.ts L23-27)
The presence handler still looks up and validates the federated user before emitting, but the typing handler now sends the raw Matrix user ID—downstream consumers rely on internal user IDs to filter out self-typing and drive UI logic correctly.

🤖 Prompt for AI Agents
In ee/packages/federation-matrix/src/events/edu.ts around lines 23–27, the
typing handler currently broadcasts the raw Matrix user ID; restore the
federated-user lookup/validation used in the presence handler and map
data.user_id to the local user record before broadcasting. Specifically,
fetch/validate the local user (using the same helper used by presence, e.g. the
federated user lookup), bail out if the federated user is not found/invalid, and
pass user: localUser._id (not data.user_id) in the api.broadcast payload; keep
existing error handling/logging when lookup fails.

@ggazzo ggazzo merged commit 0fa06e5 into release-7.11.0 Oct 1, 2025
32 of 34 checks passed
@ggazzo ggazzo deleted the fix-federation-typing branch October 1, 2025 23:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stat: QA assured Means it has been tested and approved by a company insider stat: ready to merge PR tested and approved waiting for merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants