Skip to content

Conversation

@ggazzo
Copy link
Member

@ggazzo ggazzo commented Oct 10, 2025

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

  • Updated handleThreadedMessage and handleQuoteMessage methods to improve message processing.
  • Consolidated logic for replying to messages, ensuring proper handling of threaded and quoted messages.
  • Added error handling for missing event IDs and improved logging for message processing failures.

Proposed changes (including videos or screenshots)

Issue(s)

Steps to test or reproduce

Further comments

Summary by CodeRabbit

  • Bug Fixes

    • Improved reliability of threaded and quoted replies, ensuring replies target the correct message or latest thread message.
    • Prevents unexpected errors when thread data is absent and provides clearer errors when a thread root cannot be found.
    • Streamlined handling of text, file, and media messages so thread and quote context is preserved consistently.
  • Chores

    • Updated federation SDK version to improve overall stability.

@dionisio-bot
Copy link
Contributor

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

⚠️ No Changeset found

Latest commit: 37006c3

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

@ggazzo ggazzo force-pushed the regression/upload-fed branch from 7a55879 to dffa7ae Compare October 10, 2025 15:39
@coderabbitai
Copy link
Contributor

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

Unifies thread and quote handling for Matrix federation messages, updating control flow in FederationMatrix and events/message to compute reply targets upfront. Adjusts media handling to pass a thread object instead of tmid. Bumps @rocket.chat/federation-sdk from 0.1.25 to 0.1.26 in two package.json files.

Changes

Cohort / File(s) Summary of Changes
Federation flow: unified thread/quote handling
ee/packages/federation-matrix/src/FederationMatrix.ts
Centralizes computation of replyToMessage and quoteMessage for text/file sends. Revises handleThreadedMessage return shape and error paths; handleQuoteMessage now returns { replyToEventId } and early-returns when no quote. Updates downstream to use a single eventToReplyTo.
Events: media message thread metadata shape
ee/packages/federation-matrix/src/events/message.ts
Changes handleMediaMessage signature to accept/return thread?: { tmid: string; tshow: boolean } instead of tmid?: string. Updates call sites and save payload to propagate thread object.
Dependency bump: federation SDK
ee/packages/federation-matrix/package.json, packages/core-services/package.json
Updates dependency @rocket.chat/federation-sdk from 0.1.25 to 0.1.26.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor User
  participant Client
  participant FederationMatrix
  participant EventsMessage
  participant MatrixServer as Matrix Server

  User->>Client: Send message (text/file) with thread/quote
  Client->>FederationMatrix: handleTextMessage/handleFileMessage(payload)
  rect rgba(230,245,255,0.6)
    note right of FederationMatrix: Resolve reply context
    FederationMatrix->>FederationMatrix: getQuoteMessage(...) => quoteMessage?
    FederationMatrix->>FederationMatrix: handleThreadedMessage(thread?, quote?)<br/>=> { threadEventId, replyToEventId | latestThreadEventId }?
    FederationMatrix->>FederationMatrix: Compute eventToReplyTo (unified)
  end
  alt File message
    FederationMatrix->>EventsMessage: handleMediaMessage(..., thread?)
    EventsMessage-->>FederationMatrix: { ..., attachments, thread? }
  else Text message
    FederationMatrix->>MatrixServer: send message with eventToReplyTo/threadEventId
  end
  MatrixServer-->>FederationMatrix: federation_event_id
  FederationMatrix-->>Client: success or error

  %% Error paths
  rect rgba(255,235,230,0.6)
    note over FederationMatrix: Throws if thread root event ID missing<br/>or no event to reply to when required
  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
  • rodrigok

Poem

In threads I hop, attachments tight,
No more strays into the timeline night—
A federated burrow for each reply,
Quotes and roots aligned just right.
Thump-thump! goes CI, green and bright.
(\/) 🧵
(•
•) 📎

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
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 (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title succinctly identifies the core fix—restoring image uploads within federated threads—using the established “regression(federation)” prefix and clearly conveys the primary change without extraneous detail.
Linked Issues Check ✅ Passed The changes replace the legacy tmid parameter with a full thread object and update handleFileMessage and handleMediaMessage flows to carry thread metadata through to federation send and persistence, ensuring that attachments uploaded in a federated thread are sent with the correct threadEventId and preserved on external homeservers as nested messages rather than standalone posts.
Out of Scope Changes Check ✅ Passed All modifications are confined to the federation-matrix package and its media message flow, including the dependency bump, unified thread metadata handling, and related error paths, with no unrelated feature code introduced outside the scope of ensuring threaded file uploads are delivered correctly across homeservers.
✨ 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 regression/upload-fed

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.

@ggazzo ggazzo added this to the 7.11.0 milestone Oct 10, 2025
Copy link
Contributor

@ricardogarim ricardogarim left a comment

Choose a reason for hiding this comment

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

code lgtm! however, during testing i noticed a case where files sent from remote threads appear as regular messages on the RC side. all other use cases worked as expected.

@ggazzo
Copy link
Member Author

ggazzo commented Oct 10, 2025

code lgtm! however, during testing i noticed a case where files sent from remote threads appear as regular messages on the RC side. all other use cases worked as expected.

this is not what I was trying to solve, but since you raised it... solved

@ggazzo ggazzo marked this pull request as ready for review October 10, 2025 23:04
Copilot AI review requested due to automatic review settings October 10, 2025 23:04
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 regression in federation where images were not being properly uploaded on threads. The change consolidates message processing logic to ensure proper handling of both threaded and quoted messages.

  • Updated federation SDK version from 0.1.23 to 0.1.24
  • Refactored message handling methods to return reply metadata instead of directly sending messages
  • Changed thread parameter structure from simple string to object with tmid and tshow properties

Reviewed Changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated 2 comments.

File Description
packages/core-services/package.json Updated federation SDK dependency to version 0.1.24
ee/packages/federation-matrix/package.json Updated federation SDK dependency to version 0.1.24
ee/packages/federation-matrix/src/events/message.ts Changed thread parameter from string to object structure
ee/packages/federation-matrix/src/FederationMatrix.ts Refactored message handling methods to consolidate reply logic

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

parsedMessage,
userIdSchema.parse(matrixUserId),
);
throw new Error('Thread root event ID not found');
Copy link

