8.2 KiB
Polls — three payloads, and a poll the client keeps (PROTOCOL.md §4)
Amicitia F28, step 3 of its full-chat plan (Amicitia/.agents/features/full-chat.md §2). Everything
here is inside MLS: the relay's view (§5, §8) does not change. No new route, no new column.
1. Why and what
Where shall we eat — the Italian place or the Thai one? A chat people move to lets them ask a question with a few answers, lets everyone vote and change their vote, and shows who chose what. The person who asked closes it, and from then on the result is the same on every device.
So this change adds:
poll, a message (it has aseq, so it can be replied to and reacted to, and a receipt covers it): a question, 2–10 options, single or multiple choice;vote, a member's choices in a poll, replacing their earlier vote; no choices takes it back;pollClose, sent by the asker only: the poll is closed, and these are the final votes.
2. Design
sequenceDiagram
participant A as Anna's app
participant C as Client (Anna)
participant R as Relay
participant D as Client (Ben)
participant B as Ben's app
A->>C: compose_poll(ben, "Where?", ["Italian","Thai"], false) → seq 8
C->>R: {"kind":"poll","seq":8,"question":"Where?","options":["Italian","Thai"],"multiple":false}
R->>D: fetch
D->>B: Poll{seq 8, …}; D remembers (Anna, 8): 2 options, single choice, open
B->>D: vote(anna, (Anna, 8), [1])
D->>R: {"kind":"vote","poll":{"author":"…","seq":8},"choices":[1]}
R->>C: fetch
C->>A: Vote{poll (Anna, 8), choices [1]}
A->>C: close_poll(ben, (Anna, 8))
C->>R: {"kind":"pollClose","poll":{…},"ballots":[{"author":"<Ben>","choices":[1]}]}
R->>D: fetch
D->>B: PollClosed{poll, ballots}: the final result
2.1 The payloads
{"kind":"poll","seq":8,"question":"Where?","options":["Italian","Thai"],"multiple":false}
{"kind":"vote","poll":{"author":"<22 chars>","seq":8},"choices":[1]}
{"kind":"vote","poll":{"author":"<22 chars>","seq":8},"choices":[]}
{"kind":"pollClose","poll":{"author":"<22 chars>","seq":8},"ballots":[{"author":"<22 chars>","choices":[1]}]}
poll:question1–300 characters,options2–10 of 1–100 characters each, all different; none blank, none with a control character.multiplesays whether a vote may hold several choices. It shares the sender's oneseqcounter withtext.vote:choicesare indexes intooptions, ascending, each once; withmultiplefalse, at most one.[]takes the vote back. A vote replaces the sender's earlier one in that poll. Noseq.pollClose: only the poll's author may send it.ballotsare the votes the author's client had accepted when it closed, one per member who has a vote (an empty vote is left out). Noseq.
2.2 Why the close carries the votes
Without them two devices can disagree for ever: Ben votes while Anna closes; Anna's client receives
the vote after its close and drops it, Ben's app counted it. With ballots, the result after a close
is what the asker's device saw, and every device shows that. A vote that crossed the close is not
counted anywhere, and Ben's app sees that his vote is not in the result.
2.3 What the client keeps
For each conversation, the polls in it: who asked and the seq, how many options, multiple,
whether it is closed, and each member's current choices (at most two in a 1:1 chat). This goes into
the snapshot (polls, absent in older snapshots, so SNAPSHOT_VERSION stays 1). With it the client
— not each app — decides whether a vote or a close makes sense, and the close's ballots come from
what it accepted, not from the app.
2.4 What the receiving client checks
| Received | Dropped when | Otherwise |
|---|---|---|
poll |
a field over its limit, fewer than 2 or more than 10 options, a blank or repeated option, a control character | Event::Poll; remembered; its seq counts like a text's |
vote |
the poll is not one it remembers in this conversation, or is closed; a choice out of range, repeated, not ascending; two choices in a single-choice poll | Event::Vote; replaces the sender's choices |
pollClose |
the sender is not the poll's author; the poll is unknown or already closed; a ballot by someone not in the conversation, twice for one person, empty, or invalid as a vote | Event::PollClosed with the ballots; the poll is closed, its votes are the ballots |
| Blocked contacts' polls, votes and closes are dropped, as their texts are. Sending checks the same | ||
rules and refuses with ClientError::BadPoll (a malformed poll or vote, a poll that is not ours to |
||
close) or ClientError::PollClosed. |
2.5 The client's API (Amicitia pins it)
compose_poll(contact, question, options: &[String], multiple) -> Outgoing;sent_seqnames it.vote(contact, poll: MessageRef, choices: &[u8]) -> Outgoing.close_poll(contact, poll: MessageRef) -> Outgoing; only our own poll.Event::Poll { contact, seq, question, options, multiple },Event::Vote { contact, poll, choices },Event::PollClosed { contact, poll, ballots: Vec<Ballot> };Ballot { author, choices }.- Constants
MIN_POLL_OPTIONS2,MAX_POLL_OPTIONS10,MAX_OPTION_CHARS100,MAX_QUESTION_CHARS300.
2.6 An older client
A client from F27 does not know these kinds: a poll (it has a seq) shows as Update Amicitia to
see this message; a vote and a pollClose (no seq) are dropped. That is F27's rule working.
3. Risks
- Privacy: the two members learn the question, the options and who voted for what — there is no anonymous poll: MLS authenticates every sender, so an anonymous vote could not be honest. The app says Everyone in this chat sees who voted for what on the poll. The relay sees three more kinds of blob, sized like short texts; the close's size grows with the number of votes (§5's note on sizes; padding is G41's later work).
- Integrity: only a member can vote (MLS), only for themselves (a vote has no author field: it is the sender's), only the asker can close, and the close can only name members.
- Snapshot growth: a few dozen bytes per poll, kept while the conversation exists.
- Events (Amicitia): none — votes and closes are not check-ins; a poll is a message like a text.
- Offline: staged as every payload; the app delivers them in order (F27's
deliver_older).
4. Gaps and designed solutions
| Gap | Design |
|---|---|
| A vote and a close cross | The close carries the ballots (§2.2) |
| The app could invent a close's result | The client fills ballots from what it accepted (§2.3) |
| A poll from before the client kept polls (none exist: nobody sent one) | — |
| Polls in groups (F32): more members, more ballots | Ballot already names its author; F32 checks membership against the roster |
| The close's size reveals roughly how many voted | Up to two ballots in 1:1; G41's padding later |
A peer reuses the seq of an earlier text for a poll, so one name means two messages (texts allow it too) |
Later, for every kind with a seq at once: refuse a seq at or below the highest received, with care for a blob fetched again after a crash |
5. Verification
| Case | Test |
|---|---|
A poll arrives with its seq, question, options and multiple; a receipt covers it |
client/tests/polls.rs |
| A vote is set, replaced and taken back; both sides' own and their votes | same |
| A close carries the ballots the asker had, and the result is the same on both sides | same |
| A vote that crosses the close is not in the result anywhere | same |
| Only the asker closes; a vote or a second close after the close is refused and dropped | same + unit |
| Malformed polls, votes and closes are refused when sending and dropped when received | unit through receive_payload |
| A blocked contact's poll and vote are dropped | unit |
| The poll survives a snapshot and restore, closed or open, with its votes | client/tests/polls.rs |
| An F27 client shows a poll as Unsupported | F27's rule, its own test (a_newer_apps_message_is_unsupported_and_counts_for_receipts, now with file as the newer kind) |
| The relay's database holds no question and no option (canary; a choice is a small number, which no canary can find) | real_relay.rs |
| Planted bugs | the review |