[client] Polls: poll, vote and pollClose inside MLS — a poll is a message, only the asker closes, the close carries the final votes #22

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

Polls: three payloads inside MLS. Amicitia F28 (step 3 of its full-chat plan). Analysis: .agents/features/polls.md. docs/PROTOCOL.md §4 and §7 updated. The relay does not change: no route, no column.

  • poll {seq, question, options, multiple} is a message: it shares seq with text, so it can be replied to, reacted to and covered by a receipt. 1–300 characters of question, 2–10 different answers of 1–100, none blank, no control characters.
  • vote {poll, choices}: indexes, ascending, each once, at most one unless multiple; it replaces the sender's earlier vote, [] takes it back. No seq.
  • pollClose {poll, ballots}: only the poll's author. It carries the final votes as the author's client accepted them, so a vote that crosses the close counts nowhere and both devices show the same result.
  • The client keeps each conversation's polls in the snapshot (polls, absent in older snapshots; SNAPSHOT_VERSION stays 1), so it decides which votes and closes make sense, and the close's ballots come from what it accepted, not from the app.
  • Client API: compose_poll, vote, close_poll; Event::Poll, Event::Vote, Event::PollClosed, Ballot; ClientError::BadPoll, ClientError::PollClosed; limits as constants.
  • An F27 client shows a poll as Update Amicitia to see this message and drops votes and closes (no seq): F27's rule.
**Polls: three payloads inside MLS.** Amicitia F28 (step 3 of its full-chat plan). Analysis: `.agents/features/polls.md`. `docs/PROTOCOL.md` §4 and §7 updated. **The relay does not change**: no route, no column. - `poll` `{seq, question, options, multiple}` is a message: it shares `seq` with `text`, so it can be replied to, reacted to and covered by a receipt. 1–300 characters of question, 2–10 different answers of 1–100, none blank, no control characters. - `vote` `{poll, choices}`: indexes, ascending, each once, at most one unless `multiple`; it replaces the sender's earlier vote, `[]` takes it back. No `seq`. - `pollClose` `{poll, ballots}`: only the poll's author. **It carries the final votes** as the author's client accepted them, so a vote that crosses the close counts nowhere and both devices show the same result. - The client keeps each conversation's polls in the snapshot (`polls`, absent in older snapshots; `SNAPSHOT_VERSION` stays 1), so it decides which votes and closes make sense, and the close's ballots come from what it accepted, not from the app. - Client API: `compose_poll`, `vote`, `close_poll`; `Event::Poll`, `Event::Vote`, `Event::PollClosed`, `Ballot`; `ClientError::BadPoll`, `ClientError::PollClosed`; limits as constants. - An F27 client shows a poll as *Update Amicitia to see this message* and drops votes and closes (no `seq`): F27's rule.
mnovak added 2 commits 2026-11-22 10:38:46 +01:00
mnovak reviewed 2026-11-22 10:38:46 +01:00
mnovak left a comment
Author
Owner

Adversarial self-review — polls

Evidence

What Result
cargo test --workspace protocol: wire 18; client: unit 14 (4 new), block 7, pairing 8, polls 4 (new), push 3, reactions 5, real_relay 2, state 14; relay: unit 2, quotas 8, relay 19, wake 9
clippy --workspace --all-targets -D warnings clean
cargo fmt --all --check clean
Planted bugs (30, each alone, client tests) 30/30 caught — choice range, order, single choice, replace vs add, empty ballot, 1 and 11 answers, a repeated answer, a blank question, our vote or close after the close, our vote or close not remembered, closing their poll, closing twice, a close without ballots, a blocked contact's poll, an over-long or malformed received poll, two polls under one name, a poll not counted for receipts, their vote after the close, their bad vote, their vote not remembered, them closing ours, a stranger's / repeated / empty ballot, a second close, the close's ballots not taken, pollClose missing from the known kinds
Privacy canary a poll's question and both answers are not readable in the relay's database while waiting or after (real_relay.rs)

Findings

F1–F6 are on their lines.

