Skip to content

Conversation

@Muawiya-contact
Copy link

@Muawiya-contact Muawiya-contact commented Jan 19, 2026

Description

This PR addresses the TODO in event-wrapper.ts regarding the naming of the origin getter.

Previously, EventWrapper.origin was extracting the domain from the Sender's ID (e.g., @user:domain.com). In the Matrix protocol, "Origin" refers specifically to the server that created the event. This naming was misleading and has been clarified.

Changes

  • Refactored EventWrapper: Renamed the domain extractor to senderDomain.
  • Protocol Compliance: Kept an origin property to return the actual rawEvent.origin, maintaining alignment with the Matrix specification and PersistentEventBase interface.
  • Build Integrity: Updated all call sites (federation service, room service, authorization rules) to use the new senderDomain property where appropriate.

Testing

  • Verified build with bun run build (FULL TURBO).
  • Verified all 5 packages compile successfully.

Summary by CodeRabbit

  • Refactor
    • Updated federation event processing to use consistent server domain identification throughout the platform, improving reliability of event routing and server communications.
    • Enhanced authorization validation logic for room aliases and federated creation events by normalizing domain comparison methods.
    • Streamlined internal tracking of event origin metadata to improve code clarity and maintainability.

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

@CLAassistant
Copy link

CLAassistant commented Jan 19, 2026

CLA assistant check
All committers have signed the CLA.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 19, 2026

Walkthrough

This PR refactors event origin tracking by introducing a new eventOrigin field to store the originating server separately from derived domain values. A new senderDomain getter extracts domain from the sender ID. Call sites are systematically updated to use senderDomain instead of origin for domain-identity validation checks, and join event processing is simplified to use only the resident server context.

Changes

Cohort / File(s) Summary
Event Metadata Tracking
packages/room/src/manager/event-wrapper.ts
Adds eventOrigin?: string field to store origin server metadata. Introduces senderDomain getter deriving domain from sender ID. Updates origin getter to return eventOrigin instead of computed value.
Origin Accessor Updates
packages/room/src/manager/room-state.ts
Simplifies origin accessor to return createEvent.senderDomain directly, removing previous createEvent.origin lookup and validation.
Domain-Identity Validation
packages/room/src/authorizartion-rules/rules.ts
Replaces origin checks with senderDomain in canonical alias and federated create validations; updates domain-matching logic in isRoomAliasAllowed and checkEventAuthWithState.
Server Skip Logic
packages/federation-sdk/src/services/federation.service.ts
Changes skip condition in sendEventToAllServersInRoom from comparing event.origin to event.senderDomain; updates corresponding log message.
Join Event Processing
packages/federation-sdk/src/services/room.service.ts
Simplifies argument passed to processIncomingPDUs during join handling from residentServer || joinEventFinal.origin to only residentServer.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • ricardogarim
  • ggazzo
  • sampaiodiego

Poem

🐰 Event origins now split with care,
senderDomain in the air!
From ID to domain, a cleaner way,
Event metadata shines today ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ 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 accurately describes the main refactoring: renaming the confusing origin getter to senderDomain in EventWrapper.
Linked Issues check ✅ Passed All coding requirements from issue #144 are met: the misleading origin getter has been renamed to senderDomain and origin property now returns the actual event origin.
Out of Scope Changes check ✅ Passed All changes are directly related to the refactoring objective; updates to federation service, room service, and authorization rules are necessary for call-site consistency.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

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 8 files

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: 4

🤖 Fix all issues with AI agents
In `@packages/core/src/events/m.room.create.spec.ts`:
- Around line 112-113: The test is passing an undefined value because it uses
finalEvent.senderDomain (which doesn't exist) when calling createFromRawEvent;
replace that reference with the existing property finalEvent.origin (or derive
the domain from finalEvent.sender if that was intended) so the origin argument
passed to createFromRawEvent uses the correct value; update the call site that
references finalEvent.senderDomain to use finalEvent.origin (or adjust to
extract domain from finalEvent.sender) and run the tests.

In `@packages/core/src/events/m.room.member.spec.ts`:
- Around line 309-310: signedKickEvent is a plain object returned by signEvent,
so tests should access raw fields not getters; replace uses of
signedKickEvent.senderDomain with signedKickEvent.content?.sender ||
signedKickEvent.content?.user_id as appropriate (or compare
signedKickEvent.origin and/or signedKickEvent.content fields) and keep the
origin_server_ts assertion to check signedKickEvent.origin_server_ts directly;
update the assertions around senderDomain to reference the actual property
produced by signEvent (e.g., content.sender or sender) instead of relying on a
getter.
- Around line 477-478: The test is trying to use the senderDomain getter on
signedBanEvent which is a plain object; replace that usage by either
constructing a MatrixEvent wrapper (e.g., new MatrixEvent(signedBanEvent)) and
asserting its .senderDomain, or compute the domain directly from the plain
object's sender string (e.g., parse signedBanEvent.sender.split(':')[1]) and
compare that to serverName; keep the existing assertion for origin_server_ts
as-is.
- Around line 145-146: The test is asserting a non-existent property
`senderDomain` on the plain object returned by signEvent; update the assertion
to check the actual property present on the SignedEvent object (use
`signedLeaveEvent.origin`) instead of `signedLeaveEvent.senderDomain`. Locate
the test around the `signEvent` usage and replace the `senderDomain` expectation
with `origin`, keeping the `origin_server_ts` assertion as-is; this uses the
`signEvent` return value (SignedEvent<T>) rather than the PersistentEventBase
class getter.
🧹 Nitpick comments (2)
packages/room/src/manager/event-wrapper.ts (1)

128-139: Unreachable null check due to extractDomainFromId throwing behavior.

The local extractDomainFromId function (lines 23-29) throws an Error when no domain is found, so it never returns a falsy value. The if (!domain) check on line 135-136 is unreachable dead code.

🔧 Remove unreachable check
     get senderDomain() {
-        const domain = extractDomainFromId(this.rawEvent.sender);
-        if (!domain) {
-            throw new Error('Invalid sender, no domain found');
-        }
-        return domain;
+        return extractDomainFromId(this.rawEvent.sender);
     }
packages/room/src/manager/room-state.ts (1)

112-128: Comment is now misleading after refactor.

The comment on line 112 states "origin is the origin of the room gotten from the room id", but the implementation now uses createEvent.senderDomain which is derived from the sender, not the room_id. While these should match for valid rooms (per Matrix authorization rules), the comment should be updated to reflect the actual implementation.

Additionally, senderDomain throws if the domain is invalid, so the if (!origin) check on line 123 may be unreachable.

📝 Update comment to match implementation
-	// origin is the origin of the room gotten from the room id
+	// origin is the domain of the room creator (sender of m.room.create event)
 	get origin() {
 		const createEvent = getStateByMapKey(this.stateMap, {
 			type: 'm.room.create',
 		});

 		if (!createEvent) {
 			throw new Error('Room create event not found');
 		}

-		const origin = createEvent.senderDomain;
-		if (!origin) {
-			throw new Error('Room create event has no origin');
-		}
-
-		return origin;
+		return createEvent.senderDomain;
 	}

@Muawiya-contact
Copy link
Author

I have addressed the feedback from CodeRabbit in the latest commit (61e51f5). All tests are verified, and the build is successful. Ready for a human review! @sampaiodiego

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.

2 participants