Skip to content

Conversation

@rodrigok
Copy link
Member

@rodrigok rodrigok commented Oct 14, 2025

Proposed changes (including videos or screenshots)

Issue(s)

Steps to test or reproduce

Further comments

Summary by CodeRabbit

  • Bug Fixes
    • Improved reliability when creating group direct messages in federated environments. If inviting one member fails, the process now continues inviting the remaining members.
    • Enhanced per-member error handling and logging to prevent a single failure from interrupting the overall invitation flow.
    • Reduces instances of partially created or stalled group DMs due to individual invite errors.
    • One-on-one direct message behavior remains unchanged.

@rodrigok rodrigok added this to the 7.11.0 milestone Oct 14, 2025
Copilot AI review requested due to automatic review settings October 14, 2025 17:06
@dionisio-bot
Copy link
Contributor

dionisio-bot bot commented Oct 14, 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 14, 2025

⚠️ No Changeset found

Latest commit: 6d2a0ef

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 a bug in DM creation where federation invite messages were being sent twice. The fix involves correcting the placement of a closing brace that was causing the member invitation loop to execute outside of its intended conditional block.

Key changes:

  • Fixed brace placement in the DM creation logic to properly scope the member invitation loop
Comments suppressed due to low confidence (1)

ee/packages/federation-matrix/src/FederationMatrix.ts:1

  • The closing brace was moved to line 337, but this creates a logical issue. The member invitation loop (lines 318-338) should only execute for group DMs, but now it will execute for all DM types. The loop should be properly scoped within the group DM conditional block that starts around line 314.
import { type IFederationMatrixService, ServiceClass } from '@rocket.chat/core-services';

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 14, 2025

Walkthrough

Refactors group DM creation in ee/packages/federation-matrix/src/FederationMatrix.ts by inlining the per-member invitation loop under the group-room path and wrapping each invite in its own try-catch to log per-user errors without aborting the loop. One-on-one DM flow remains unchanged.

Changes

Cohort / File(s) Summary of Changes
Federation Matrix DM invite flow
ee/packages/federation-matrix/src/FederationMatrix.ts
Reorganized group DM invitation control flow: expanded per-member async loop inline and added per-invite try-catch with per-user error logging to avoid halting the overall invitations. 1:1 DM path unchanged.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant Client
  participant FederationMatrix
  participant MatrixServer as Matrix Server
  participant Member as Federated Member(s)

  Client->>FederationMatrix: createDirectMessageRoom(members)
  alt 1-on-1 DM
    FederationMatrix->>MatrixServer: createRoom(1:1)
    MatrixServer-->>FederationMatrix: roomId
    FederationMatrix->>MatrixServer: invite(otherUser)
    MatrixServer-->>FederationMatrix: inviteResult
    FederationMatrix-->>Client: roomId
  else Group DM
    FederationMatrix->>MatrixServer: createRoom(group)
    MatrixServer-->>FederationMatrix: roomId
    loop for each member
      note right of FederationMatrix: try { invite(member) } catch { log(memberError) }
      FederationMatrix->>MatrixServer: invite(member)
      MatrixServer-->>FederationMatrix: inviteResult or error
      FederationMatrix-->>FederationMatrix: log per-user error (non-blocking)
    end
    FederationMatrix-->>Client: roomId
  end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested labels

stat: ready to merge

Suggested reviewers

  • ggazzo
  • ricardogarim

Poem

A rabbit taps the matrix keys with cheer,
Loop by loop, each invite crystal clear.
If one hop slips, we log—don’t fear,
The warren gathers, friends draw near.
Rooms bloom open, ear to ear—
Async thumps across the frontier. 🐇✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Title Check ⚠️ Warning The title claims to fix duplicate DM invites but the changes instead reorganize the per‐member invitation flow and add granular error handling without explicitly addressing a double invite issue, so it does not accurately summarize the main code modifications. Please update the title to reflect the refactored invitation logic and error handling changes or clarify how these modifications resolve the duplicate invite problem.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ 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-dm-creation

📜 Recent 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 4711b48 and 6d2a0ef.

📒 Files selected for processing (1)
  • ee/packages/federation-matrix/src/FederationMatrix.ts (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
ee/packages/federation-matrix/src/FederationMatrix.ts (1)
packages/core-typings/src/IUser.ts (1)
  • isUserNativeFederated (276-277)
⏰ 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). (3)
  • GitHub Check: 📦 Build Packages
  • GitHub Check: CodeQL-Build
  • GitHub Check: CodeQL-Build
🔇 Additional comments (1)
ee/packages/federation-matrix/src/FederationMatrix.ts (1)

318-336: Update error log and confirm duplicate-invite fix

  • Replace the catch message in createDirectMessageRoom with:
    } catch (error) {
    -   this.logger.error('Error creating or updating bridged user for DM:', error);
    +   this.logger.error('Failed to invite user to group DM:', error);
    }
  • The manual for-await loop no longer calls inviteUsersToRoom, so the “sending invite twice” issue is resolved.

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.

@codecov
Copy link

codecov bot commented Oct 14, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 66.36%. Comparing base (4711b48) to head (6d2a0ef).
⚠️ 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   #37222      +/-   ##
==================================================
- Coverage           66.39%   66.36%   -0.03%     
==================================================
  Files                3386     3386              
  Lines              115618   115618              
  Branches            21352    21356       +4     
==================================================
- Hits                76765    76733      -32     
- Misses              36251    36279      +28     
- Partials             2602     2606       +4     
Flag Coverage Δ
e2e 57.23% <ø> (-0.10%) ⬇️
unit 71.23% <ø> (-0.02%) ⬇️

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 the stat: QA assured Means it has been tested and approved by a company insider label Oct 14, 2025
@dionisio-bot dionisio-bot bot added the stat: ready to merge PR tested and approved waiting for merge label Oct 14, 2025
@kodiakhq kodiakhq bot merged commit 34cbb6b into release-7.11.0 Oct 14, 2025
79 of 81 checks passed
@kodiakhq kodiakhq bot deleted the fix/federation-dm-creation branch October 14, 2025 21:39
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