Skip to content

fix: send presence_state when a new token grants presence read - #2674

Open
Indian-boult wants to merge 2 commits into
supabase:mainfrom
Indian-boult:fix/presence-sync-on-read-granted
Open

Indian-boult wants to merge 2 commits into
supabase:mainfrom
Indian-boult:fix/presence-sync-on-read-granted

Conversation

@Indian-boult

Copy link
Copy Markdown
Contributor

Why

A client that joins a private channel without presence read gets no presence_state. When a new access_token grants presence read, maybe_resubscribe_fastlane updates the fastlane metadata and the client starts to get every presence_diff, but the channel never sends presence_state. realtime-js holds each presence_diff until a presence_state arrives, so presence stays empty on the client until it rejoins.

What changed

  • After maybe_resubscribe_fastlane in apply_access_token, maybe_sync_presence/2 sends :sync_presence when presence is enabled, the new policies grant presence read and the previous ones did not. The existing :sync_presence handler then pushes the current state.
  • A new test in test/integration/rt_channel/presence_read_granted_on_refresh_test.exs runs 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's presence_diff and also a presence_state with 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

  • The new test fails on main at ccb1bf8 because presence_state never arrives, and passes with the change.
  • With the change, the tests under test/integration/rt_channel and test/realtime_web/channels pass, 1021 tests with one failure. That one is the WAL bloat test, which fails on main too in my setup because its setup expects wal_keep_size of 32MB from the compose file.
  • On Elixir 1.19.7 and OTP 28.5, mix compile --force --warnings-as-errors passes, and mix format --check-formatted and mix credo --strict pass on the changed files. I did not run Dialyzer or the full suite.

Fixes #2673

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.
…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.
@Indian-boult
Indian-boult requested a review from seangeo November 30, 2026 00:55

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Presence stays empty after a new token grants presence read on a private channel

2 participants