<!-- XE-16842 · [Low] ChatStore.Messages since cursor silently skips out-of-order messages; results returned in arrival order, not timestamp order · testnet -->
*Markdown view of <https://bounty.xe.network/XE-16842>. The page is the record; this is the same page for reading.*

XE-16842 · Bounty

# \[Low\] ChatStore.Messages since cursor silently skips out-of-order messages; results returned in arrival order, not timestamp order

Closed · duplicate
—
[xe#671](https://github.com/xeprotocol/xe/issues/671)
filed 2026-11-17 06:33 UTC
by kecedanzz77-bit

Verdict
:   Duplicate

Tier
:   —

Claimed
:   —

Area
:   Node / API

Duplicate of
:   —

Tracked
:   —

Updated
:   2026-11-22 23:26 UTC

Told
:   2026-11-22 23:26 UTC

### Patches

None linked.

### History

- [770248](https://bounty.xe.network/log/770248) 2026-11-22 23:26 UTC reply.mirror\_failed
- [769849](https://bounty.xe.network/log/769849) 2026-11-22 23:26 UTC proposal.adopted
- [769848](https://bounty.xe.network/log/769848) 2026-11-22 23:26 UTC reply.sent
- [769847](https://bounty.xe.network/log/769847) 2026-11-22 23:26 UTC proposal.adopted
- [769846](https://bounty.xe.network/log/769846) 2026-11-22 23:26 UTC ticket.status new → closed
- [768801](https://bounty.xe.network/log/768801) 2026-11-22 23:25 UTC proposal.adopted
- [768800](https://bounty.xe.network/log/768800) 2026-11-22 23:25 UTC ticket.facts area
- [768799](https://bounty.xe.network/log/768799) 2026-11-22 23:25 UTC proposal.adopted
- [768798](https://bounty.xe.network/log/768798) 2026-11-22 23:25 UTC ticket.facts
- [768797](https://bounty.xe.network/log/768797) 2026-11-22 23:25 UTC proposal.adopted
- [768796](https://bounty.xe.network/log/768796) 2026-11-22 23:25 UTC ticket.facts
- [766646](https://bounty.xe.network/log/766646) 2026-11-22 23:17 UTC note.added

[Full history](https://bounty.xe.network/log?ref=XE-16842) · [JSON](https://bounty.xe.network/v1/tickets/XE-16842) · [markdown](https://bounty.xe.network/XE-16842.md)

### Report

## Summary

`ChatStore.Messages(account, since)` filters on the **sender's** timestamp and returns envelopes in **arrival order**. Any API consumer using `since` as a polling cursor — its evident purpose (`docs/api.md` documents `since` as "optional, unix nanos, default 0" for incremental fetching) — permanently misses a message that arrives after its poll but carries an earlier timestamp than the cursor. The message sits in the store but is never returned again. Consumers that don't re-sort also display messages out of sequence.

## Root cause

`chat/chat.go:112-122` — `Messages` filters on `env.Timestamp > since` and appends in slice (arrival) order. Sender timestamps are wall-clock values accepted within a freshness window (`chat/envelope.go:113-115`), and messages can arrive out of timestamp order (clock skew between senders, network delay). There is no monotonic per-account arrival sequence.

## Verification

Executed PoC against the real `chat.ChatStore`:

```
store env1 (ts=1000): true
poll since=0 -> 1 message(s): [id-1 ts=1000]
store env2 (ts=999, arrived after env1): true
poll since=1000 -> 0 message(s)
BUG 1: env2 arrived after the previous poll but is NEVER returned to a since-based polling client (silently lost forever).
poll since=0 -> order: [id-1 ts=1000] [id-2 ts=999]
BUG 2: Messages() returns arrival order, not timestamp order
```

`xe chat read` prints in returned order (`cmd/xe/chat.go:226-232`), while the web UI works around the ordering issue by sorting client-side (`web/assets/chat.js:285,388`).

## Impact

Severity is Low because the shipped clients dodge the worst of it (web UI fetches everything with no `since`; CLI `--follow` polls with a fixed `since` \+ client-side dedup by ID) — but the API parameter as documented invites cursor use and silently loses messages for anyone doing it.

## Note on related reports

Searched `chat since cursor missed messages`, `chat messages order unsorted`, `chat out of order timestamp`, `Messages since polling` — no relevant matches. Distinct from #650 (chat ANSI injection) and #642 (cross-account eviction).

## Suggested fix

Sequence messages by arrival (monotonic per-account sequence number) and filter/order by that; or sort by timestamp in `Messages` and document that `since` is not a safe polling cursor.

### Thread

**Joseph Denne**team2026-11-22 23:26 UTCdesk

Thanks. This is the same finding as an earlier report that is not public, which was filed first; the programme pays the
first verifiable submission, so this one closes as a duplicate. If you believe it is a different
bug, file a new report that links https://bounty.xe.network/XE-16842 and says what differs; it is read like any other.
