Text chat 13: core-reactions (#263) #310
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "textchat-13-core-reactions"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What this builds
fluxer-core::chat::reactions(Text chat spec §6.2 "Reactions"), plus reaction events applied to message records inmessages.rs.reactionschange only with server answers and gateway events (MESSAGE_REACTION_ADD,_ADD_MANY,_REMOVE,_REMOVE_EMOJI,_REMOVE_ALL); this user's own reaction is idempotent throughme, so an echo of something the record already shows changes nothing. A click records the wanted state in aReactionOp;selectors::reactionslays it over the record (count without the server'sme, plus one if wanted). An op is dropped once nothing is in flight and the record agrees, and dropping it on failure is the revert. Requests go out one per message at a time, becauseApiResult::ReactionDonenames the message, not the emoji. After a successful request the op waits up toECHO_GRACE(5 s) for its echo, since the gateway drops an add/remove pair that meets inside its 650 ms buffer (gw/session/session_dispatch_voice.erl:42-101).max(2^n s, retry_after)(Effect::Schedule), up to 3 times, then reverted. A 400MAX_REACTIONSbecomesReactionRefusal::TooMany.max_reactions_per_messagefrom the instance limits (default 30). Refusals go toapp.chat.reactions.refusal.RemoveReactionof another user,RemoveAllReactionsby emoji or for all: these need MANAGE_MESSAGES in guilds, are not optimistic (the events clear the row) and use the same retry rule.OpenReactors/LoadMoreReactorsfetch pages of 100 through thenext_aftercursor; stale pages are dropped and duplicates removed. Tooltip names (up to 3) come from reactor pages and gateway events, using nick, then global name, then username.selectors::quick_reactions(&App, n). Frecency first (custom emoji only when a known guild has them), then thumbsup, ok_hand, tada, heart, with the user's skin tone.How it was tested
crates/fluxer-core/tests/chat_reactions.rshas every test the plan names. Before the implementation they failed to compile against the Task 10 stub; with it, they pass:toggle_adds_optimistically_and_sends_put,own_echo_not_double_counted(single andADD_MANY),others_add_many_applies_each(Text chat 2 fixtures),remove_emoji_and_remove_all,failure_reverts,retry_429_backoff_then_revert,new_emoji_needs_add_reactions,existing_emoji_does_not,thirty_emoji_cap,reactors_paging,quick_reactions_defaults_and_frecency, and the proptestany_interleaving_converges_to_server_counts. The proptest runs 512 cases over a model of the server, the gateway's 650 ms add buffer (an add and its remove cancel inside it), the network, and other users' and moderators' actions. It checks that no pill is ever zero or duplicated, and that after settling the row equals the server's state with no op left. Its regression seeds are committed.FLUXER_SCREENSHOT_TESTS=1 cargo xtask cipasses locally. No desktop-only tests apply.Deviations from the plan
tests/chat_ports.rs::stubs_emit_nothing(Text chat 10) now skips the reaction actions, because they have behaviour now. Text chat 11 changes the same test in the same way for the composer, so a merge conflict there is mechanical.chat/mod.rsandselectors/mod.rsonly gain re-exports. They are not in the Files list.ReactionOpsgainsmoderation,refusalandknown.ReactionOpgainssending,echoed,confirmed,retryandgrace.Reactorsgainsnext_after. All of these are additive to the Task 10 types.UserPrivatehas no traits yet (as noted inchat::limits), so only USE_EXTERNAL_EMOJIS is checked, and the server's 4xx reverts the rest.REMOVE_EMOJI/REMOVE_ALL, which affects every client, the original included.+:name:reacting to the last message is in Text chat 11 (plus_react_shorthand_reacts_to_last).Closes #263
🤖 Generated with Claude Code
Independent review: Text chat 13 (reactions)
Reviewed
git diff 53fbd6f..a78a9c6cold:chat/reactions.rs,messages.rs,tests/chat_reactions.rs,tests/chat_ports.rs, re-exports, README.Plan tests: all 12 named tests exist and assert what the plan says. Spec values hold: 429 backoff
max(2^n s, retry_after)for n = 0, 1, 2 (three retries, then revert); 30-emoji cap; reactor pages of 100; quick reactions frecency first, then thumbsup, ok_hand, tada, heart. The proptest runs 512 cases, and its regressions file is committed.Interfaces:
selectors::reactions(&App, channel, message) -> Vec<ReactionModel { emoji: EmojiRef, count, me, tooltip_names }>andselectors::quick_reactions(&App, n) -> Vec<EmojiRef>match the plan exactly.OpenReactors,LoadMoreReactors, ADD_REACTIONS for a new emoji only, USE_EXTERNAL_EMOJIS, the 30-emoji cap, and the 429 retry throughEffect::Scheduleare all present.Reactorsgainsnext_after, and nothing outside the module builds it.Invariants: no new dependency, no I/O, no new fixture (the tests use Text chat 2's gateway and REST fixtures). Server data cannot panic the client: counts saturate, removals never go below the user's own reaction, and the shift is clamped.
Review Focus 1: verified. The record holds only the server's state, and the user's own reaction is idempotent through
me. The optimistic wish is shown over the record and never written into it.chat::reduceruns aftermessages.reduce(app.rs), sosettlesees the record with the echo already applied. Requests go out one per message at a time, which is sound becauseReactionDonecarries no emoji. TheECHO_GRACEdesign also holds: a stale grace timer cannot clear a newerconfirmed, because the timer ids must match.Findings
ReactionOps::knowngets an entry for every reaction event in the session, including messages that were never loaded. Only READY clears it (MESSAGE_DELETE removes one message). Memory grows without bound over a long session. Consider recording users only for loaded messages.follow-upissue.MAX_REACTIONSanswer setsTooMany { max: DEFAULT_MAX_REACTIONS }instead of the resolvedmax_reactions(ctx, channel). The modal shows 30 on an instance with a different limit.UserPrivatehas no traits yet), and custom emoji in DMs are not checked at all. The server's 4xx reverts the reaction, so no data is lost.FLUXER_SCREENSHOT_TESTS=1 cargo xtask cifailed. Theapps/fluxerlib tests passed all 53 tests, then aborted at exit withThe futex facility returned an unexpected error code(SIGABRT). Three direct reruns of that binary and a second full CI run were green, so this looks like an intermittent abort at teardown in the app crate. This PR touches onlyfluxer-core. Abugissue should be opened (I could not open one from here).Local CI:
FLUXER_SCREENSHOT_TESTS=1 cargo xtask cigreen on rerun (all steps passed). The first run hit the flaky abort in finding 5.Verdict: approve. No blocking findings.
Independent review (second pass): Text chat 13 (reactions), head
901849cI reviewed
git diff 9fcc13d..901849ccold in a fresh worktree. It coverschat/reactions.rs,messages.rs,tests/chat_reactions.rs(with the proptest regressions file),tests/chat_ports.rs, the re-exports inchat/mod.rsandselectors/mod.rs, and the README.(1) Plan tests. All 12 named tests exist and check what the plan says:
toggle_adds_optimistically_and_sends_putown_echo_not_double_counted: single echo before the 204,ADD_MANYafter it, and a removal echoothers_add_many_applies_each, which uses Text chat 2'smessage_reaction_add_many.jsonremove_emoji_and_remove_allfailure_revertsretry_429_backoff_then_revertnew_emoji_needs_add_reactionsexisting_emoji_does_notthirty_emoji_capreactors_pagingquick_reactions_defaults_and_frecencyany_interleaving_converges_to_server_counts: 512 cases, regressions file committedThe spec values hold, and I checked the backoff against the original. The 429 wait is
max(2^n s, retry_after)for n = 0..2, which matchesReactionCommands.tsx:249-250(MAX_RETRIES = 3), and the request is reverted after that. The other values: a cap of 30 distinct emoji, reactor pages of 100, and quick reactions frecency first, then thumbsup, ok_hand, tada, heart.(2) Interfaces. These match the plan exactly:
selectors::reactions(&App, channel, message) -> Vec<ReactionModel { emoji: EmojiRef, count, me, tooltip_names: Vec<String> }>selectors::quick_reactions(&App, n) -> Vec<EmojiRef>OpenReactorsandLoadMoreReactorsEffect::ScheduleThe changes to the Task 10 types only add fields, and nothing outside the module builds those types.
(3) Invariants.
min(6), a removal never takes the count below the user's own reaction, and a server count of 0 shows asmax(me).(4) Review Focus 1. Verified. The record holds only the server's state. The user's own reaction is idempotent through
me, which the server computes per viewer (fluxer_messages/src/shard_impl.rs:2964). The user's wish is laid over the record and never written into it.chat::reduceruns aftermessages.reduce(app.rs). Requests go one per message at a time, which is sound becauseReactionDonecarries no emoji. I traced these cases by hand and they converge:ECHO_GRACEexpires(5) CI.
FLUXER_SCREENSHOT_TESTS=1 cargo xtask ciin the review worktree: green (all steps passed) on the second run. The first run failed at theteststep:apps/fluxer --libpassed all 53 tests, then the process died at exit with SIGSEGV. I rerancargo test -p fluxer --libthree times and it passed each time. This diff does not touchapps/fluxer, so this is the known exit-time crash tracked in #338 (filed there as a futex SIGABRT; this time it was SIGSEGV).Findings
400 MAX_REACTIONS,on_failedsetsTooMany { max: DEFAULT_MAX_REACTIONS }instead ofmax_reactions(ctx, channel_id). On an instance with a different limit, the modal shows 30.ctxis already in scope inreduce. This needs afollow-upissue before merge (CLAUDE.md: anything deferred gets its own issue).ECHO_GRACEexpires has no bound. Suppose the record saysme = falsewhile the server already has this user's reaction. A click sendsPUT. The server returns 204 with no event (MessageReactionService.tsaround line 212:if (userReactionExists) return;). Grace expires,needs_requestis true again, and the client sends anotherPUTevery 5 s for as long as the message is loaded. Meanwhile the pill shows count + 1. READY reloads the records and a resume replays missed events, so I could not produce this state with the current server, which is why this is not blocking. A cap on grace-expiry re-sends (say, one) would close it. Suggest folding it into the same follow-up as finding 1.UserPrivatehas no traits yet, and custom emoji in DMs are not checked at all. The server's 4xx reverts the reaction, so no data is lost.MESSAGE_REACTION_ADD,on_gatewaylooks the reactor up inctx.users, butusers.reduceruns afterchat::reduce. A user who first appears in that event, without amember, is not remembered for the tooltip. Cosmetic; it belongs with #337 (tooltip names).#337 and #338 already cover the first review's other minor findings.
Verdict: APPROVE. No blocking findings. Local CI is green (one flaky run from #338 before that).