Skip to content

Conversation

@ggazzo
Copy link
Member

@ggazzo ggazzo commented Jan 5, 2026

rocketchat.atlassian.net/browse/FB-137

Summary by CodeRabbit

  • Chores
    • Upgraded the federation service endpoint for room leave events from API v1 to v2, ensuring improved compatibility with current protocol standards.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 5, 2026

Walkthrough

The federation SDK's sendLeave endpoint has been updated from the v1 API path to the v2 API path. The endpoint specification now references /_matrix/federation/v2/send_leave/${roomId}/${eventId} instead of the v1 equivalent.

Changes

Cohort / File(s) Summary
Federation API Endpoint Update
packages/federation-sdk/src/specs/federation-api.ts
Updated FederationEndpoints.sendLeave endpoint from v1 to v2 API path (/_matrix/federation/v1/.../_matrix/federation/v2/...)

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

🐰 An endpoint hops from version one,
To v2's path—the work is done!
The federation route now reads so clean,
The finest upgrade ever seen! ✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: updating the sendLeave endpoint from v1 to v2 API version, which is the only modification in this changeset.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ 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/send_leave

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 marked this pull request as ready for review January 5, 2026 21:01
Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

No issues found across 1 file

@codecov-commenter
Copy link

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 52.29%. Comparing base (1890741) to head (effd400).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #324      +/-   ##
==========================================
+ Coverage   52.04%   52.29%   +0.25%     
==========================================
  Files          97       97              
  Lines       13153    13153              
==========================================
+ Hits         6845     6878      +33     
+ Misses       6308     6275      -33     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 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 a1e115b into main Jan 5, 2026
3 of 4 checks passed
@ggazzo ggazzo deleted the fix/send_leave branch January 5, 2026 21:04
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

Fix all issues with AI Agents 🤖
In @packages/federation-sdk/src/specs/federation-api.ts:
- Around line 54-55: Add a v1 endpoint variant for sendLeave (e.g., sendLeaveV1)
in FederationEndpoints alongside the existing sendLeave (v2), mirroring the
pattern used for sendJoinV2/inviteV2; then update the call site in
federation.service.ts where FederationEndpoints.sendLeave is used (around the
logic at/near the current sendLeave invocation) to first try the v2 endpoint
and, on HTTP 400 or 404 errors, retry the same request against the new
sendLeaveV1 endpoint for backward compatibility. Ensure the retry only triggers
for 400/404 and preserves the original request body/headers.
📜 Review details

Configuration used: Organization 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 1890741 and effd400.

📒 Files selected for processing (1)
  • packages/federation-sdk/src/specs/federation-api.ts
🧰 Additional context used
🧠 Learnings (1)
📓 Common learnings
Learnt from: ricardogarim
Repo: RocketChat/homeserver PR: 234
File: packages/federation-sdk/src/repositories/event.repository.ts:407-423
Timestamp: 2025-09-29T16:12:21.350Z
Learning: The Matrix Federation API backfill endpoint should include the anchor events provided in the 'v' parameter along with preceding events, as explicitly stated in the Matrix specification: "including the given event(s)".
⏰ 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: cubic · AI code reviewer

Comment on lines 54 to +55
sendLeave: (roomId: string, eventId: string) =>
`/_matrix/federation/v1/send_leave/${roomId}/${eventId}`,
`/_matrix/federation/v2/send_leave/${roomId}/${eventId}`,
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

🧩 Analysis chain

🏁 Script executed:

# First, let's examine the federation-api.ts file to see the context
cat -n packages/federation-sdk/src/specs/federation-api.ts | head -70

Repository: RocketChat/homeserver

Length of output: 3221


🌐 Web query:

Matrix Federation API send_leave endpoint specification v1.7 API versions

💡 Result:

Summary — send_leave federation endpoint:

  • v1: PUT /_matrix/federation/v1/send_leave/{roomId}/{eventId} — submits a signed m.room.member (membership: "leave") PDU to the resident server. This v1 endpoint is deprecated; its response format is not standardized (older array-style response examples). (spec.matrix.org)

  • v2: PUT /_matrix/federation/v2/send_leave/{roomId}/{eventId} — same request semantics but with a fixed/standardized response format; preferred over v1. Clients/servers should try v2 first and fall back to v1 if v2 returns 400/404/unsupported. (spec.matrix.org)

Additional related endpoints used in the leave flow:

  • GET /_matrix/federation/v1/make_leave/{roomId}/{userId} — returns a template leave event to be signed before calling send_leave. (spec.matrix.org)

If you want the full field-level request/response examples or exact deprecation wording, I can fetch and show the exact spec excerpts.

Citations:


🏁 Script executed:

# Search for all usages of sendLeave in the codebase
rg -n 'sendLeave' --type=ts --type=js -B2 -A2

# Also search for the endpoint path pattern
rg -n 'send_leave' --type=ts --type=js -B2 -A2

Repository: RocketChat/homeserver

Length of output: 3372


Add v1 fallback support for backward compatibility with older servers.

The v2 endpoint is correct per the Matrix specification v1.7 and is the preferred version. However, the specification recommends that implementations try v2 first and fall back to v1 if the request fails with 400/404 errors, since some servers may not yet support v2.

Unlike sendJoin and invite, which define both v1 and v2 endpoint variants in this file, sendLeave only provides v2 with no v1 fallback option. The current implementation in federation.service.ts:120 uses FederationEndpoints.sendLeave directly without fallback logic, which could cause failures against older servers that only support v1.

Consider adding sendLeaveV1 as a separate endpoint (consistent with sendJoinV2 and inviteV2 patterns), and implement fallback logic in federation.service.ts:118 to retry with v1 if v2 fails.

🤖 Prompt for AI Agents
In @packages/federation-sdk/src/specs/federation-api.ts around lines 54-55, Add
a v1 endpoint variant for sendLeave (e.g., sendLeaveV1) in FederationEndpoints
alongside the existing sendLeave (v2), mirroring the pattern used for
sendJoinV2/inviteV2; then update the call site in federation.service.ts where
FederationEndpoints.sendLeave is used (around the logic at/near the current
sendLeave invocation) to first try the v2 endpoint and, on HTTP 400 or 404
errors, retry the same request against the new sendLeaveV1 endpoint for backward
compatibility. Ensure the retry only triggers for 400/404 and preserves the
original request body/headers.

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