-
Notifications
You must be signed in to change notification settings - Fork 14
fix: update sendLeave endpoint to use v2 API version #324
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
WalkthroughThe federation SDK's Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this 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 Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
There was a problem hiding this 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.
📒 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
| sendLeave: (roomId: string, eventId: string) => | ||
| `/_matrix/federation/v1/send_leave/${roomId}/${eventId}`, | ||
| `/_matrix/federation/v2/send_leave/${roomId}/${eventId}`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 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 -70Repository: 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:
- 1: https://spec.matrix.org/legacy/server_server/r0.1.4.html?utm_source=openai
- 2: https://spec.matrix.org/v1.4/server-server-api/?utm_source=openai
- 3: https://spec.matrix.org/v1.15/server-server-api/?utm_source=openai
🏁 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 -A2Repository: 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.
rocketchat.atlassian.net/browse/FB-137
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.