Skip to content

[DX-879] [DX-880] Addresses discontinuity docs gap from llm-eval docs audit#3232

Merged
umair-ably merged 2 commits intomainfrom
DX-879-880-Discontinuity
Mar 3, 2026
Merged

[DX-879] [DX-880] Addresses discontinuity docs gap from llm-eval docs audit#3232
umair-ably merged 2 commits intomainfrom
DX-879-880-Discontinuity

Conversation

@umair-ably
Copy link
Contributor

Description

Addresses discontinuity docs gap from llm-eval docs audit

Checklist

@coderabbitai
Copy link

coderabbitai bot commented Mar 2, 2026

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch DX-879-880-Discontinuity

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

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

@umair-ably umair-ably changed the title Addresses discontinuity docs gap from llm-eval docs audit [DX-879] [DX-880] Addresses discontinuity docs gap from llm-eval docs audit Mar 2, 2026
@umair-ably umair-ably force-pushed the DX-879-880-Discontinuity branch from 5919b84 to 460407b Compare March 2, 2026 13:34
@umair-ably umair-ably requested a review from GregHolmes March 2, 2026 13:34
@umair-ably umair-ably assigned AndyTWF and unassigned AndyTWF Mar 2, 2026
@umair-ably umair-ably requested a review from AndyTWF March 2, 2026 13:34
@umair-ably umair-ably marked this pull request as ready for review March 2, 2026 13:34
const { off } = room.onDiscontinuity((reason) => {
console.log('Discontinuity detected:', reason);
// Fetch missed messages using history
room.messages.history({ orderBy: OrderBy.NewestFirst, limit: 50 }).then((history) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

You're likely to want to use historyBeforeSubscribe based on your messages subscription here

@@ -0,0 +1,170 @@
---
Copy link
Contributor

Choose a reason for hiding this comment

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

I would split this guide into Pub/Sub and Chat - they're handled quite differently so it would be weird to have someone expecting to find Chat to be greeted by Pub/Sub.

Discontinuity occurs when the Ably SDK cannot guarantee that all messages have been delivered to the client. The most common causes are:

- Network disconnection lasting longer than two minutes. Ably preserves [connection state](/docs/connect/states#connection-state-recovery) for up to two minutes. Beyond this window, Ably cannot guarantee message continuity.
- Server-initiated continuity loss. Operational events such as cluster rebalancing may cause a partial loss of message continuity, even if the client remained connected.
Copy link
Contributor

Choose a reason for hiding this comment

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

Also when outbound rate limits are hit

<Code>
```javascript
async function recoverMissedMessages(channel) {
const history = await channel.history({ untilAttach: true });
Copy link
Contributor

Choose a reason for hiding this comment

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

This example is incomplete - untilAttach will allow you to paginate all messages up until the point of attachment (or re-attachment, in this case). However it is the users responsibility to work out how far back they need to go with their history query (e.g. using timebounds, then checking message IDs or serials for things they've already seen before).

There is also no guarantee that all missed messages are in one page, so multiple pages may be required (not shown here).

</Code>

<Aside data-type="important">
Subscribe to the channel before making a history request with `untilAttach` set to `true`. Calling `subscribe()` implicitly attaches the channel, which populates the serial number used by the `untilAttach` parameter. This guarantees that messages from the point of attachment onwards are received via the subscription, while prior messages are retrieved via history.
Copy link
Contributor

Choose a reason for hiding this comment

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

Only if the attachOnSubscribe setting is true.

```
</Code>

You can also use [`historyBeforeSubscribe()`](/docs/chat/rooms/history#subscribe) to retrieve messages from the point at which your listener was subscribed, ensuring no overlap between historical and live messages.
Copy link
Contributor

Choose a reason for hiding this comment

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

From the point at which it was re-subscribed. The attachment point changes post-resume. historyBeforeSubscribe is preferred for Chat over history as it guarantees you don't miss anything.

A complication you have to consider with Chat is that message UPDATEs and DELETEs may have happened on the channel during the discontinuity period, which wouldn't be picked up by simply appending messages to the UI.

In this situation, you want to refresh the entire Chat message state.

@umair-ably umair-ably requested a review from AndyTWF March 3, 2026 12:20
@umair-ably umair-ably force-pushed the DX-879-880-Discontinuity branch from ce4a09d to c7c8a1a Compare March 3, 2026 21:31
@umair-ably umair-ably enabled auto-merge (squash) March 3, 2026 21:32
@umair-ably umair-ably merged commit 7ba0e44 into main Mar 3, 2026
7 checks passed
@umair-ably umair-ably deleted the DX-879-880-Discontinuity branch March 3, 2026 21:40
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.

2 participants