Skip to content

Conversation

@ricardogarim
Copy link
Contributor

@ricardogarim ricardogarim commented Sep 29, 2025

Proposed changes (including videos or screenshots)

Issue(s)

Steps to test or reproduce

Further comments

Summary by CodeRabbit

  • New Features

    • Added a Backfill API endpoint (GET /v1/backfill/:roomId) to retrieve historical room events.
    • Validates required event ID(s) and accepts an optional limit (default 100).
    • Returns standardized responses: 200 with results, 400 when event ID is missing, and 500 for unexpected errors.
  • Chores

    • Bumped federation SDK dependency to v0.1.11.

@dionisio-bot
Copy link
Contributor

dionisio-bot bot commented Sep 29, 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 Sep 29, 2025

⚠️ No Changeset found

Latest commit: a299f3b

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 Sep 29, 2025

Walkthrough

Adds Matrix federation backfill support: AJV schemas/validators and a new GET /v1/backfill/:roomId route that requires v (event ID(s)), accepts optional limit (defaults to 100), calls event.getBackfillEvents(roomId, eventIds, limit), and returns 200/400/500 with federation metadata.

Changes

Cohort / File(s) Summary of Changes
Matrix Federation Backfill API
ee/packages/federation-matrix/src/api/_matrix/transactions.ts
Added BackfillParamsSchema, BackfillQuerySchema, BackfillResponseSchema and validators; added isBackfill* type guards; implemented GET /v1/backfill/:roomId route: validates roomId, requires v (event ID(s)), optional limit (default 100); returns 400 (M_BAD_REQUEST) if v missing, on success calls event.getBackfillEvents(roomId, eventIds, limit) and returns 200 with results, on failure returns 500 (M_UNKNOWN "Failed to get backfill events"); route annotated with Federation license/tag metadata.
Package dependency bumps
ee/apps/federation-service/package.json, ee/packages/federation-matrix/package.json
Bumped @rocket.chat/federation-sdk from 0.1.10 to 0.1.11.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor HS as Remote Homeserver
  participant API as Federation API (/v1/backfill/:roomId)
  participant EV as Event Service

  HS->>API: GET /v1/backfill/{roomId}?v={eventId(s)}&limit={n}
  API->>API: Validate params/query (roomId, v required, limit default 100)
  alt Missing v
    API-->>HS: 400 M_BAD_REQUEST (missing event ID)
  else Valid request
    API->>EV: getBackfillEvents(roomId, eventIds, limit)
    alt Success
      EV-->>API: Backfill events
      API-->>HS: 200 BackfillResponse
    else Failure
      EV-->>API: Error
      API-->>HS: 500 M_UNKNOWN ("Failed to get backfill events")
    end
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

stat: ready to merge, stat: QA assured

Suggested reviewers

  • sampaiodiego

Poem

I hop where old events hide and play,
Nose twitching through the threads of day,
I fetch the echoes, stitch them tight,
Bringing back the past to light.
A rabbit cheers — backfill takes flight! 🐇✨

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 pull request title "feat(federation): implement backfill endpoint" accurately describes the main change in the changeset. The code changes show the addition of a new GET route /v1/backfill/:roomId with supporting schemas, validators, and request handling logic for backfill functionality in the federation-matrix package. The title is concise, clear, and directly reflects the primary objective of adding backfill endpoint support to the federation system.
Linked Issues Check ✅ Passed The linked issue FDR-163 requires implementing a backfill route, and the code changes directly address this requirement. The PR adds a complete backfill endpoint implementation including the GET /v1/backfill/:roomId route with proper schemas (BackfillParamsSchema, BackfillQuerySchema, BackfillResponseSchema), validators, request handling with parameter extraction (roomId, limit, event IDs), error handling (400 for missing event IDs, 500 for failures), and integration with the event.getBackfillEvents service method. The implementation follows the established patterns of other Federation routes and includes all necessary components for a functional backfill endpoint.
Out of Scope Changes Check ✅ Passed The dependency version bumps for @rocket.chat/federation-sdk from 0.1.10 to 0.1.11 in both ee/apps/federation-service/package.json and ee/packages/federation-matrix/package.json appear to be supporting changes related to the backfill endpoint implementation. These dependency updates are likely necessary to support the new backfill functionality or include related federation SDK improvements, making them within the reasonable scope of implementing the backfill endpoint feature. All changes in the PR are directly related to adding backfill endpoint support to the federation system.
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 feat/federation-backfill-endpoint

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
🧪 Early access (Sonnet 4.5): enabled

We are currently testing the Sonnet 4.5 model, which is expected to improve code review quality. However, this model may lead to increased noise levels in the review comments. Please disable the early access features if the noise level causes any inconvenience.

Note:

  • Public repositories are always opted into early access features.
  • You can enable or disable early access features from the CodeRabbit UI or by updating the CodeRabbit configuration file.

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

@ricardogarim ricardogarim marked this pull request as ready for review September 29, 2025 10:42
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 dca0b3a and 42ce6f0.

📒 Files selected for processing (1)
  • ee/packages/federation-matrix/src/api/_matrix/transactions.ts (2 hunks)

