[client] Reactions and replies: messages named by author and seq, a reply's reference, reactions, Unsupported for newer kinds #21

Closed
mnovak wants to merge 0 commits from feature/reactions into main
Owner

Reactions and replies: messages that can be named, inside MLS. Amicitia F27 (step 2 of its full-chat plan). Analysis: .agents/features/reactions-replies.md. docs/PROTOCOL.md §4 and §7 updated. The relay does not change: no route, no column.

  • A message is named by (author, seq): author is the 16 random bytes already in the author's MLS credential (Author in the protocol crate, 22 characters of base64url), seq the author's own count.
  • text gains an optional replyTo; without it the JSON is unchanged. New payload reaction {to, emoji?}: an emoji sets the sender's one reaction, none removes it. 1–32 bytes, no control characters.
  • The receiver accepts a reference only to a message that exists in that conversation. A bad reaction is dropped; a text with a bad reference keeps its words and loses the reference.
  • A payload of an unknown kind with a seq becomes Event::Unsupported (the app shows update to see this message) and counts for receipts. Today it vanishes without a trace. New fields go into new kinds (§4).
  • Client API: Event::Message gains seq and reply_to; new Event::Reaction and Event::Unsupported; compose_text, react, author, contact_author; ClientError::BadReference. compose is unchanged.
**Reactions and replies: messages that can be named, inside MLS.** Amicitia F27 (step 2 of its full-chat plan). Analysis: `.agents/features/reactions-replies.md`. `docs/PROTOCOL.md` §4 and §7 updated. **The relay does not change**: no route, no column. - A message is named by **(author, seq)**: `author` is the 16 random bytes already in the author's MLS credential (`Author` in the protocol crate, 22 characters of base64url), `seq` the author's own count. - `text` gains an optional `replyTo`; without it the JSON is unchanged. New payload `reaction` `{to, emoji?}`: an emoji sets the sender's one reaction, none removes it. 1–32 bytes, no control characters. - The receiver accepts a reference only to a message that exists in that conversation. A bad reaction is dropped; a text with a bad reference keeps its words and loses the reference. - A payload of an **unknown kind with a `seq`** becomes `Event::Unsupported` (the app shows *update to see this message*) and counts for receipts. Today it vanishes without a trace. New fields go into new kinds (§4). - Client API: `Event::Message` gains `seq` and `reply_to`; new `Event::Reaction` and `Event::Unsupported`; `compose_text`, `react`, `author`, `contact_author`; `ClientError::BadReference`. `compose` is unchanged.
mnovak added 2 commits 2026-11-21 20:04:23 +01:00
mnovak reviewed 2026-11-21 20:04:27 +01:00
mnovak left a comment
Author
Owner

Adversarial self-review — reactions and replies

Evidence

What Result
cargo test --workspace protocol: wire 18 (1 new); client: unit 10 (6 new), block 7, pairing 8, push 3, reactions 5 (new), real_relay 2 (the canary test now also carries a reaction), state 14; relay: unit 2, quotas 8, relay 19, wake 9
clippy -D warnings, cargo fmt --check clean
Planted bugs (mutate_react.py) 20/20 caught: seq 0 accepted; our future seq; their future seq; any author taken for the peer; a bad reply reference kept; a text counted before its reference is checked (a text answering itself); a received bad emoji; a blocked contact's reaction; a received reaction to nothing; control characters; an empty emoji; a long emoji composed; a reply composed to nothing; a reaction composed to nothing; unknown kinds without seq shown; known kinds taken for unknown; Unsupported not counted for receipts; Unsupported from a blocked contact; replyTo always written; our own author taken for the peer's
Privacy canaries the relay's database (real relay) and the memory relay hold no emoji, no reply text, no replyTo/reaction key and no author's wire spelling

Findings

R1–R8 are on their lines.

Not verified

  • The client tests on the Android emulator (they have no I/O and ran there for F24; not re-run for this change).
  • Fuzzing the new payload parser (cargo fuzz is not set up here; the proptest parsers cover the protocol types, not Payload).

