Skip to content

UTS: wait for client B's presence sync before the RTP8 lifecycle enters - #587

Open
owenpearson wants to merge 1 commit into
mainfrom
fix/uts-rtp8-wait-for-sync
Open

owenpearson wants to merge 1 commit into
mainfrom
fix/uts-rtp8-wait-for-sync

Conversation

@owenpearson

Copy link
Copy Markdown
Member

Closes #564

The race

realtime/integration/RTP8/enter-update-leave-lifecycle-0 attaches client B, subscribes, attaches client A and enters, then asserts that client B's first presence event is an ENTER. Nothing waits for client B's initial presence sync.

The sandbox answers the first attach to a new channel with HAS_PRESENCE even though the channel is empty, and sends a SYNC shortly after. RTP1 allows this ("the sync may be empty"), so the server is not at fault. If client A's enter reaches the server before that SYNC goes out, the SYNC carries the member to client B as PRESENT, ahead of the live ENTER (which carries the same id), and the first assertion fails.

Measured against the sandbox:

  • Client B's first attach carried HAS_PRESENCE in 738 of 738 runs (presence_lifecycle_test.md's RTP8 test races the server's first presence sync, so the first event can be PRESENT rather than ENTER #564) and in 168 of 168 in a re-run for this PR, json and msgpack alike. The SYNC followed a median of 80ms later (90th percentile 96ms).
  • Sending client A's enter a fixed delay after client B's ATTACHED, swept from 50 to 105ms: 28 of 336 runs saw PRESENT first without the wait, every one between 50 and 84ms. With the wait, 0 of 336.
  • In the 168-run re-run without an injected delay, client A's own attach still carried HAS_PRESENCE in 82 of 84 runs without the wait, so client A was attaching, and entering, before client B's sync had gone out. With the wait, 0 of 84. (Local latency kept the enter outside the window in those runs, so none saw PRESENT first.)
  • ably-js's derived test fails this way in CI: expected 'present' to equal 'enter' at presence_lifecycle.test.ts:180, in 31 jobs across 28 failed runs of "Test NodeJS (UTS)" since 2026-10-22. ably-python's derived test failed this way six times in CI in a week. ably-dotnet's derived test sees a PRESENT among the events too.

The fix

  • Wait for client B's sync with AWAIT channel_b.presence.get() (RTP11c1) between client B's subscribe and client A's attach, so client A's enter reaches client B live. get() returns an empty list there, and every assertion stands.
  • Reword the bulk-enter test's comment. That test already counts PRESENT alongside ENTER, which tolerates the same race, but the comment attributed the PRESENT events only to client B's connection dropping. It now names the first sync too. The test's steps are unchanged.

Test IDs are unchanged. npm run lint passes.

Not addressed here: RTP2a/RTP2b2 don't say whether an incoming message with an equal id counts as newer, which decides whether the duplicate ENTER is discarded or emitted after the PRESENT. The fix makes the first event an ENTER either way.

🤖 Generated with Claude Code

The sandbox answers the first attach to a new channel with HAS_PRESENCE,
even when the channel is empty, and sends the SYNC shortly after. If
client A's enter reaches the server before that SYNC goes out, client B
receives the member inside the SYNC as PRESENT ahead of the live ENTER,
so the RTP8 lifecycle test's first event is not an ENTER.

Wait for client B's sync with presence.get() (RTP11c1) before client A
attaches, and reword the bulk-enter test's comment to name the first
sync, as well as a dropped connection, as a source of PRESENT events.

Closes #564

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch was successfully deployed

1 active deployment
staging/pull/587 — 9420b90a Deployed Nov 27, 2026 by github-actions[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

presence_lifecycle_test.md's RTP8 test races the server's first presence sync, so the first event can be PRESENT rather than ENTER

1 participant