Skip to content

Conversation

@rodrigok
Copy link
Member

@rodrigok rodrigok commented Oct 8, 2025

https://rocketchat.atlassian.net/browse/FDR-215

Proposed changes (including videos or screenshots)

Issue(s)

Steps to test or reproduce

Further comments

Summary by CodeRabbit

  • New Features
    • Improved handling of native federated rooms: display names may include MRID suffix, and URL slugs align with discussions/native federated rules.
  • Bug Fixes
    • Corrected slug generation and display name updates for native federated rooms to ensure consistent naming.
  • Security/Permissions
    • Only local users can rename rooms, change topics, or modify room-scoped roles; federated users are blocked from these actions.
  • Refactor
    • Standardized internal user identifier handling for more consistent behavior across federation-related actions.

Copilot AI review requested due to automatic review settings October 8, 2025 21:08
@dionisio-bot
Copy link
Contributor

dionisio-bot bot commented Oct 8, 2025

Looks like this PR is not ready to merge, because of the following issues:

  • This PR is missing the 'stat: QA assured' label

Please fix the issues and try again

If you have any trouble, please check the PR guidelines

@changeset-bot
Copy link

changeset-bot bot commented Oct 8, 2025

⚠️ No Changeset found

Latest commit: 7718345

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

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 fixes an issue with duplicated federation events for room power levels, name, and topic changes by preventing federated users from making changes that would cause event loops between Matrix homeservers.

  • Adds early return checks to prevent federated users from updating room names, topics, and user roles
  • Updates room name handling to use native federation type checking and append federation identifiers
  • Reorders code logic to check user permissions before processing federation actions

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/FederationMatrix.ts Adds federated user checks to prevent duplicate events in room operations
apps/meteor/app/channel-settings/server/functions/saveRoomName.ts Updates federation type checking and room name formatting for federated rooms

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

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 8, 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

Adjusts room-renaming logic for native federated rooms to append MRID to display names and to route updates via isRoomNativeFederated checks. In FederationMatrix, adds early-return guards preventing federated (non-local) users from renaming rooms, changing topics, or modifying room-scoped roles; standardizes local-style sender identifiers.

Changes

Cohort / File(s) Summary of changes
Channel name handling (native federation)
apps/meteor/app/channel-settings/server/functions/saveRoomName.ts
Switches checks from isRoomFederated to isRoomNativeFederated; appends MRID to displayName for native federated rooms; adjusts slugified name selection for discussions/native federated; updates branching to call updateFName vs updateRoomName using native-federation check.
FederationMatrix guards & local identifier use
ee/packages/federation-matrix/src/FederationMatrix.ts
Adds guards to block non-local users from updateRoomName and updateRoomTopic; enforces sender validation and early return for federated senders in addUserRoleRoomScoped; standardizes deriving local-style MUI for allowed operations; removes redundant MUI derivations.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor User
  participant Client
  participant Server as RC Server
  participant Save as saveRoomName.ts
  participant Fed as FederationMatrix

  User->>Client: Rename/Topic/Role change action
  Client->>Server: Request (roomId, userId, payload)
  Server->>Save: saveRoomName(...)
  Note over Save: Determine isDiscussion / isRoomNativeFederated
  Save->>Save: Build displayName (+MRID if native federated)
  Save->>Save: Choose slug (discussion or native federated)
  alt Native federated
    Save->>Fed: updateFName / federated pathway
  else Non-federated
    Save->>Fed: updateRoomName / non-federated pathway
  end

  Note over Fed: New guards for non-local senders
  Fed->>Fed: If sender is federated → log + return
  Fed->>Fed: Else compute local-style MUI and proceed
  Fed-->>Server: Result (ok or no-op)
  Server-->>Client: Response
Loading
sequenceDiagram
  autonumber
  participant Client
  participant Server
  participant Fed as FederationMatrix

  rect rgba(230,245,255,0.6)
  note right of Fed: Changed control flow
  Client->>Server: updateRoomTopic / addUserRoleRoomScoped
  Server->>Fed: Call method
  alt Sender is federated (non-local)
    Fed->>Fed: Log debug
    Fed-->>Server: Early return (no change)
  else Sender is local
    Fed->>Fed: Derive local-style MUI
    Fed->>Fed: Apply topic/role update
    Fed-->>Server: Success
  end
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested labels

stat: ready to merge, stat: QA assured

Suggested reviewers

  • ricardogarim
  • ggazzo

Poem

I nibble names with careful cheer,
Add MRIDs so paths are clear.
If you roam from distant warren—halt!
Local paws must lead the vault.
Topics, roles, hop in line—
Federation flows, now crisp, now fine. 🥕🐇

Pre-merge checks and finishing touches

❌ Failed checks (3 warnings)
Check name Status Explanation Resolution
Linked Issues Check ⚠️ Warning The linked issue FDR-215 focuses on restoring message delivery after a channel rename by a federated user, but the changes only address deduplicating federation events for room power_levels, name, and topic without modifying the message synchronization logic or verifying message receipt post-rename. Include or update code that specifically ensures message synchronization continues after channel renames and add tests to verify federated message delivery is restored under the FDR-215 scenario.
Out of Scope Changes Check ⚠️ Warning The changes to saveRoomName.ts that add MRID suffix handling and adjust slugified name logic for native federated rooms do not relate to fixing duplicated federation events or message delivery issues outlined in the linked FDR-215 issue, indicating these modifications fall outside the stated objectives. Remove or relocate the MRID suffix and slugification adjustments into a separate pull request that explicitly targets slug handling for native federated rooms and keep this PR focused solely on deduplicating federation events.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title succinctly describes the primary fix in the PR by referencing the duplication of room power_levels, name, and topic events within the federation context, which aligns with the main changes to guard against duplicated update events.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/federation-event-duplication

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