@ggazzo ggazzo added this to the 7.11.0 milestone Sep 29, 2025
@codecov
Copy link

codecov bot commented Sep 29, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 67.39%. Comparing base (dca0b3a) to head (a299f3b).
⚠️ Report is 4 commits behind head on release-7.11.0.

Additional details and impacted files

Impacted file tree graph

@@               Coverage Diff               @@
##           release-7.11.0   #37087   +/-   ##
===============================================
  Coverage           67.38%   67.39%           
===============================================
  Files                3328     3328           
  Lines              113342   113342           
  Branches            20562    20560    -2     
===============================================
+ Hits                76375    76382    +7     
+ Misses              34363    34358    -5     
+ Partials             2604     2602    -2     
Flag Coverage Δ
e2e 57.31% <ø> (+0.03%) ⬆️
unit 71.13% <ø> (-0.01%) ⬇️

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 changed the base branch from develop to release-7.11.0 September 29, 2025 20:29
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

🧹 Nitpick comments (2)
ee/packages/federation-matrix/src/api/_matrix/transactions.ts (2)

464-472: Document error responses in the schema.

The handler returns 400 (lines 478-484) and 500 (lines 495-500) error responses, but only the 200 response is declared in the schema. While some existing endpoints in this file share this pattern, documenting error responses improves API clarity and enables proper validation.

Consider adding error response schemas:

 				{
 					params: isBackfillParamsProps,
 					query: isBackfillQueryProps,
 					response: {
+						400: isErrorResponseProps,
+						500: isErrorResponseProps,
 					},
 					tags: ['Federation'],
 					license: ['federation'],
 				},

475-475: Validate limit parameter coercion.

Number(c.req.query('limit') || 100) can produce NaN if the query string contains a non-numeric value (e.g., ?limit=abc). When limit becomes optional (per the previous comment), the schema validator won't catch malformed values that are present. Consider validating the coerced number or relying on the validator to enforce numeric types before this line executes.

One approach is to add explicit NaN handling:

-					const limit = Number(c.req.query('limit') || 100);
+					const rawLimit = c.req.query('limit');
+					const limit = rawLimit ? Number(rawLimit) : 100;
+					if (isNaN(limit)) {
+						return {
+							body: {
+								errcode: 'M_BAD_REQUEST',
+								error: 'Invalid limit parameter',
+							},
+							statusCode: 400,
+						};
+					}
📜 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 665be86 and a299f3b.

📒 Files selected for processing (1)
  • ee/packages/federation-matrix/src/api/_matrix/transactions.ts (2 hunks)
⏰ 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 (5)
ee/packages/federation-matrix/src/api/_matrix/transactions.ts (5)

473-485: Good validation of required event IDs.

The check for eventIds?.length correctly validates that at least one event ID is provided, and the error response follows Matrix spec conventions with appropriate errcode and message.


255-268: Schema definition looks good.

The BackfillParamsSchema correctly validates the room ID with the Matrix room pattern, consistent with other room ID validations in this file (e.g., line 93).


293-314: Response schema properly structured.

The BackfillResponseSchema correctly reuses EventBaseSchema for PDU validation and follows the established pattern of other response schemas in this file.


270-286: Make limit optional to match the handler's default behavior.

The schema marks limit as required (line 284), but the handler provides a default value of 100 when it's missing (line 475). This inconsistency will cause the validator to reject valid requests that omit the limit parameter, preventing the default from ever being applied.

Apply this diff to align the schema with the implementation:

-	required: ['limit', 'v'],
+	required: ['v'],

487-493: Verify that the SDK implements getBackfillEvents method.

The call to event.getBackfillEvents(roomId, eventIds as EventID[], limit) on line 488 follows the same pattern as other event service methods in this file (e.g., getEventById, getState, getStateIds). However, the event service is provided by the external @rocket.chat/federation-sdk package (version 0.1.11), and the getBackfillEvents method definition cannot be found in this repository.

Ensure that:

  • The SDK has been updated to include the getBackfillEvents method with the expected signature (roomId: string, eventIds: EventID[], limit: number)
  • The method returns data conforming to the BackfillResponseSchema structure (with origin, origin_server_ts, and pdus fields)
  • The SDK version dependency is correctly specified to include this new method

@ggazzo ggazzo added the stat: QA assured Means it has been tested and approved by a company insider label Sep 29, 2025
@dionisio-bot dionisio-bot bot added the stat: ready to merge PR tested and approved waiting for merge label Sep 29, 2025
@kodiakhq kodiakhq bot merged commit c984d49 into release-7.11.0 Sep 29, 2025
24 checks passed
@kodiakhq kodiakhq bot deleted the feat/federation-backfill-endpoint branch September 29, 2025 20:42
ricardogarim added a commit that referenced this pull request Oct 7, 2025
Co-authored-by: Guilherme Gazzo <5263975+ggazzo@users.noreply.github.com>
ricardogarim added a commit that referenced this pull request Oct 8, 2025
Co-authored-by: Guilherme Gazzo <5263975+ggazzo@users.noreply.github.com>
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.

3 participants