Skip to content

Refuse to forget a room with a pending out-of-band invite or knock - #20501

Draft
sandhose wants to merge 1 commit into
developfrom
quenting/fix-forget-oob
Draft

sandhose wants to merge 1 commit into
developfrom
quenting/fix-forget-oob

Conversation

@sandhose

@sandhose sandhose commented Nov 10, 2026 •

Copy link
Copy Markdown
Member

More internal context here

/rooms/{roomId}/forget has to fail while the user is still invited or knocking. It does when the server is in the room (400), but for an invite or knock in a room the server is not in it returned 200 and hid the room from every sync flavour, while the invite stayed pending on the other side.

RoomMemberHandler.forget read the membership from the room's current state, which an out-of-band invite or knock never enters. It now reads local_current_membership, which is written in the same transaction as current_state_events and also for out-of-band memberships. forget is only called for local users, so the room-state lookup was redundant. A rejected invite or rescinded knock is a leave there and can still be forgotten.

ForgetOutOfBandMembershipTestCase in tests/handlers/test_room_member.py: a pending remote invite and a pending knock get 400 (200 on develop), and forgetting after rejecting the invite still works.

Pull Request Checklist

🤖 Generated with Claude Code

https://claude.ai/code/session_01Usuxv8JofVGciXVtxbdTtr

`RoomMemberHandler.forget` raised a 400 when the user's membership was
anything but `leave` or `ban`, and read that membership from the room's
current state. A remote invite, or a knock on a room the server is not
in, is an out-of-band membership: an outlier that never enters the room
state. The lookup returned nothing, the guard did not fire, and
`POST /rooms/{roomId}/forget` returned 200 and hid the room from every
sync flavour while the invite or knock was still pending on the remote
side. A server in the room returns 400 for the same call.

`forget` now reads the membership from `local_current_membership`
alone. For a local user that table is written in the same transaction
as `current_state_events`, from the same delta, and additionally for
out-of-band memberships. The room's current state is deleted when the
server leaves the room. The two can therefore only disagree in the
out-of-band direction (room state empty, `local_current_membership`
holding the invite or knock), so the room-state lookup adds nothing.
`forget` is only called for local users, which
`get_local_current_membership_for_user_in_room` requires.

A user who rejected the invite or rescinded the knock has a `leave`
there and can still forget. The internal callers (`forget_rooms_on_leave`,
deactivation, room shutdown) forget after the leave is persisted, so they
are unaffected. The error message and errcode are unchanged.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Usuxv8JofVGciXVtxbdTtr
@sandhose
sandhose force-pushed the quenting/fix-forget-oob branch from fb83f1d to 3c02f52 Compare November 17, 2026 17:56

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants