Skip to content

ably: accept PRESENT in the presence Enter/Update/Leave test - #721

Closed
sacOO7 wants to merge 1 commit into
mainfrom
fix/presence-test-accept-sync-present
Closed

sacOO7 wants to merge 1 commit into
mainfrom
fix/presence-test-accept-sync-present

Conversation

@sacOO7

@sacOO7 sacOO7 commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes an occasional CI failure in TestRealtimePresence_Presence_Enter_Update_Leave. Client1's presence subscriber sometimes receives PRESENT where the test expects ENTER or UPDATE. The fix is 2 lines, test-only: accept PRESENT at those two steps. No SDK code changes.

ℹ️ Confidence: the explanation below follows from the SDK code and the spec, and fits both failures. We could not reproduce it against the sandbox (0 in about 440 runs), so the exact server-side trigger is inferred, not observed. See "Evidence" for what was checked.

The failures

Both on CI, in the integration-test (1.25, json) job, and both passed on re-run.

Run Branch Failing step Expected Got
39564890840 integration/v2 ENTER (line 175) 2 (ENTER) 1 (PRESENT)
39619921907 #720 UPDATE (line 186) 4 (UPDATE) 1 (PRESENT)

Why a PRESENT can arrive

  1. The SDK never invents PRESENT. processProtoPresenceMessage (ably/realtime_presence.go) emits each message to subscribers with the action the server sent. It rewrites the action to PRESENT only for the internal presence map, as spec RTP2d1/RTP2d2 require. So a subscriber sees PRESENT only when the server sent PRESENT, which is what a presence SYNC delivers.
  2. A sync can happen at any time (RTP18). If client1 gets a sync that already includes client2's current state, client2 is emitted as PRESENT with that message's ID.
  3. The real event is then dropped. The ENTER or UPDATE that follows has the same msgSerial and index, so the newness check (IsNewerThan, RTP2b2) says it isn't newer and it's discarded (RTP2a). The test therefore never sees ENTER or UPDATE for that step; it sees PRESENT.

This fits both failures: a sync carrying client2's entered state at the ENTER step, and its updated state at the UPDATE step.

The fix

// ENTER step
assert.Contains(t, []ably.PresenceAction{ably.PresenceActionEnter, ably.PresenceActionPresent}, member_received.Action) // RTP2d1: a SYNC may deliver the member as PRESENT
// UPDATE step
assert.Contains(t, []ably.PresenceAction{ably.PresenceActionUpdate, ably.PresenceActionPresent}, member_received.Action) // RTP2d1: a SYNC may deliver the member as PRESENT

What still holds:

  • Each step still asserts ClientID == "client2" and the exact Data ("enter client2", "update client2"), so the content is still verified.
  • LEAVE stays strict. A sync never delivers a leave as PRESENT.
  • It can't hide an SDK bug on this path, because the SDK only emits PRESENT when the server sent it.

Why not just skip PRESENT messages? Because the real ENTER or UPDATE is dropped as a duplicate (step 3), a test that waited for it would hang until timeout.

Evidence

Check Result
SDK emits subscribers the server's action; maps store PRESENT ✅ Confirmed in ably/realtime_presence.go (Emit(msg.Action, …)), matching spec RTP2d1/RTP2d2
Equal msgSerial/index is "not newer" ✅ Confirmed in ably/proto_presence_message.go (IsNewerThan), matching RTP2b2
Reproduce against the sandbox, without the fix ❌ 0 failures in about 440 runs (60 serial with -race, plus 6 parallel × 60 with per-message logging): always ENTER → UPDATE → LEAVE
Recent change on main introducing it None found

Validation on this branch

Check Result
go build ./..., go vet with default, unit and integration tags, gofmt -l ✅
go test -tags=unit ./... ✅
Fixed test ×10 against the sandbox, application/json ✅
Fixed test ×10 against the sandbox, application/x-msgpack ✅
Every test in realtime_presence_integration_test.go, once (json) ✅

Compatibility with open work

Checked with in-memory trial merges; no branches were changed:

Merged into Result
main ✅ clean
integration/v2 (#712), where the file moved to internal/ably/ ✅ clean. The fix lands in the moved file, and the merged tree vets and passes the test.
#718 and #719 branches ✅ clean
#720 (TimeFuncs flake fix) ✅ clean. The combined tree vets and passes the test.

Reviewer notes

Summary by CodeRabbit

  • Tests
    • Updated presence synchronization checks to accept either the expected action or a “present” state when members are delivered as already present.

TestRealtimePresence_Presence_Enter_Update_Leave occasionally fails on
CI because client1's subscriber receives PRESENT where the test expects
ENTER or UPDATE.

The SDK emits each presence message to subscribers with the action the
server sent (RTP2d1), so a PRESENT can only come from the server,
typically in a SYNC. Ably may start a sync at any time (RTP18). If one
carries client2's current state before the matching ENTER or UPDATE
arrives, the member is emitted as PRESENT, and the later ENTER or
UPDATE has the same msgSerial and index, so it isn't newer and is
dropped (RTP2a, RTP2b2). Both CI failures fit this, one at the ENTER
step and one at the UPDATE step. We could not reproduce it against the
sandbox, so the trigger is inferred rather than observed.

Accept PRESENT alongside ENTER and UPDATE at those two steps. The test
still checks the client ID and data of each message, and LEAVE stays
strict, since a sync never delivers a leave as PRESENT. Skipping PRESENT
instead would hang the test, because the real event is dropped as a
duplicate.
@coderabbitai

coderabbitai Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 33969480-c75e-4544-b93b-2b1935b52827
📥 Commits

Reviewing files that changed from the base of the PR and between b3040fe and 9717e36.

📒 Files selected for processing: 1
  • ably/realtime_presence_integration_test.go

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

Walkthrough

Two presence integration test assertions now accept Present as an alternative to the expected Enter or Update action.

Changes

Presence integration tests

Layer / File(s) Summary
Accept Present actions
ably/realtime_presence_integration_test.go
The enter-event assertion accepts Enter or Present. The update-event assertion accepts Update or Present.

Priority: ⬇️ Low

Estimated code review effort: 1 (Trivial) | ~4 minutes

Change: Other

Merge Risk: ⚪ Minimal · up to 9717e

This test adjustment reflects valid presence synchronization behavior and does not introduce production risk.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 1 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly describes the main test change: accepting PRESENT during the presence Enter, Update, and Leave test. It is concise and specific.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

A rabbit checks the presence stream,
“Enter” or “Present” fits the scheme.
“Update” can be “Present” too,
The tests accept both paths now through.
I hop away; the checks are green.

Comment @coderabbitai help to get the list of available commands.

@sacOO7

sacOO7 commented Oct 21, 2026

Copy link
Copy Markdown
Contributor Author

closing in favor of https://github.com/ably/ably-go/pull/720

@sacOO7 sacOO7 closed this Oct 21, 2026

This branch was successfully deployed

1 active deployment
staging/pull/721/godoc — 9717e36b Deployed Oct 21, 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.

1 participant