Bounty
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 filed 2026-11-17 06:33 UTC by kecedanzz77-bit

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 Denneteam2026-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.