Repository navigation
Conversation
…t route the server refuses, and the test expects it sealed with an echo that lands (red)
…ack onto the message
…folds rebuilt in the server's order, owed reactions applied when their message lands, and a reaction that cannot open yet is folded again
Tiny Code Reviewthe AI provider rate-limited the request This is advice, not a gate. Re-run with the |
There was a problem hiding this comment.
Tiny Code Review
🟡 1 finding (0 blocking).
The sealed-reaction design is coherent: a new Kind::Reaction envelope carried over the server's encrypted reactions route, AAD bound to the conversation it was posted to, a per-device fold for counts, and kept own-post rows so a device's own echo lands without MLS. Wire compatibility is preserved (on is Option with default and skipped on the wire; message/edit bytes unchanged), the plaintext route is gone with no fallback, and tests cover the envelope, the AAD binding, the repair case, and the end-to-end fold. I found one real gap: a reaction sent to a message this device has not yet stored is silently dropped from the UI until a later page fetch, because the apply failure is not kept owed the way the echo path does.
Residual risk
- Each
e2ee.reactionsocket event spawns a fresh thread that takes the device mutex and does network list fetches; a server flooding events could spawn many threads and stall other device users. Existing handlers follow the same shape, so this is not new to this diff's pattern. - If the server's POST answer omits
id,reactkeys the kept row under an empty blob id (reaction.), so the device's own echo would not fold; real servers return an id. apply_reactionrejects non-emojilanded.emojiby returning false, which keeps the pair pending forever rather than dropping it; pending is bounded by (message, emoji) pairs.- Fold counts are per-device; a conversation that previously had plaintext reactions will show those chips replaced by the fold, as the docs now state.
| match result { | ||
| Ok((device, landed)) => { | ||
| drop(device); | ||
| if let Some(landed) = landed { |
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
There was a problem hiding this comment.
Fixed as suggested: the sealed react arm now settles the pair owed on the same held lock when apply_reaction reports the message is not stored (messages.rs, the Ok((device, landed)) arm — Device::settle_reactions(conversation_id, &[], &owed)) before the Ok reply. The later echo still adds nothing new, but the owed pair is applied when the message lands (the message.created arm drains it via owe_reactions) or the next page does.
itz4blitz
left a comment
There was a problem hiding this comment.
Requesting changes. The security side reads sound, but sealed reactions do not persist. Everything below is from reading the code path end to end at the PR head; nothing was built or run, and line numbers are approximate.
Blocking
-
Reopening a conversation wipes the chips.
fetch_pageinmessages.rs(~1426-1445) callsctx.historywith rows mapped from the wire, which carry no reactions for sealed messages.Store::ingest(store.rs~2218-2234) replaces the stored body, andreaction_changesonly returns pairs changed in that pass, so nothing is re-applied. Backfill runs on every newest-page open and after handshakes, so this is the normal path. -
Other people's reactions do not survive a restart. Folds are memory-only (
e2ee.rs~1078) and only our own blobs are kept. On restartfold_listre-decrypts every historical blob fromafter=0, but each key is already spent (messaging.rs~319-329 returnsUndecryptable). If Ada and Bea both reacted, Ada's count goes back to 1 after she restarts, and with (1) Bea's chip is gone for good. It also adds up to 800 failed decrypts per launch, each with a checkpoint restore and group reload under the device lock, on top of theSecretReuseErrorlines already in the logs. -
"Retry" never retries.
fold_listsetsfold.at = newest(~2926) even whenfold_onereturnedRetry(~2970). A reaction that arrives before its commit is processed is skipped until restart, which contradicts the I3 claim in the description.
Non-blocking
- Pending pairs never expire: a member can post invalid emoji or unknown message ids, and
owe_reactionsretries them on the socket thread under the device lock on every message. - The swept-kept pass (~2877-2892) runs after a list capped at 800, iterates in uuid order rather than time order, and applies one row per pair per call, so an add and a take-back can flip. Plausible, not confirmed.
- If the server's answer lacks
id, the fold marks""as seen and nothing is persisted.
Checked and sound
- The reactor is taken from the MLS credential, not the payload, so A cannot react as B.
- The authenticated data binds kind and conversation.
- There is no plaintext fallback: the sealed arm returns and
react_generationis gone. - The decoder is strict and size-capped.
- Old clients drop the unknown event and an old server's 404 is handled.
Tests
The tests do exercise the sealed route and would fail on main, but none covers the three blockers: the "restart" case only clears Ada's own fold, and there is no receiver restart, no refetch after a reaction, and no Retry case. Please add those three, and get the lab scenario to run (there is no e2e-proof status on this PR).
…ursor and owed pairs are kept sealed beside the cache, a blob that cannot open yet holds the cursor until it opens or its tries run out, and a restart neither refolds history nor loses a count
Re: review round — all findings addressed (head
|
There was a problem hiding this comment.
Tiny Code Review
🟡 2 findings (0 blocking).
The sealed-reaction design is sound: reactions ride as MLS application messages with conversation-binding AAD, the envelope's new on word is serde-defaulted and left off messages/edits so wire bytes are unchanged, and tests cover the binding, the retry and the round trip. Two real defects remain: the fold state grows without any cap and is re-appended in full on every fold, and the socket thread now takes the device mutex on every incoming message of an encrypted conversation, which the same diff itself avoids for e2ee.reaction.
Residual risk
- The
e2ee.reactionhandler drops the spawned thread's JoinHandle and silently loses the fold nudge if the spawn fails; the next page fetch recovers it. - An empty
onentry is left inFoldState.onwhen the last reactor of a pair takes it back, so the map slowly accumulates dead keys. keep_reactedinDevicecallsself.cache(...)twice (two lock acquisitions) where one would do.
| #[derive(Clone, Default, PartialEq, Serialize, Deserialize)] | ||
| pub(crate) struct FoldState { | ||
| at: i64, | ||
| seen: BTreeSet<String>, |
There was a problem hiding this comment.
🟠 Major
Every reaction blob id ever folded is kept in seen forever and in memory, and set_fold re-appends the whole FoldState (all seen ids, all on sets, all pending pairs) as one sealed line to cache-{conv}.log on every fold. A busy conversation's cache file grows roughly quadratically in the number of reactions ever posted and is never compacted, and the in-memory seen set grows without bound for as long as chatd runs — a disk- and memory-growth hazard driven by how much the network sends.
Why this diff causes it: FoldState has at, seen: BTreeSet<String>, pending, on with no size cap; set_fold calls write_sealed(key, "reactionfold", state) which appends the full serialized state each time; apply and the fold loop only ever insert into seen, nothing prunes it.
Smallest fix: Cap the persisted state: keep seen only for ids at or above at minus a window (or drop ids older than the server's list can still return, since the after cursor already prevents refetching), and prune empty on/pending entries in apply/settle. Add a test that folding N blobs keeps the persisted line bounded.
| } else { | ||
| deliver(ctx, saved, names, &conversation, &wire); | ||
| } | ||
| owe_reactions(ctx, saved, &conversation); |
There was a problem hiding this comment.
🟠 Major
This runs inline in on_live's message.created branch, i.e. on the socket's thread, and takes the device's std::sync::Mutex. That mutex is held across network I/O during syncs and repairs (operation_deadline exists for exactly that), so a repair in flight can stall the receive socket for every incoming message of an encrypted conversation. The same diff explicitly moves the identical work off the socket thread in the e2ee.reaction branch ('Off the socket's thread: the event only says the server's list moved'), so the two paths disagree.
Why this diff causes it: The e2ee.reaction arm spawns a tiny-e2ee thread before calling owed_reactions/settle_reactions, while owe_reactions locks device.lock() directly on the live path, and fetch_page also folds while holding the lock but on a worker.
Smallest fix: In the message.created branch, do what the e2ee.reaction arm does: hand conversation_id and a cloned ctx to a spawned tiny-e2ee thread (or a single fold worker) that locks the device and applies the owed reactions, instead of locking on the socket thread.
…led and fold onto the message
…ad of appended whole and keeps only what the cursor can still deliver, a blob that cannot open three folds is skipped for this session and the first fold after a restart steps back below it, the reaction list is paged without the device mutex held and a page applies only while the cursor still stands where it was asked for, rows without an id move the cursor so a page of them is never asked for twice, and a taken-back reaction leaves no empty entry behind
|
Addressed the last remaining review finding in \7ef2a8f4:
All blocking findings from the earlier review round (\18fb2a29, \ |
What changed and why
A reaction in an encrypted Tiny conversation was refused: the sealed send path asked the plaintext reactions route (
PUT/DELETE /v1/messages/{id}/reactions), which the server answers with400 e2ee_requiredfor any encrypted message, and the client never called the server's encrypted route (POST/GET /v1/e2ee/conversations/{id}/reactions). The receive side had no arm for the server'se2ee.reactionevent either, so nothing could have merged even if it had gone out. Fixes #234.The sealed design. A reaction is now a ciphertext of its own, opaque to the server: the envelope gains
Kind::Reactioncarryingtext= emoji,reply_to= target message id and a newonword (never serialized for messages or edits, so their wire bytes are unchanged). The ciphertext rides in the group the conversation serves now while its authenticated data names the conversation it was posted to (encrypt_in/decrypt_in) — after a repair the two ids differ, and the server checks both words at once, so a reaction can never be replayed onto another conversation that shares the group. Each device folds every blob it can open, in the server's list order, into who-is-on-each-(message, emoji); taking a reaction back posts another blob withon: false(the encrypted route has no delete). Counts are the device's fold, not a server word.The fold is durable (review round two). Reaction chips live in the store's message rows, like every plaintext network's, written as blobs fold. The fold's bookkeeping — cursor, seen blobs, owed pairs, the on-map — persists as a sealed
reactionfoldrow in the conversation's sealed cache (the same sealed append-only file that keeps own-post rows), so a restart continues from the device's cursor instead of re-opening historical blobs, whose keys forward secrecy has already spent. Two consequences, both covered by tests: a fetched page cannot wipe stored chips (a sealed wire row never carries reactions;Store::ingestkeeps what a sealed row's store body folded), and a blob that cannot open yet holds the cursor — retried each fold, never skipped — until it opens or a bounded per-process budget gives up on it. Pairs whose message was not stored yet are kept owed and applied when the message lands or the next page does; pairs are validated at fold time and unclaimed ones are dropped after a bounded number of keeps.Review findings (round one) and their resolutions
r-<uuid>(38 chars); both fakes enforce the real rule (empty / >64 / control chars →400 invalid), and the repair fake answers uuid-shaped idsKeptReactiongained the blob'sseq); restart assertion in the regression testNoGroup/NotAMember-class marks seen; everything else retries — and since review round two, holds the cursor while it does (Blocking 3)reactarm discarded an unapplied pairOk(reply)decodemirrorsencode: no target, noon, or an attachment along is not a reactiontracing::debug!on every retryable open failure, same shape as the message pathfold.seenis aBTreeSetReview round two (durable fold) — findings and tests
Store::ingestkeeps storedreactionsforSeal::Encryptedrows whose wire carries none (a sealed wire row never can); chosen over a re-apply hook because it has no coupling to fold state at ingest time and keepsStored::Samededup. Test:a_conversation_reopened_keeps_its_sealed_reaction_chipsa_restarted_device_still_sees_the_reaction_counts— restart, one catch-up ask, counts intact, and a new reaction folds immediately (a lost cursor would stall behind the spent old blob)Retryblob; a bounded budget (MAX_REACTION_RETRIES = 3, per process) gives up so it cannot hold the cursor forever; a restart grants a fresh budget. Test:a_reaction_that_cannot_open_yet_is_retried_when_its_epoch_arrives— a third person's join moves the group to epoch 2; the blob folds only after Bea catches up, and the fake's log shows it asked for twicereactarm discarded an unapplied pairOkreply, like echo and pageAccepted pushback on the two-device repair ceremony
The generation-1 flow test runs
Device::reactaftersubmit_repairand the fake checks the real MLS words on the reaction ciphertext (group = the binding's group, AAD names the conversation), plus an engine-level split proof (crates/e2ee/tests/reaction.rs) and a receiver-sideAadMismatchproof with a real receiver (groups.rs). A full two-device repair ceremony ine2ee/fake.rswas not built: aftersubmit_repair, the second device must adopt the canonical binding from the/generationslisting rather than submit its own (two client-constructed bindings for one generation disagree, and the client refuses a mismatched receipt) — faking that faithfully would mean reverse-engineering the engine's adoption flow and testing assumptions instead of the product. The coverage above is equivalent.Type
Platforms
The change is desktop chatd only (the phone proof build does not run desktop chatd; the scenario says why it is not applicable there).
Proof
Scenario: e2e/scenarios/tiny-e2ee-reaction
Lab run: attempted from this checkout; blocked on the lab actor token (see the Lab paragraph below).
Compatibility
onfield inside the encrypted plaintext, written for reactions only; older decoders ignore unknown fields, and messages/edits are byte-identical to before.e2ee.reactionevents and never posts reactions itself, so nothing changes for it; the server still refuses its plaintext reactions, so no downgrade path exists.Risk and rollback
The riskiest surface is the fold and its persistence. A wrong fold shows a wrong chip; the fold is rebuilt from the server's blob list at any time and the chips live in the store, so a revert of this pull request restores the previous behaviour (reactions refused in encrypted conversations) without data damage. No setting, no server deploy, squash-revert is enough.
Lab
Attempted
python e2e/lab/lab.py pr 259 --platforms windows,linuxfrom this checkout; blocked the same way as #257 — the lab needs its actor's token (gh auth token --user itz4blitz) and this machine'sghis signed in as a different account, solab.pyfails before it reaches any host:No
e2e-lab/*ore2e-proofstatus could be posted from this side. Local evidence already recorded:crates/chatd/src/main.rsatorigin/mainhas notiny-e2ee-reactionarm (0 mentions), so a base build ignoresTINYCLIENT_PROVE=tiny-e2ee-reaction, keeps serving, and the driver's 90 s wait expires — exit 1. The same mechanism thekeycap-reactionandfirst-encrypted-messagedrivers document.chatdbinary against the in-process MLS fake (which refuses plaintext reactions with400 e2ee_requiredexactly as the real server does) and exits 0 —[ok] a sealed reaction lands and echoes back,prove-exit:0,steps.jsonlwritten.That didn't work. Check it and try again.) and passes on this branch.Release note
Reactions work in encrypted Tiny conversations: they go out sealed, survive a restart and a reopened conversation, and taking one back works too.