40024: untilAttach history request not served by attach region
incompatible_site_for_historyA history request using untilAttach was handled by a different Ably region from the one the channel attached in. The attach point is specific to that region, so the request could not be served and no messages were returned.
What you should do
Retrying may not help, as the retry might again be handled by a different region. There is no automatic recovery, so choose the approach that best fits your application:
- Retry without untilAttach and remove duplicates yourself. Request history without untilAttach and discard any messages you have already received in real time. This keeps a gap-free record but your application has to deduplicate.
- Retry without untilAttach and accept possible duplicates. Less work, but some messages may appear both in the history response and among those already received in real time.
- Treat it as having no retrievable history. If missing the earlier messages is acceptable, continue with only the messages received in real time.
Which is best depends on whether duplicate messages or missing history is worse for your use case.
Why it happens
Each Ably region observes and orders recent messages independently, so a given point in one region's order does not necessarily correspond to the same point in another's.
A history request using untilAttach returns the messages published up to the point at which the channel attached — a point in the order of the region it attached in. If the request is handled by a different region, that region cannot reliably determine which messages fall before that point, so rather than risk returning the wrong set it does not serve the request.
What you'll see
The whole request fails and no messages are returned. The error is reported with code 40024 and HTTP status 400, with the message Unable to get channel history: cannot serve history from a different site — "site" here is the internal term for a region.