Copilot AI Oct 10, 2025

Choose a reason for hiding this comment

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

The error message should be more descriptive and include context about which thread message failed to find its root event ID.

Suggested change
throw new Error('Thread root event ID not found');
throw new Error(`Thread root event ID not found for thread message ID: ${message.tmid}, message ID: ${message._id}, room ID: ${matrixRoomId}`);

Copilot uses AI. Check for mistakes.
: undefined;

if (!quoteMessageEventId && !latestThreadMessage) {
throw new Error('No event to reply to found');
Copy link

Copilot AI Oct 10, 2025

Choose a reason for hiding this comment

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

The error message should be more specific about what type of event was expected (quote or thread) and include the message ID for debugging.

Suggested change
throw new Error('No event to reply to found');
throw new Error(
`No thread or quote event to reply to found for message ID: ${message._id}`
);

Copilot uses AI. Check for mistakes.
ricardogarim
ricardogarim previously approved these changes Oct 10, 2025
…d messages

- Updated `handleThreadedMessage` and `handleQuoteMessage` methods to improve message processing.
- Consolidated logic for replying to messages, ensuring proper handling of threaded and quoted messages.
- Added error handling for missing event IDs and improved logging for message processing failures.
@ggazzo ggazzo force-pushed the regression/upload-fed branch from 0d16a77 to 37006c3 Compare October 11, 2025 12:45
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: 0

♻️ Duplicate comments (1)
ee/packages/federation-matrix/src/FederationMatrix.ts (1)

439-439: Include context in the thrown error.

Please carry the relevant identifiers (message _id, tmid, room/event IDs) into this exception so production logs explain which thread failed to map. That aligns with the earlier review feedback on this spot and makes the incident actionable.

-			throw new Error('Thread root event ID not found');
+			throw new Error(
+				`Thread root event ID not found (messageId=${message._id}, tmid=${message.tmid}, roomId=${matrixRoomId})`,
+			);
🧹 Nitpick comments (1)
ee/packages/federation-matrix/src/FederationMatrix.ts (1)

368-394: Avoid double quote resolution work.

handleThreadedMessage already calls getQuoteMessage, so invoking handleQuoteMessage immediately afterward runs the same DB lookup and formatting twice whenever a threaded reply also carries a quote attachment. Consider caching the quote payload (or threading it through) so you only compute it once per message.

📜 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 0d16a77 and 37006c3.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (4)
  • ee/packages/federation-matrix/package.json (1 hunks)
  • ee/packages/federation-matrix/src/FederationMatrix.ts (3 hunks)
  • ee/packages/federation-matrix/src/events/message.ts (3 hunks)
  • packages/core-services/package.json (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • ee/packages/federation-matrix/src/events/message.ts
  • ee/packages/federation-matrix/package.json
  • packages/core-services/package.json
🧰 Additional context used
🧬 Code graph analysis (1)
ee/packages/federation-matrix/src/FederationMatrix.ts (2)
ee/packages/federation-matrix/src/events/message.ts (1)
  • message (114-410)
packages/core-typings/src/IMessage/IMessage.ts (1)
  • IMessage (138-239)
⏰ 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

@codecov
Copy link

codecov bot commented Oct 11, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 66.36%. Comparing base (f44030f) to head (37006c3).
⚠️ Report is 3 commits behind head on release-7.11.0.

Additional details and impacted files

Impacted file tree graph

@@                Coverage Diff                 @@
##           release-7.11.0   #37201      +/-   ##
==================================================
+ Coverage           65.32%   66.36%   +1.04%     
==================================================
  Files                3141     3386     +245     
  Lines              111835   115618    +3783     
  Branches            20468    21357     +889     
==================================================
+ Hits                73058    76732    +3674     
+ Misses              36431    36278     -153     
- Partials             2346     2608     +262     
Flag Coverage Δ
e2e 57.27% <ø> (+4.48%) ⬆️
unit 71.22% <ø> (+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 merged commit 9ee9679 into release-7.11.0 Oct 11, 2025
18 checks passed
@ggazzo ggazzo deleted the regression/upload-fed branch October 11, 2025 12:58
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