Not verified

  • Polls in groups (F32): ballots name their author already, but membership is the other member (peer_author), as F27's references.
  • The Android emulator run of the client tests (no I/O, should run as F27's did).

Verdict

Merging. Next: Amicitia F28 (create, vote, results, close) pins the merge.

## Adversarial self-review — polls ### Evidence | What | Result | |:--|:--| | `cargo test --workspace` | protocol: wire **18**; client: unit **14** (4 new), block **7**, pairing **8**, polls **4** (new), push **3**, reactions **5**, real_relay **2**, state **14**; relay: unit **2**, quotas **8**, relay **19**, wake **9** | | clippy `--workspace --all-targets -D warnings` | clean | | `cargo fmt --all --check` | clean | | Planted bugs (30, each alone, client tests) | **30/30 caught** — choice range, order, single choice, replace vs add, empty ballot, 1 and 11 answers, a repeated answer, a blank question, our vote or close after the close, our vote or close not remembered, closing their poll, closing twice, a close without ballots, a blocked contact's poll, an over-long or malformed received poll, two polls under one name, a poll not counted for receipts, their vote after the close, their bad vote, their vote not remembered, them closing ours, a stranger's / repeated / empty ballot, a second close, the close's ballots not taken, `pollClose` missing from the known kinds | | Privacy canary | a poll's question and both answers are not readable in the relay's database while waiting or after (`real_relay.rs`) | ### Findings F1–F6 are on their lines. ### Not verified - Polls in groups (F32): ballots name their author already, but membership is *the other member* (`peer_author`), as F27's references. - The Android emulator run of the client tests (no I/O, should run as F27's did). ### Verdict Merging. Next: Amicitia F28 (create, vote, results, close) pins the merge.
@@ -214,0 +266,4 @@
/// A poll in a conversation, as this client accepted it (`.agents/features/polls.md` §2.3).
#[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub(crate) struct PollState {
Author
Owner

F4 — scope / growth. One PollState per poll, kept as long as the conversation (a few dozen bytes, plus up to two ballots in 1:1). No pruning: a closed poll is still needed to refuse a late vote. forget_contact drops them with the contact.

**F4 — scope / growth.** One `PollState` per poll, kept as long as the conversation (a few dozen bytes, plus up to two ballots in 1:1). No pruning: a closed poll is still needed to refuse a late vote. `forget_contact` drops them with the contact.
@@ -576,0 +783,4 @@
&mut c.group,
&Payload::PollClose {
poll,
ballots: c.polls[p].ballots.clone(),
Author
Owner

F1 — correctness (designed, not a bug found late). Without the ballots, a vote and a close that cross leave the two devices disagreeing for ever: the asker's client drops the late vote, the voter's app counted it. The close carries what the asker's client accepted, and the receiver replaces its votes with them. Test: a_vote_that_crosses_the_close_is_counted_nowhere; planted our close carries no ballots and the close's ballots not taken are caught.

**F1 — correctness (designed, not a bug found late).** Without the ballots, a vote and a close that cross leave the two devices disagreeing for ever: the asker's client drops the late vote, the voter's app counted it. The close carries what the asker's client accepted, and the receiver replaces its votes with them. Test: `a_vote_that_crosses_the_close_is_counted_nowhere`; planted *our close carries no ballots* and *the close's ballots not taken* are caught.
@@ -1058,0 +1298,4 @@
};
let name = MessageRef { author, seq };
let c = &mut self.contacts[index];
let fits = question.chars().count() <= MAX_QUESTION_CHARS
Author
Owner

F3 — correctness, accepted. A malformed poll is dropped and its seq does not count, so a receipt for it waits until their next message. Same as a blob that does not parse. The sender's app shows it not delivered until then, not lost.

**F3 — correctness, accepted.** A malformed poll is dropped and its `seq` does not count, so a receipt for it waits until their next message. Same as a blob that does not parse. The sender's app shows it *not delivered* until then, not *lost*.
@@ -1058,0 +1306,4 @@
|| seq == 0
|| !fits
|| !poll_ok(&question, &options)
|| c.polls.iter().any(|p| p.poll == name)
Author
Owner

F2 — correctness, accepted. A poll is refused under a name a poll already has, but not under the seq of an earlier text: a misbehaving peer (MLS-authenticated, so only the other member) could reuse a seq and make one name point at two messages. Texts have the same property today. The fix belongs to every kind with a seq at once (seq > received_seq), with care for blobs fetched again after a crash; recorded in the analysis §4 as later work.

**F2 — correctness, accepted.** A poll is refused under a name a poll already has, but not under the `seq` of an earlier *text*: a misbehaving peer (MLS-authenticated, so only the other member) could reuse a `seq` and make one name point at two messages. Texts have the same property today. The fix belongs to every kind with a `seq` at once (`seq` > `received_seq`), with care for blobs fetched again after a crash; recorded in the analysis §4 as later work.
@@ -1058,0 +1361,4 @@
/// The contact closed their own poll: its votes become the close's ballots, if each is a
/// member's, once, and a valid vote.
fn receive_close(
Author
Owner

F5 — integrity. Only the poll's author closes (poll.author == peer), and each ballot must be by a member, once, non-empty, and a valid vote for that poll. A peer cannot close our poll or put words in our mouth beyond our own accepted vote… except that the close names our choices as they saw them: a peer could report our vote differently in their close. It is their poll's result as they show it; our own app also shows it. Accepted for 1:1; F32 should show your vote was counted as … if it differs.

**F5 — integrity.** Only the poll's author closes (`poll.author == peer`), and each ballot must be by a member, once, non-empty, and a valid vote for that poll. A peer cannot close our poll or put words in our mouth beyond our own accepted vote… except that the **close names our choices as they saw them**: a peer could report our vote differently in their close. It is their poll's result as they show it; our own app also shows it. Accepted for 1:1; F32 should show *your vote was counted as …* if it differs.
@@ -55,1 +55,4 @@
| `reaction` *(2026-11-21)* | `to`, `emoji`? | the sender's reaction to the message `to`: `emoji` (1–32 bytes of UTF-8, no control characters) sets it, replacing their earlier one; absent removes it. No `seq` |
| `poll` *(2026-11-22)* | `seq`, `question`, `options`, `multiple` | a message (it shares `seq` with `text`): a question of 1–300 characters and 2–10 different options of 1–100, none blank, no control characters; `multiple` allows several choices in a vote |
| `vote` *(2026-11-22)* | `poll`, `choices` | the sender's choices in the poll `poll` names, replacing their earlier ones: indexes into `options`, ascending, each once, at most one unless `multiple`; `[]` takes the vote back. Refused once the poll is closed. No `seq` |
| `pollClose` *(2026-11-22)* | `poll`, `ballots` | sent by the poll's author only: the poll is closed, and `ballots` (`{author, choices}`, one per member with a non-empty vote) are **the final votes**, as the author's client had accepted them, so a vote that crossed the close counts nowhere. No `seq` |
Author
Owner

F6 — privacy. Members learn who voted for what: there is no anonymous poll (MLS authenticates every sender), and the app says so on every poll. The relay sees three more kinds of blob, sized like short texts; a close grows with the number of ballots (at most two in 1:1), which G41's padding covers later.

**F6 — privacy.** Members learn who voted for what: there is no anonymous poll (MLS authenticates every sender), and the app says so on every poll. The relay sees three more kinds of blob, sized like short texts; a close grows with the number of ballots (at most two in 1:1), which G41's padding covers later.
mnovak added 1 commit 2026-11-22 10:38:47 +01:00
Author
Owner

Merged into main with --no-ff as 4d0dac0591 (remote hash verified).

Merged into `main` with `--no-ff` as 4d0dac059143198fab55529c8bde1e75dd1859e7 (remote hash verified).
mnovak closed this pull request 2026-11-22 10:39:02 +01:00
Some checks are pending
ci / check (pull_request) Has been cancelled

Pull request closed

Sign in to join this conversation.