{"id":"XE-16842","kind":"bounty","visibility":"public","source":"github","source_repo":"xeprotocol/xe","source_ref":"671","source_url":"https://github.com/xeprotocol/xe/issues/671","reporter_id":2920,"title":"[Low] ChatStore.Messages since cursor silently skips out-of-order messages; results returned in arrival order, not timestamp order","area":"node-api","claimed_tier":null,"assessed_tier":null,"verdict":"duplicate","duplicate_of":null,"tracked":false,"internal_ref":"","internal_url":"","status":"closed","closed_reason":"duplicate","github_state":"open","disclosed_at":null,"award_xe":null,"award_approved":false,"paid_ref":"","created_at":"2026-11-17T06:33:15.261071+00:00","updated_at":"2026-11-22T23:26:12.075892+00:00","source_created_at":"2026-11-17T06:33:01+00:00","told_at":"2026-11-22T23:26:12.109565+00:00","status_changed_at":"2026-11-22T23:26:12.082078+00:00","url":"https://bounty.xe.network/XE-16842","body":"## Summary\n\n`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.\n\n## Root cause\n\n`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.\n\n## Verification\n\nExecuted PoC against the real `chat.ChatStore`:\n```\nstore env1 (ts=1000): true\npoll since=0 -> 1 message(s): [id-1 ts=1000]\nstore env2 (ts=999, arrived after env1): true\npoll since=1000 -> 0 message(s)\nBUG 1: env2 arrived after the previous poll but is NEVER returned to a since-based polling client (silently lost forever).\npoll since=0 -> order: [id-1 ts=1000] [id-2 ts=999]\nBUG 2: Messages() returns arrival order, not timestamp order\n```\n\n`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`).\n\n## Impact\n\nSeverity 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.\n\n## Note on related reports\n\nSearched `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).\n\n## Suggested fix\n\nSequence 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.","patch_refs":[],"thread":[{"id":18804,"source":"desk","source_ref":"reply:16481","author":"Joseph Denne","team":true,"body":"Thanks. This is the same finding as an earlier report that is not public, which was filed first; the programme pays the\nfirst verifiable submission, so this one closes as a duplicate. If you believe it is a different\nbug, file a new report that links https://bounty.xe.network/XE-16842 and says what differs; it is read like any other.","created_at":"2026-11-22T23:26:12.075892+00:00"}]}