Text chat 14: core expressions (#264) #312
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "textchat-14-core-expressions"
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-coreexpressions (spec §6.2 "Expressions"), inchat/expressions.rs:READY/GUILD_CREATE/GUILD_SYNC, replaced byGUILD_EMOJIS_UPDATE/GUILD_STICKERS_UPDATE.selectors::usable(&App, &EmojiRef, channel) -> Usability::{Yes, NeedsPremium, NeedsPermission}(ascheckEmojiAvailability).selectors::emoji_picker(Favorited, Frequently used top 42, guild sections in guild order, Unicode categories; merged search),sticker_picker,meme_picker,gif_picker.ApiRequest::PatchUserSettings) on top of the last snapshot so every other field stays byte for byte; replaced by another client'sUSER_SETTINGS_UPDATE. Soundboard favourites (#92) synced through the same preferences.Effect::Schedule, featured cached per session,register-shareon pick, auto-send or append with Shift. Stickers send alone or wait with text. Saved media fromREADY.favorite_memesandFAVORITE_MEME_*events.How it was tested
crates/fluxer-core/tests/chat_expressions.rs: the 15 tests named in the plan, written first and seen failing, then passing.FLUXER_SCREENSHOT_TESTS=1 cargo xtask cigreen locally after merging the currentorigin/textchat.Deviations from the plan
fluxer-proto:ReadyPayload.favorite_memesadded (shaped fromfluxer_api/src/api/rpc/RpcService.ts:1164, read by the original inGatewayReady.ts:150), so saved media arrive with READY. Small, own commit.guilds.rsuntouched: guild emoji/stickers are held inchat.expressions(guild_emojis/guild_stickers).session.rskeeps the instance's GIF provider config for the picker's attribution.app.rs/chat/mod.rspass soundboard favourites and the composer/settings into the expressions reducer;selectors/mod.rsre-exports the selectors;tests/chat_ports.rsskips the expression actions instubs_emit_nothing(they are no longer stubs).Review fixes (
d1a94ee, tests in9cd766e)Expressions::take_soundboard_adopt, applied inAppafter the text chat reduces (voice/soundboard.rstouched for this). The review's scenario (star, then an echo or an unrelatedUSER_SETTINGS_UPDATEwithin the debounce) is insoundboard_favourites_sync.prefs_written_debounced_1500ms.synced_preferenceschange nothing (after the first snapshot). Test inprefs_from_other_client_replace_local.SYNCED_PREFERENCES_CONFLICT).PickEmoji { target: Reaction }so they count toward frecency.FLUXER_SCREENSHOT_TESTS=1 cargo xtask cigreen locally onb1bb741(latestorigin/textchatmerged).Closes #264
🤖 Generated with Claude Code
Independent review: Text chat 14 (core expressions)
Scope:
git diff origin/textchat...origin/textchat-14-core-expressions(11 files; the rest of4eec2aa..is Text chat 10 and later textchat merges).Checked and OK
crates/fluxer-core/tests/chat_expressions.rsand assert the spec values: top 42, 1500 ms prefs debounce, GIF search 350/1000 ms, suggest 250/900 ms, skeleton 800 ms, register-share slug-else-id, sticker alone vs pending,favorite_meme_id.selectors::{emoji_picker, sticker_picker, meme_picker, gif_picker, usable},EmojiPickerModel { sections, locked_count, locked_guilds },EmojiSection { id, label, icon, items },EmojiCell { emoji, names, locked },Usability::{Yes, NeedsPremium, NeedsPermission},GifPickerModel { view, results, loading_skeleton, provider_name, .. }all exist as written.get/char boundaries, so it cannot panic.prefs_write_preserves_unparsed_fieldsconfirms that every other top-level field (unknown 999 included) stays byte for byte.ReadyPayload.favorite_memeschecked against the fork (RpcService.ts:1164,GatewayReady.ts:150). It is read leniently. OK.Findings
BLOCKING (loses user data): soundboard favourites starred locally are reverted by any
USER_SETTINGS_UPDATEorUserSettingsPatchedthat arrives before the 1.5 s write, and the star is then never written.Soundboard::take_synced_favourites(settings, false)replacesfavouriteson every update/patch answer without checking for an echo or for pending local changes. The expressions side compares bytes, sees an echo, and keepsdirty.soundboard. When its timer fires, it writesctx.soundboard_favourites, which is now the old list again, sonext == baseand nothing goes out. The server sends full settings in everyUSER_SETTINGS_UPDATE(guild-folder changes, DOB, voice-activity sharing, any other PATCH), and the echo of an in-flight expressions write does the same. I reproduced it with a scratch test: start fromapp(),ToggleFavouriteSound(key), thenUserSettingsUpdate({synced_preferences: <same base>, theme: "light"})within the debounce, then fire the 1500 ms timer. Result:favourites == ["default:1"], the starred key is gone, and no PATCH is sent. Fix: the soundboard should take synced favourites only when the expressions treat the snapshot as non-echo/remote, and never whiledirty.soundboardis pending (for example, the expressions decide and pass the list through, or the soundboard skips when the snapshot'ssoundboard_favoritesequals the last one it took). Add this scenario tosoundboard_favourites_sync.minor (follow-up): no
synced_preferences_base_hashand no conflict handling. The original sendssynced_preferences_base_hash(sha256 of the base) and, onSYNCED_PREFERENCES_CONFLICT, refetches and merges (UserSettings.ts:990-1060). The proto (UserSettingsPatch.synced_preferences_base_hash) and fluxer-api (the conflict error) already support this. Without it, a write from the Electron app that lands between our last snapshot and our PATCH is overwritten by last-writer-wins. That includes non-picker fields. The window is about one gateway round trip. fluxer-core cannot hash without a dependency, so the runtime or fluxer-api could compute it from the base. Please open afollow-upissue linked from this PR.minor: echo detection compares exact bytes, but the server re-encodes the snapshot canonically (
normalizeSyncedPreferencesSnapshot,UserAccountSettingsService.ts:522). If our encoding differs from the TS canonical form (field order, or unknown field 999 dropped by the TS decoder), every echo counts as a remote snapshot. A change made while a write is in flight (skin tone, favourite) would then be reverted to the server value.prefs_written_debounced_1500msonly checks a byte-identical echo. Consider adopting the patch answer'ssynced_preferencesas the new base, as the original does withwireSyncedPreferencesBase = confirmedRaw, and re-applying the dirty fields on top instead of dropping them.minor: a
user_settingsobject without asynced_preferenceskey reads as an empty snapshot (UserSettings::synced_prefsreturnsOk(default)). The picker data is then replaced with empty data, and the next write encodes a near-empty snapshot. I reproduced this: the written snapshot was 9 bytes against 1238 before. The real server always sends the key (UserMappers.ts:367), so this only matters for partial payloads, but treating "key absent" as "unknown, keep base" would be safer.minor: frecency on quick reactions. The original also tracks emoji clicked in the hover bar's quick reactions and the context menu (
MessageActionBar.tsx:182,MessageContextMenu.tsx:436). Here onlyPickEmojiand sent content count, so Text chat 29 must emitPickEmoji { target: Reaction }(orToggleReactionmust record) for parity. Noting it for Text chat 29.CI:
FLUXER_SCREENSHOT_TESTS=1 cargo xtask cigreen locally on7efd571(all steps passed; livekit-interop skipped as usual). Remote runners not checked.Verdict: changes requested. One blocking finding (#1, soundboard favourites lost). The rest are minor or follow-up.
🤖 Generated with Claude Code
Independent review: Text chat 14 (re-review at
b1bb741, diff 9fcc13d..origin/textchat-14-core-expressions)Checked: all 15 tests that Step 1 names exist and assert the plan's values (1500 ms debounce, top 42, 350/1000 and 250/900 ms GIF debounces, the 800 ms skeleton). The Interfaces names exist as the plan writes them:
selectors::{emoji_picker, sticker_picker, meme_picker, gif_picker, usable},EmojiPickerModel/EmojiSection/EmojiCell/SectionIcon,GifPickerModel { view, results, loading_skeleton, provider_name },Usability::{Yes, NeedsPremium, NeedsPermission}. Crate invariants hold: no new dependency, no I/O, no file bytes or URLs in core. Writes rebuild the last snapshot and touch only the parts that changed, andprefs_write_preserves_unparsed_fieldschecks that every other top-level field stays byte for byte (Review Focus 3). Readingfavorite_memesfrom READY matches the fork (RpcService.ts:1164).apply_remote's per-partchanged()handles echoes, re-encoded echoes and updates to other settings correctly. LocalFLUXER_SCREENSHOT_TESTS=1 cargo xtask ciis green onb1bb741.Findings
apply_remotetreats "first snapshot, synced list empty, local list non-empty" as the one-time migration (dirty.soundboard = true). That condition is true on everyREADY, not only once. Separately, favourites adopted from a snapshot (take_soundboard_adoptinApp::apply) are never written to the local settings file, becausepersist::reducesavesvoice.soundboard.prefs()only onToggleFavouriteSound/SetSoundboardMute. So the local file keeps the old list forever.Scenario: device B starred x, and it synced. On device A the user unstars x, so the synced list is
[]. B adopts[]in memory, but its file still holds[x]. B restarts, loads[x], getsREADYwith[], and writes[x]back to the account. Every device sees x again.I confirmed this with a throwaway test, now removed: after the adopt it emits 0
SaveSettingsand the file still holds the key; after the "restart" the write holds[key].Fix: persist the adopted list (save settings when
take_soundboard_adoptreturnsSome). Also make the migration happen once, for example with a localsoundboard_favourites_syncedflag inLocalSettingsset after the first successful write or adopt. Add a test for "remote clear, then restart, does not resurrect".write_prefssetsprefs.base = nextand clearsdirtybefore the answer arrives, and nothing handlesEffectFailedforPatchUserSettings. If the PATCH fails, the next remote snapshot sees the part as "changed by another device" and reverts the local change. The next local write would re-send it only if no snapshot comes first. Suggest keeping the dirty flags untilUserSettingsPatchedarrives, or restoring them on failure. A follow-up issue is fine.READYafter a reconnect drops a pending change.self.prefs = PrefsSync::default()throws away a local change made within 1.5 s of a gateway re-identify:firstreplaces the picker data. This window is narrow, so a follow-up is fine.fluxer-proto. It changesgateway/ready.rs(ReadyPayload.favorite_memes) and its README, so it touches a second crate outside the Files list. The plan says a two-crate task must be serialised and say so. The change is additive (lenientVec,#[serde(default)]) and breaks no interface. Please say so in the PR body.Earlier findings 2 (#348) and 5 (Text chat 29) are tracked as the PR body says. Findings 3 and 4 of the previous review are fixed and tested.
Verdict: changes requested. One blocking finding (1). ci is green locally; remote runners not checked.
Review round 1, addressed in
6de2258(tests first;FLUXER_SCREENSHOT_TESTS=1 cargo xtask cigreen locally).Blocking: soundboard favourite deleted elsewhere comes back.
persist::reducenow saves the soundboard prefs whenever they differ from the store, on any event (READY included), not only onToggleFavouriteSound/SetSoundboardMute. An adopted list is written tosettings.toml.Soundboard::favourites_synced/SoundboardPrefs::synced([voice.soundboard] synced = true) is set once the account's list is known to match the local one: a readable snapshot holds it, and no write of it is waiting or unanswered.ChatCtx::soundboard_syncedgates the migration, so after that an empty synced list from another device wins, including on a machine that was off when the list was cleared.soundboard_favourites_cleared_elsewhere_stay_cleared. It covers the migration write, the answer savingsynced, another device clearing the list (the empty list is adopted and saved), a restart (no write), and a stale local list after a restart (it gives way).fluxer-platform(src/settings.rs: one serde field with a default, plus its round-trip test), because the flag must survive a restart.Minor: a failed write is reverted by the next snapshot.
write_prefsstill advancesbase, so echoes stay harmless. It now records each write (PrefsWrite { id, fields, before }) until it is answered. If the write fails (EffectFailedwith its id), its parts go back intobasefrombeforeand are marked dirty again. A snapshot that still holds what an unanswered write was built on is not treated as another device's change. The write is not retried on its own, so a write that keeps failing cannot loop; the next change or the next snapshot writes it. Test:prefs_failed_write_keeps_the_local_change.Minor: READY drops a change waiting in the debounce.
PrefsSync. A re-identify compares parts with the known snapshot like any other snapshot, and merges usage instead of reloading it. Test:prefs_change_pending_survives_reidentify.Minor: the second crate (
fluxer-proto) is touched without saying so.fluxer-proto(ReadyPayload.favorite_memes, lenient and additive, matchingRpcService.ts:1164, and its README line). With this fix it also touchesfluxer-platform(above). Both changes are additive.Merged
origin/textchat(b87bcd9) in07ee073;FLUXER_SCREENSHOT_TESTS=1 cargo xtask cigreen locally.app.rs,chat/mod.rs,selectors/mod.rs,session.rs,tests/chat_ports.rs) resolved by keeping both sides.PickEmoji { target: Composer }at the cursor, soexpressionsno longer inserts it as well (it only records frecency and the pending pick). Without this the emoji would appear twice.Draft::new(channel_id)/Composers::draft()(nowpub(crate)), move the cursor to the end, and schedule the 400 ms draft save.prefs_written_debounced_1500msnow filters on the 1500 ms timer, because the pick also schedules the composer's draft save.🤖 Generated with Claude Code
Independent review: Text chat 14 (round 3, at
07ee073, diff b87bcd9..origin/textchat-14-core-expressions)What I checked
Tests: all 15 tests that Step 1 names are in
tests/chat_expressions.rsand assert the spec's values:The three tests added in round 2 are also present (soundboard list cleared elsewhere, failed write, re-identify).
Interfaces: the names exist exactly as the plan writes them:
selectors::{emoji_picker, sticker_picker, meme_picker, gif_picker, usable};EmojiPickerModel { sections, locked_count, locked_guilds },EmojiSection { id, label, icon, items },EmojiCell { emoji, names, locked },SectionIcon;GifPickerModel { view, results, loading_skeleton, provider_name };Usability::{Yes, NeedsPremium, NeedsPermission}.Invariants:
fluxer-coregets no new dependency and does no I/O.custom_emoji_atandunicode_emoji_atslice only at char boundaries.Review Focus 3:
prefs_write_preserves_unparsed_fieldschecks every other top-level field byte for byte, including unknown field 999 andemoji_pickerfield 9.USAGE_SYNC_DEBOUNCE_MSinEmojiPicker.ts.mergeWireUsageMapsdoes it.RpcService.ts:1164,GatewayReady.ts:150).Merge with Text chat 11: Text chat 11's composer inserts
PickEmoji{Composer}at the cursor, and expressions now only counts the pick. I verified there is no double insert (frecency_recorded_on_send_react_pickasserts the draft is:blobwave:). Pending stickers go throughDraft::sticker, which the Text chat 11/12 send paths turn intosticker_ids.Settings load:
persist::reducenow saves the soundboard prefs whenever they change. OnLoaded,voice.load_settingsruns before the comparison, so the loaded favourites are not overwritten.Findings
ApiResult::UserSettingsPatchedremoves the oldest prefs write without checking which request it answers (expressions.rs,on_result). Todayexpressionsis the only sender ofPatchUserSettings, so this is correct for now. Once Text chat 19 patches the display settings through the same request, an answer to that patch will remove a prefs write that is still waiting. If that prefs write then fails,on_write_failedcannot find it. The next snapshot then looks like another device's change, and the local change is lost. Suggested fix: carry theEffectIdon the answer, or have Text chat 19 route its answer separately. A follow-up issue (linked to Text chat 19) is enough.SendRichMessage, with no pending message. If the send fails, the user sees nothing. Possible follow-up for the UI tasks (27/28).composer_picks. The next message the user sends in that channel then counts that emoji one time too few. The effect on frecency is negligible.fluxer-proto(ReadyPayload.favorite_memes, additive) andfluxer-platform([voice.soundboard] synced, serde default plus a round-trip test). Both changes are additive. Please say so in the PR body, as the plan asks.Round 2's blocking finding (a soundboard favourite deleted on another device comes back) is fixed and tested. The two minor findings (failed write, re-identify) are also fixed and tested.
Local ci:
FLUXER_SCREENSHOT_TESTS=1 cargo xtask ci: not completed in this review session (the run was stopped while still compiling, when the review had to be returned), so I cannot confirm it is green; the implementer reports it green locally at07ee073.Verdict: no blocking findings in the code. Not approved yet, only because I could not confirm local ci; re-run
FLUXER_SCREENSHOT_TESTS=1 cargo xtask cibefore addingready-to-merge.Independent review: Text chat 14 (round 4, at
07ee073, diff b87bcd9..origin/textchat-14-core-expressions)The remote branch has not changed since round 3. The implementer's fix for round-3 minor 3 and its merge of
origin/textchat(12e0695) are local only. They are not onorigin/textchat-14-core-expressions, so this round reviews07ee073.What I checked
tests/chat_expressions.rsand assert the spec's values: prefs debounce 1500 ms, "Frequently used" capped at 42 (ordered by use), GIF search 350/1000 ms, suggestions 250/900 ms, skeleton after 800 ms, share id = slug else id, sticker sent alone or held with text,favorite_meme_id, and theFAVORITE_MEME_*events. The three round-2 tests are also present (soundboard list cleared elsewhere, failed write, re-identify).selectors::{emoji_picker(&App, &str, &PickerFilter), sticker_picker, meme_picker, gif_picker(&App), usable(&App, &EmojiRef, Option<Snowflake>)},EmojiPickerModel { sections, locked_count, locked_guilds },EmojiSection { id, label, icon, items },EmojiCell { emoji, names, locked },SectionIcon,GifPickerModel { view, results, loading_skeleton, provider_name, .. },Usability::{Yes, NeedsPremium, NeedsPermission}.fluxer-corehas no Cargo change, no I/O and no clock, and holds no file bytes, upload URLs or paths. Its logs carry no URLs.ReadyPayload.favorite_memesmatches the fork (RpcService.ts:1164) and is read leniently.custom_emoji_at,unicode_emoji_at). Nonce arithmetic cannot panic.fluxer-platformchange is additive:synceduses a serde default and is skipped when false.usage_statskeeps each entry's unknown fields).prefs_write_preserves_unparsed_fieldspasses. Writes are debounced 1.5 s. Echoes, failed writes and re-identifies keep the pending local change.FLUXER_SCREENSHOT_TESTS=1 cargo xtask ciis green on07ee073("all steps passed";chat_expressions18/18).Findings
composer_picks(expressions.rs,PickEmoji). The fix and the testemoji_picked_into_an_edit_is_not_a_composer_pickexist only in the implementer's local worktree. Push them, or leave the item as is (frecency impact is negligible).fluxer-protochange but still does not name the additivefluxer-platformchange (SoundboardFile.syncedplus its round-trip test).emoji_pickercallsusable()once per candidate. For every custom emoji,usable()rescans every guild's list (emoji_guild) and recomputes the guild features, limits and channel permissions. That makes the selector O(custom²) on each call.Candidate.guildis already known, so computing availability once per guild would make it linear. This only matters if the UI calls the selector on every frame; the picker task can memoise it instead.follow-up). OK.Verdict: approved. No blocking findings, and local ci is green on
07ee073. If the local fix for minor 1 (with the12e0695merge) is pushed, re-runFLUXER_SCREENSHOT_TESTS=1 cargo xtask cion the new head beforeready-to-merge.🤖 Generated with Claude Code