Add clearSessionRoom function and tests for stale session room handling#4188
Add clearSessionRoom function and tests for stale session room handling#4188
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes repeated 403 M_FORBIDDEN errors when realm-server tries to broadcast realm events to stale Matrix session rooms. When the send fails because the realm server is no longer in the room, the stale session_room_id is cleared from the database.
Changes:
- Added
clearSessionRoomDB helper that conditionally nulls out a user'ssession_room_idwhen it matches a given room ID. - Added error detection in
broadcastRealmEventto catch "not in room" Matrix errors and clear the stale session room. - Added tests for both the DB helper and the broadcast cleanup path, registered in CI.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
packages/runtime-common/db-queries/session-room-queries.ts |
New clearSessionRoom function |
packages/realm-server/node-realm.ts |
Error parsing + stale room cleanup in broadcastRealmEvent |
packages/realm-server/tests/session-room-queries-test.ts |
Tests for clearSessionRoom |
packages/realm-server/tests/node-realm-test.ts |
Tests for broadcast stale room handling |
packages/realm-server/tests/index.ts |
Register new test file |
.github/workflows/ci.yaml |
Add new test to CI shard list |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9bed476a54
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Host Test Results 1 files 1 suites 2h 29m 19s ⏱️ Results for commit 3caf9b7. ♻️ This comment has been updated with latest results. |
backspace
left a comment
There was a problem hiding this comment.
The same host test failed on a PR of mine so it seems spurious or flaky 😞
|
that test failure should be fixed in main now. if you merge upstream it will pass |
Summary
M_FORBIDDEN"realm server not in room" send error duringbroadcastRealmEvent.users.session_room_idfor that user/room pair so future index broadcasts stop targeting an invalid room.Problem
After from-scratch indexing, realm-server could try to broadcast incremental index events into per-user session DM rooms that no longer included
@realm_server:localhost. Those stalesession_room_idvalues remained in the database, so every later broadcast retried the same dead room and logged repeated403 M_FORBIDDENerrors.Fix
When Matrix rejects a send with the specific "user not in room" error, realm-server now treats that room mapping as stale and removes it from the user record. This keeps the existing design intact, where realm events are delivered through per-user session DMs, while preventing endless retries against rooms the service account has already left or lost access to.