@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 df117e7 and 7718345.

📒 Files selected for processing (2)
  • apps/meteor/app/channel-settings/server/functions/saveRoomName.ts (3 hunks)
  • ee/packages/federation-matrix/src/FederationMatrix.ts (3 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
ee/packages/federation-matrix/src/FederationMatrix.ts (1)
packages/core-typings/src/IUser.ts (1)
  • isUserNativeFederated (276-277)
apps/meteor/app/channel-settings/server/functions/saveRoomName.ts (2)
packages/core-typings/src/IRoom.ts (1)
  • isRoomNativeFederated (124-125)
apps/meteor/server/services/room/service.ts (1)
  • getValidRoomName (84-86)
⏰ 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). (1)
  • GitHub Check: CodeQL-Build
🔇 Additional comments (6)
apps/meteor/app/channel-settings/server/functions/saveRoomName.ts (2)

3-3: LGTM! Import change aligns with native federation handling.

The switch from isRoomFederated to isRoomNativeFederated correctly narrows the check to rooms with the federation metadata object, which aligns with the changes that append MRID information.


80-80: Ignore undefined displayName concern: For federated rooms, displayName is reassigned to a string before the trim check; otherwise, the !displayName?.trim() guard returns early—so at the slugifiedRoomName assignment it’s always a defined, non-empty string.

Likely an incorrect or invalid review comment.

ee/packages/federation-matrix/src/FederationMatrix.ts (4)

841-846: LGTM! Guard prevents federated users from renaming rooms.

This guard correctly prevents non-local (federated) users from triggering room rename events, which addresses the duplicate federation events issue described in the PR objectives. The local-only userMui construction on line 846 is now safe because the guard ensures only local users reach that line.


862-867: LGTM! Guard prevents federated users from changing room topics.

Similar to the room rename guard, this correctly prevents federated users from triggering topic change events, reducing duplicate federation synchronization issues. The userMui is correctly constructed for local users only.


887-897: LGTM! Sender validation prevents federated users from changing roles.

The guard at lines 892-895 correctly blocks federated users from modifying room-scoped roles, preventing duplicate power-level events. The senderMui construction at line 897 is safe because it only executes for local senders.


903-903: Clarification: The past review comment misidentifies the user in this line.

The past review comment suggests simplifying line 903 to always use local format, but this line constructs the MUI for the target user (the user receiving the role change), not the sender. The target user can still be federated (e.g., granting owner rights to a federated user as described in the PR objectives), so the conditional assignment is correct and necessary.

The sender (line 897: senderMui) is already guaranteed to be local by the guard at lines 892-895.

Comment on lines +66 to +68
if (isRoomNativeFederated(room)) {
displayName = `${displayName}:${room.federation.mrid.split(':').pop()}`;
}
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 | 🟠 Major

Handle undefined displayName before string concatenation.

The displayName parameter is typed as string | undefined, but the MRID-appending logic assumes it's defined. Additionally, room.federation.mrid.split(':').pop() can return undefined if the split produces an empty array, resulting in a string with "undefined" concatenated.

Apply this diff to safely handle undefined values:

 	await Room.beforeNameChange(room);
 
 	if (isRoomNativeFederated(room)) {
-		displayName = `${displayName}:${room.federation.mrid.split(':').pop()}`;
+		const serverPart = room.federation.mrid.split(':').pop();
+		if (displayName && serverPart) {
+			displayName = `${displayName}:${serverPart}`;
+		}
 	}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (isRoomNativeFederated(room)) {
displayName = `${displayName}:${room.federation.mrid.split(':').pop()}`;
}
await Room.beforeNameChange(room);
if (isRoomNativeFederated(room)) {
const serverPart = room.federation.mrid.split(':').pop();
if (displayName && serverPart) {
displayName = `${displayName}:${serverPart}`;
}
}
🤖 Prompt for AI Agents
In apps/meteor/app/channel-settings/server/functions/saveRoomName.ts around
lines 66 to 68, the code assumes displayName and the MRID split result are
defined; instead guard against undefined by (1) checking displayName is a
non-empty string before concatenation (return or set a safe fallback like an
empty string if undefined), (2) safely derive the federation part by splitting
room.federation.mrid and selecting the last element only if it exists and is
non-empty (otherwise skip appending), and (3) perform the concatenation only
when both displayName and the federation part are valid to avoid producing
"undefined" in the final string.

@codecov
Copy link

codecov bot commented Oct 8, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 67.42%. Comparing base (df117e7) to head (7718345).
⚠️ 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   #37174   +/-   ##
===============================================
  Coverage           67.41%   67.42%           
===============================================
  Files                3329     3329           
  Lines              113381   113381           
  Branches            20570    20575    +5     
===============================================
+ Hits                76441    76452   +11     
+ Misses              34341    34329   -12     
- Partials             2599     2600    +1     
Flag Coverage Δ
e2e 57.25% <ø> (-0.04%) ⬇️
unit 71.21% <ø> (+0.03%) ⬆️

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.

@ggazzo ggazzo added this to the 7.11.0 milestone Oct 8, 2025
@ggazzo ggazzo merged commit 11e3e0f into release-7.11.0 Oct 8, 2025
20 checks passed
@ggazzo ggazzo deleted the fix/federation-event-duplication branch October 8, 2025 21:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants