Skip to content

fix: add sequence numbers and sender timestamps for message ordering (#7)#15

Open
rafabd1 wants to merge 1 commit intomainfrom
fix/issue-7-message-ordering
Open

fix: add sequence numbers and sender timestamps for message ordering (#7)#15
rafabd1 wants to merge 1 commit intomainfrom
fix/issue-7-message-ordering

Conversation

@rafabd1
Copy link
Owner

@rafabd1 rafabd1 commented Mar 14, 2026

Fix: Add sequence numbers and sender timestamps for message ordering

Closes #7

Problem

Messages had no explicit ordering mechanism. The ratchet counter was used for decryption only, timestamps were generated locally on receive (subject to clock skew), and the frontend rendered messages in array order without sorting.

Solution

Backend:

  • Added seq (monotonic sequence number) and ts (sender unix timestamp) fields to the wire message protocol
  • ActiveSession now tracks send_seq and recv_seq counters
  • On receive, validates sequence ordering and logs out-of-order detection
  • Uses sender's timestamp instead of local time for the message timestamp
  • Fields are serde(default) for backward compatibility

Frontend:

  • ChatWindow now sorts messages by timestamp then by id for deterministic ordering

Security considerations

  • Sequence numbers and timestamps are not used for cryptographic validation — the ratchet counter still enforces that
  • No additional attack surface: these are metadata fields in the already-encrypted stream

This PR was generated with Oz.

)

- Add seq (monotonic sequence number) and ts (sender timestamp) to wire protocol
- Track send_seq/recv_seq on ActiveSession for ordering enforcement
- Detect out-of-order messages on receive side and log warnings
- Use sender timestamp for message display instead of local clock
- Sort messages by timestamp in ChatWindow for consistent ordering
- Backward compatible: seq/ts fields use serde(default)

Co-Authored-By: Oz <oz-agent@warp.dev>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Message ordering issue: No sequence enforcement

1 participant