Skip to content

fix: do not fabricate a presence id from a missing protocol message id - #719

Merged
ttypic merged 2 commits into
ably:mainfrom
RaphaelFakhri:fix/presence-fabricated-none-id
Nov 26, 2026
Merged

ttypic merged 2 commits into
ably:mainfrom
RaphaelFakhri:fix/presence-fabricated-none-id

Conversation

@RaphaelFakhri

@RaphaelFakhri RaphaelFakhri commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Refs #706.

When a PRESENCE protocol message carried no id, Message.update_inner_message_fields set each inner message id to the string "None:<index>". The RTP2b newness check then failed to parse that id and raised ValueError. The transport logged the exception and dropped the presence message.

Changes

  • ably/types/message.py: set an inner message id from the protocol message only when the protocol message has an id.
  • ably/realtime/presencemap.py: _is_newer compares by timestamp (RTP2b1) when either message has no id, instead of calling parse_id().
  • test/unit/message_test.py: add tests for both changes.

Testing

  • pytest test/unit test/ably/realtime/presencemap_test.py: 130 passed.
  • The two new tests fail without the source changes and pass with them.
  • ruff check ably test/unit: clean.

The third point in the issue, what is_synthesized() returns for a message without an id, is unchanged. Messages without an id now never reach the id-based comparison.

Summary by CodeRabbit

  • Bug Fixes
    • Prevented presence messages without IDs from receiving fabricated IDs.
    • Corrected ordering for presence messages without IDs by comparing their timestamps.

@coderabbitai

coderabbitai Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The changes prevent synthesis of an inner presence-message ID when the protocol message has no ID. They also compare presence messages without IDs by timestamp and add tests for both behaviors.

Changes

Presence message ID handling

Layer / File(s) Summary
Inner ID creation and ordering
ably/pubsub/types/message.py, ably/pubsub/realtime/presencemap.py, test/unit/message_test.py
Inner presence-message IDs are synthesized only when the protocol message has a truthy ID. _is_newer compares messages by timestamp when either message lacks an ID. Tests cover both behaviors and both timestamp comparison directions.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: owenpearson, sacoo7

Merge Risk: Minimal · up to 5dde6

Presence messages without an ID are no longer dropped and are ordered by timestamp. The change is small and tested, and no merge-blocking risk was found.

Security architecture risk: Low · up to f3bad

Messages without IDs can now participate in presence updates using timestamp ordering. The review found no demonstrated identity-control bypass, but could not establish who controls the incoming timestamps and identity fields.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The newly accepted ordering path affects presence entries addressed by a member key within channel presence handling; the evidence does not establish a broader privilege or cross-service change.

Trust Boundaries and Controls

  • observed — The inspected channel handler passes incoming presence fields to decoding and state handling, while PresenceMap enforces a member-key requirement. The inspected path does not establish where protocol authenticity or timestamp and identity provenance are enforced upstream.

Resilience and Maintainability Implications

  • observed — ID-less updates now avoid ID parsing during newness checks. Both storage and removal retain their existing member-key and newness checks.
Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the main change: the fix stops synthesizing a presence message ID when the protocol message has no ID. The changeset matches this. The presencemap.py change compares by timestamp when …
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.
Full details: Title check

Explanation

The title names the main change: the fix stops synthesizing a presence message ID when the protocol message has no ID. The changeset matches this. The presencemap.py change compares by timestamp when a message lacks an ID, and the message.py change synthesizes the inner ID only when the protocol message ID is truthy. The added tests in test/unit/message_test.py cover both behaviors. The title is specific and uses the conventional fix: prefix.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
Fix failing CI checks

  • 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 message trail,
No missing ID can grow a tail.
Timestamps sort the present pair,
The tests confirm the order there.
I hop away, with carrots fair.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 8b53ac89-7adc-4ffd-a9bc-a7112d44fbc2
Commits

Reviewing files that changed from the base of the PR and between f3bad52 and 5dde6c4.

Files selected for processing: 3

  • ably/pubsub/realtime/presencemap.py
  • ably/pubsub/types/message.py
  • test/unit/message_test.py

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

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🔵 Needs a closer look

Add regression tests covering mixed IDs, both argument orders, and timestamp precedence.

Review effort: Lite
Findings: None

What changed in this PR

Fixes presence handling when protocol messages lack IDs by preserving missing IDs and using timestamp-based newness checks.

Changes:

  • Prevents fabricated inner message IDs.
  • Adds timestamp fallback for missing IDs.
  • Adds regression tests.
File Summary
test/​unit/​message_test.py Adds regression coverage for missing IDs.
ably/​types/​message.py Prevents fabricated inner IDs.
ably/​realtime/​presencemap.py Uses timestamps when IDs are missing; additional mixed-ID coverage is requested.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@RaphaelFakhri
RaphaelFakhri force-pushed the fix/presence-fabricated-none-id branch from f3bad52 to 1f0fd99 Compare November 3, 2026 10:24
@RaphaelFakhri

Copy link
Copy Markdown
Contributor Author

Rebased onto main and moved to the ably.pubsub paths. test/unit/message_test.py passes (8 tests), and the 2 new tests fail on main.

@ttypic ttypic left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for contribution! changed issue link from "fixes" to "refs", because pr does not fully fix the issue. Any other id that can't be parsed (for example one with a non-numeric serial) still makes parse_id() raise inside PresenceMap.put().

@ttypic
ttypic merged commit 2435510 into ably:main Nov 26, 2026
10 of 12 checks passed
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.

3 participants