Repository navigation
fix: send presence_state when a new token grants presence read - #2674
Open
Indian-boult wants to merge 2 commits into
Open
Indian-boult wants to merge 2 commits into
Indian-boult wants to merge 2 commits into
Conversation
A client that joined a private channel without presence read got no presence_state. When a new access_token granted presence read, the channel started to send presence_diff but never presence_state, so realtime-js held every diff and presence stayed empty until a rejoin. Send :sync_presence after the fastlane resubscribe when presence read goes from denied to granted.
seangeo
requested changes
Nov 30, 2026
…already granted Use assert_receive for the presence_state after the refresh so the test waits for it. Add a test that a new access_token gives no second presence_state when the client already had presence read.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
A client that joins a private channel without presence read gets no
presence_state. When a newaccess_tokengrants presence read,maybe_resubscribe_fastlaneupdates the fastlane metadata and the client starts to get everypresence_diff, but the channel never sendspresence_state. realtime-js holds eachpresence_diffuntil apresence_statearrives, so presence stays empty on the client until it rejoins.What changed
maybe_resubscribe_fastlaneinapply_access_token,maybe_sync_presence/2sends:sync_presencewhen presence is enabled, the new policies grant presence read and the previous ones did not. The existing:sync_presencehandler then pushes the current state.test/integration/rt_channel/presence_read_granted_on_refresh_test.exsruns for the V1 and V2 serializers. A member tracks on a private topic. A second client joins without presence read, then sends a token that grants it. The test checks that the second client gets the member'spresence_diffand also apresence_statewith the member in it.Scope
Nothing changes when presence read was already granted, when presence is not enabled or when the new token still denies presence read. A token that removes a read permission still closes the channel through
check_read_permissions_revoked. The broadcast side of this flow already worked and is not changed.Verification
presence_statenever arrives, and passes with the change.test/integration/rt_channelandtest/realtime_web/channelspass, 1021 tests with one failure. That one is the WAL bloat test, which fails on main too in my setup because its setup expectswal_keep_sizeof 32MB from the compose file.mix compile --force --warnings-as-errorspasses, andmix format --check-formattedandmix credo --strictpass on the changed files. I did not run Dialyzer or the full suite.Fixes #2673