Verdict

Merging. Amicitia's app part (storing names, the picker, the quote) is the next PR, in Amicitia.

## Adversarial self-review — reactions and replies ### Evidence | What | Result | |:--|:--| | `cargo test --workspace` | protocol: wire **18** (1 new); client: unit **10** (6 new), block **7**, pairing **8**, push **3**, **reactions 5 (new)**, real_relay **2** (the canary test now also carries a reaction), state **14**; relay: unit **2**, quotas **8**, relay **19**, wake **9** | | clippy `-D warnings`, `cargo fmt --check` | clean | | Planted bugs (`mutate_react.py`) | **20/20 caught**: seq 0 accepted; our future seq; their future seq; any author taken for the peer; a bad reply reference kept; a text counted before its reference is checked (a text answering itself); a received bad emoji; a blocked contact's reaction; a received reaction to nothing; control characters; an empty emoji; a long emoji composed; a reply composed to nothing; a reaction composed to nothing; unknown kinds without `seq` shown; known kinds taken for unknown; Unsupported not counted for receipts; Unsupported from a blocked contact; `replyTo` always written; our own author taken for the peer's | | Privacy canaries | the relay's database (real relay) and the memory relay hold no emoji, no reply text, no `replyTo`/`reaction` key and no author's wire spelling | ### Findings R1–R8 are on their lines. ### Not verified - The client tests on the Android emulator (they have no I/O and ran there for F24; not re-run for this change). - Fuzzing the new payload parser (`cargo fuzz` is not set up here; the proptest parsers cover the protocol types, not `Payload`). ### Verdict Merging. Amicitia's app part (storing names, the picker, the quote) is the next PR, in Amicitia.
@@ -44,2 +44,4 @@
/// The longest text message, in bytes; well under a blob's limit once encrypted.
pub const MAX_TEXT_BYTES: usize = 64 * 1024;
/// The longest reaction, in bytes of UTF-8: the longest emoji ZWJ sequences are 28.
pub const MAX_EMOJI_BYTES: usize = 32;
Author
Owner

R6 — scope. The client checks size and control characters only; it does not check that the text is an emoji. A peer could react with LOL. Accepted: a newer app's emoji must still arrive, and the app can decide how to draw what is not in its picker.

**R6 — scope.** The client checks size and control characters only; it does not check that the text is an emoji. A peer could react with *LOL*. Accepted: a newer app's emoji must still arrive, and the app can decide how to draw what is not in its picker.
@@ -46,0 +46,4 @@
/// The longest reaction, in bytes of UTF-8: the longest emoji ZWJ sequences are 28.
pub const MAX_EMOJI_BYTES: usize = 32;
/// The payload kinds this client knows; any other kind that carries a `seq` is `Unsupported`.
const KNOWN_KINDS: [&str; 5] = ["hello", "text", "receipt", "inbox", "reaction"];
Author
Owner

R7 — test honesty. A variant left out of KNOWN_KINDS would arrive as Unsupported at a client of the same version, silently. every_payload_kind_is_known round-trips every variant through parse_payload, so a new variant without its kind fails the test (added after this finding).

