Conversation
_sync_diff broke out of the leaves loop when a key was not present in the local state, so every remaining key in that diff was skipped: those presences stayed in presence.state forever and on_presence_leave never fired for them. Since leaves comes straight off the wire, a server diff listing an untracked key before a tracked one is enough to trigger it. Skip only the untracked key, matching Phoenix's presence.js. Fixes supabase#1630
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.
What kind of change does this PR introduce?
Bug fix.
What is the current behavior?
Fixes #1630
AsyncRealtimePresence._sync_diffusesbreakwhere it meanscontinue:When a
presence_diffcarries leaves for a key the client isn't tracking, the loop aborts and every remaining key in that diff is dropped. Those presences stay inpresence.stateindefinitely andon_presence_leavenever fires for them — a ghost user in the UI until the next fullpresence_stateresync.leavescomes straight off the wire in_on_diff_event, so the server controls both the contents and the key order; a diff listing an untracked key before a tracked one is enough. A client sees untracked keys routinely — it joined after that user left, or already removed the key in an earlier diff.What is the new behavior?
continue, so only the untracked key is skipped. This matches Phoenix'spresence.js, which this file is a port of and whichreturns from the per-key callback there._sync/presence.pyis a stub (SyncRealtimePresencehas no state handling), so there is no sync counterpart to update.Tests
test_sync_diff_processes_every_leave_keyinsrc/realtime/tests/test_presence.py— feeds a diff whose leaves list an untracked key before a tracked one, and asserts the tracked key is removed fromstateand itson_leavecallback fires. It fails onmain(bobsurvives the diff, no callback) and passes here.Validation
uv run --package realtime pytest src/realtime/tests/test_presence.py— 9 passed.uv run --package realtime pytest src/realtime/tests— 25 passed, 2 failed. The two failures aretest_connection.py::test_postgrest_changesand::test_postgrest_changes_on_different_tables; they fail identically onmainwithout this change in my environment, and are unrelated to presence.uv run --package realtime mypy src/realtime/src/realtime src/realtime/tests— success, 20 source files.uv run ruff check/uv run ruff format --check— clean.git diff --check— clean.The realtime suite runs against the local Supabase stack (
make realtime.start-infra, which needs Docker and the Supabase CLI); I had it running, hence the live tests above passing.Additional context
None.