**R7 — test honesty.** A variant left out of `KNOWN_KINDS` would arrive as *Unsupported* at a client of the same version, silently. `every_payload_kind_is_known` round-trips every variant through `parse_payload`, so a new variant without its kind fails the test (added after this finding).
@@ -487,0 +591,4 @@
.ok_or(ClientError::UnknownContact)
}
fn peer_author(&self, index: usize) -> Option<Author> {
Author
Owner

R2 — correctness, for later. The peer is the member that is not us: right for 1:1 groups only. F32 (groups) must replace this with a member lookup by author, or any member's message would pass as the peer's. Noted for F32's analysis.

**R2 — correctness, for later.** The peer is *the member that is not us*: right for 1:1 groups only. F32 (groups) must replace this with a member lookup by author, or any member's message would pass as the peer's. Noted for F32's analysis.
@@ -487,0 +603,4 @@
/// Whether `r` names a message that exists in this conversation: ours up to our last `seq`,
/// theirs up to the highest `seq` received from them.
fn names_a_message(&self, index: usize, r: &MessageRef) -> bool {
Author
Owner

R3 — correctness, accepted. "Exists" means at most the highest seq received, not received: a blob dropped as malformed leaves a hole that a reference can name. The app then shows A message you don't have (full-chat §5.2). A set of every received seq would be exact but grows for ever in the snapshot.

**R3 — correctness, accepted.** "Exists" means *at most the highest seq received*, not *received*: a blob dropped as malformed leaves a hole that a reference can name. The app then shows *A message you don't have* (full-chat §5.2). A set of every received seq would be exact but grows for ever in the snapshot.
@@ -853,1 +991,4 @@
}
// Checked before this text counts, so a text cannot answer itself. The words are
// real even when the reference is not: the text stays, the reference goes.
let reply_to = reply_to.filter(|r| self.names_a_message(index, r));
Author
Owner

R4 — people / correctness. A text with a bad reference keeps its words: the words are real; only the quote is not. Checked before the text counts, so a text cannot answer itself (planted bug caught).

**R4 — people / correctness.** A text with a bad reference keeps its words: the words are real; only the quote is not. Checked *before* the text counts, so a text cannot answer itself (planted bug caught).
@@ -858,0 +1001,4 @@
reply_to,
}))
}
Payload::Reaction { to, emoji } => {
Author
Owner

R5 — correctness. No ordering field: the last reaction received from a person wins. One sender's blobs arrive in order (one mailbox, fetched in order, MLS generations), so last received is last sent. A restart between receive and finish replays the same blobs in the same order.

**R5 — correctness.** No ordering field: the last reaction received from a person wins. One sender's blobs arrive in order (one mailbox, fetched in order, MLS generations), so last received is last sent. A restart between receive and finish replays the same blobs in the same order.
@@ -151,0 +151,4 @@
fixed_bytes!(
/// A message's author: the 16 random bytes in their MLS credential, made on their device, never
/// a name. With the author's `seq` it names a message (`PROTOCOL.md` §4, reactions and replies).
Author,
Author
Owner

R1 — privacy. Author exposes no new fact to anyone: it is the credential identity the peer's MLS already authenticates every message with. It travels only inside MLS (canary: its wire spelling is not on the relay). One identity is shared across all of a person's conversations, as the credential already is: two contacts who compare notes could already tell it is the same app. Stated in the analysis §3.

**R1 — privacy.** `Author` exposes no new fact to anyone: it is the credential identity the peer's MLS already authenticates every message with. It travels only inside MLS (canary: its wire spelling is not on the relay). One identity is shared across all of a person's conversations, as the credential already is: two contacts who compare notes could already tell it is the same app. Stated in the analysis §3.
@@ -58,0 +63,4 @@
two members, a `seq` from 1 up to the last one sent or received); a reaction that names anything
else is dropped, and a text keeps its words but loses the reference.
**Kinds a client does not know** *(2026-11-21)*: one with a `seq` of at least 1 is shown as *update
Author
Owner

R8 — compatibility. A client from before this change drops replies and reactions (deny_unknown_fields on text, no reaction). Nobody runs Amicitia outside development yet. From now on new fields go into new kinds, so older clients show Unsupported instead of losing a message.

**R8 — compatibility.** A client from before this change drops replies and reactions (`deny_unknown_fields` on `text`, no `reaction`). Nobody runs Amicitia outside development yet. From now on new fields go into new kinds, so older clients show *Unsupported* instead of losing a message.
Author
Owner

Merged into main with --no-ff as 056a68de17 (remote hash verified).

Merged into `main` with `--no-ff` as 056a68de173aeb6e2c30e9ffe71381e90f4dc08a (remote hash verified).
mnovak closed this pull request 2026-11-21 20:05:24 +01:00
Some checks are pending
ci / check (pull_request) Has been cancelled

Pull request closed

Sign in to join this conversation.