Voice 6: fluxer-core::voice voice-state store and selectors (#67) #104

Merged
charles merged 2 commits from voice-6-core-voice-states into voice 2026-11-11 18:30:58 +00:00
Owner

What

fluxer-core::voice: the voice-state store and the sidebar's voice selectors (Voice plan Task 6, spec §5.1).

  • App.voice: Voice, for now with states: VoiceStates only; later tasks add their fields.
  • VoiceStates (port of the fork's VoiceGatewayStateMachine.ts): one VoiceState per connection, indexed by channel and by user. apply, in_channel, of_user, by_connection, remove_guild, plus replace_guild, iter, len, is_empty, clear.
  • Reducer: READY replaces everything from guilds[].voice_states (the listing guild's id is authoritative), GUILD_CREATE replaces that guild's states, GUILD_DELETE (left or outage) drops them, VOICE_STATE_UPDATE applies; channel_id: null removes the connection, an empty connection_id is ignored, and a rejoin of the same gateway session under a new connection id drops the stale one (as the original). Reduced only while logged in; cleared on logout; not seeded from the cached READY.
  • selectors::voice_channel_participants -> Vec<VoiceParticipantRow> and selectors::voice_channel_user_count.
  • The member a voice state carries fills a gap in app.users and the guild's members (the original's GuildMembers.hydrateIfMissing), never replacing a known one.

How it was tested

crates/fluxer-core/tests/voice_states.rs, written first and seen failing against stubs: the seven tests the plan names (ready_seeds_states, update_moves_user_between_channels, channel_null_removes_connection, two_devices_of_one_user_group, unknown_user_or_channel_does_not_panic_or_appear_elsewhere, guild_delete_drops_states, proptest any_sequence_of_updates_keeps_indexes_consistent against a model) plus six more (fixture update, stale session, member hydration, GUILD_CREATE replacement, logout, collation). FLUXER_SCREENSHOT_TESTS=1 cargo xtask ci is green locally.

Review focus 3 is covered by unknown_user_or_channel_does_not_panic_or_appear_elsewhere: states for an unknown user/channel/guild are kept only under the channel they name and appear in no other channel.

Deviations from the plan / things to look at

  • Remote branch is voice-6-core-voice-states: voice/6-... cannot exist beside the branch voice (refname conflict), same as Voice 1 and 3.
  • One row per connection, a user's rows adjacent, devices = that user's connection count in the channel. The UI groups rows with devices > 1.
  • avatar is the user's avatar hash (Option<String>), since avatar_url needs the endpoints and a pixel size only the view knows.
  • voice_channel_user_count counts connections, not users: that is what the original's ChannelItem.tsx does (Object.keys(getAllVoiceStatesInChannel(..)).length).
  • Sort: the original uses Intl.Collator({numeric, sensitivity: 'base'}), then join order, then user id. Here: case-insensitive with numeric digit runs, then user id, then connection id. Not reproduced: accent-insensitivity (needs collation tables, no new dependency), and the per-component snapshot that freezes a name and keeps arrival order among equal names (view state).
  • Users the client has never seen are listed last as "Unknown User"; the original does not render them at all (but still counts them). Task 16 can filter if Charles prefers that.
  • speaking is always false until Voice 8 adds the live room.
  • Touched outside the Files list: guilds.rs and users.rs (member hydration; the plan's "guild/ready reducers"), selectors/mod.rs (re-exports), Cargo.toml (proptest as dev-dependency, already in the workspace, for the proptest the plan asks for), README.md.

Stacked on: voice-1-proto-voice-gateway

Closes #67

🤖 Generated with Claude Code

## What `fluxer-core::voice`: the voice-state store and the sidebar's voice selectors (Voice plan Task 6, spec §5.1). - `App.voice: Voice`, for now with `states: VoiceStates` only; later tasks add their fields. - `VoiceStates` (port of the fork's `VoiceGatewayStateMachine.ts`): one `VoiceState` per connection, indexed by channel and by user. `apply`, `in_channel`, `of_user`, `by_connection`, `remove_guild`, plus `replace_guild`, `iter`, `len`, `is_empty`, `clear`. - Reducer: `READY` replaces everything from `guilds[].voice_states` (the listing guild's id is authoritative), `GUILD_CREATE` replaces that guild's states, `GUILD_DELETE` (left or outage) drops them, `VOICE_STATE_UPDATE` applies; `channel_id: null` removes the connection, an empty `connection_id` is ignored, and a rejoin of the same gateway session under a new connection id drops the stale one (as the original). Reduced only while logged in; cleared on logout; not seeded from the cached `READY`. - `selectors::voice_channel_participants` -> `Vec<VoiceParticipantRow>` and `selectors::voice_channel_user_count`. - The `member` a voice state carries fills a gap in `app.users` and the guild's members (the original's `GuildMembers.hydrateIfMissing`), never replacing a known one. ## How it was tested `crates/fluxer-core/tests/voice_states.rs`, written first and seen failing against stubs: the seven tests the plan names (`ready_seeds_states`, `update_moves_user_between_channels`, `channel_null_removes_connection`, `two_devices_of_one_user_group`, `unknown_user_or_channel_does_not_panic_or_appear_elsewhere`, `guild_delete_drops_states`, proptest `any_sequence_of_updates_keeps_indexes_consistent` against a model) plus six more (fixture update, stale session, member hydration, `GUILD_CREATE` replacement, logout, collation). `FLUXER_SCREENSHOT_TESTS=1 cargo xtask ci` is green locally. Review focus 3 is covered by `unknown_user_or_channel_does_not_panic_or_appear_elsewhere`: states for an unknown user/channel/guild are kept only under the channel they name and appear in no other channel. ## Deviations from the plan / things to look at - Remote branch is `voice-6-core-voice-states`: `voice/6-...` cannot exist beside the branch `voice` (refname conflict), same as Voice 1 and 3. - One row per connection, a user's rows adjacent, `devices` = that user's connection count in the channel. The UI groups rows with `devices > 1`. - `avatar` is the user's avatar hash (`Option<String>`), since `avatar_url` needs the endpoints and a pixel size only the view knows. - `voice_channel_user_count` counts connections, not users: that is what the original's `ChannelItem.tsx` does (`Object.keys(getAllVoiceStatesInChannel(..)).length`). - Sort: the original uses `Intl.Collator({numeric, sensitivity: 'base'})`, then join order, then user id. Here: case-insensitive with numeric digit runs, then user id, then connection id. Not reproduced: accent-insensitivity (needs collation tables, no new dependency), and the per-component snapshot that freezes a name and keeps arrival order among equal names (view state). - Users the client has never seen are listed last as "Unknown User"; the original does not render them at all (but still counts them). Task 16 can filter if Charles prefers that. - `speaking` is always `false` until Voice 8 adds the live room. - Touched outside the Files list: `guilds.rs` and `users.rs` (member hydration; the plan's "guild/ready reducers"), `selectors/mod.rs` (re-exports), `Cargo.toml` (`proptest` as dev-dependency, already in the workspace, for the proptest the plan asks for), `README.md`. Stacked on: voice-1-proto-voice-gateway Closes #67 🤖 Generated with [Claude Code](https://claude.com/claude-code)
feat(proto): voice gateway types
All checks were successful
ci / Linux (x86_64) (push) Successful in 7m25s
ci / Windows (x64) (push) Successful in 8m0s
ci / Linux (x86_64) (pull_request) Successful in 7m29s
ci / Windows (x64) (pull_request) Successful in 8m4s
2be0cff6f0
Op 4 payload (VoiceStateUpdateParams), VoiceState, VoiceServerUpdate
(SFU and P2P forms, secrets redacted), the DM-call dispatches, the op 12
error payload with its string codes, and typed voice_states on the guild
snapshots of READY and GUILD_CREATE. Fixtures: fixtures/gateway/voice_*.json.

Refs #62

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Stubs for the voice module and the selectors so the tests compile; they fail.

Refs #67

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
feat(core): voice states and sidebar selectors
All checks were successful
ci / Linux (x86_64) (push) Successful in 7m41s
ci / Windows (x64) (push) Successful in 8m12s
ci / Linux (x86_64) (pull_request) Successful in 7m38s
ci / Windows (x64) (pull_request) Successful in 8m24s
d245b6f466
App.voice.states keeps one VoiceState per connection, indexed by channel and
user, fed by READY, GUILD_CREATE, GUILD_DELETE and VOICE_STATE_UPDATE.
voice_channel_participants and voice_channel_user_count derive the sidebar rows.

Refs #67

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Author
Owner

Independent review — Voice 6 (core-voice-states), head d245b6f

Reviewed 2be0cff..d245b6f cold, against the plan's Task 6, spec §5.1 and the fork's VoiceGatewayStateMachine.ts / VoiceParticipantSortUtils.ts.

1. Tests named by the plan — all seven present in crates/fluxer-core/tests/voice_states.rs and asserting what the plan says: ready_seeds_states, update_moves_user_between_channels, channel_null_removes_connection, two_devices_of_one_user_group, unknown_user_or_channel_does_not_panic_or_appear_elsewhere, guild_delete_drops_states, proptest any_sequence_of_updates_keeps_indexes_consistent (checked against a model, including the empty connection id and guild replace/remove). Six extra tests. 13/13 pass.

2. Interfaces — App.voice: Voice { states }, VoiceStates::{apply(&VoiceState), in_channel, of_user, by_connection(&str), remove_guild}, voice_channel_participants(&App, channel_id) -> Vec<VoiceParticipantRow> with all 14 fields under the plan's names (devices: u8), and voice_channel_user_count exist as written and are re-exported from selectors.

3. Invariants — fluxer-core gains only the proptest dev-dependency (already in the workspace); no iced/wgpu/winit/reqwest/tungstenite, no I/O. No panicking path on server data: no indexing/unwrap in the store or selector, devices saturates, and the comparator collate is a total preorder (lexicographic over tokens, digit runs as one class), so sort_by cannot hit the inconsistent-order panic. No secrets in code or tests.

4. Review Focus 3 — covered: states for an unseen user/channel/guild, without a channel, and with an empty connection id neither panic nor show in any other channel; a state is indexed only under the channel it names. The stale-session rule matches the fork (same guild + channel + session_id, other connection id).

5. CI — cargo xtask ci in the review worktree: all steps passed (screenshot step skipped, FLUXER_SCREENSHOT_TESTS unset; this task has no UI). Remote runners not checked.

Findings

  • minor — crates/fluxer-core/src/selectors/voice.rs: voice_channel_user_count counts connections, not users, despite its name (a user on two devices counts twice). Matches the original's ChannelItem.tsx per the implementer and is documented; Voice 16 must not use it as a distinct-user count.
  • minor — selectors/voice.rs: ordering differs from the original in the disclosed ways (no accent folding, no join-order tie-break, no frozen-name snapshot; ties fall to user id). Rows can reorder when a nickname changes while in the channel. Voice 16 or a follow-up should decide whether the snapshot belongs in the view.
  • minor — selectors/voice.rs: unknown users are listed (last, as "Unknown User") where the original leaves them out until resolved. Not a phantom in a wrong channel, so Review Focus 3 holds; Voice 16 to filter or keep.
  • minor — crates/fluxer-core/src/users.rs: Users::reduce is not gated on being logged in, so a VOICE_STATE_UPDATE that arrives after logout still hydrates its member's user into app.users (the voice store itself correctly drops it). Same pre-existing behaviour as PRESENCE_UPDATE; worth one follow-up for the whole reducer rather than a fix here.
  • minor — scope: guilds.rs, users.rs (hydrate-if-missing) and Cargo.toml are outside the task's Files list. The change is small, tested (member_of_an_update_names_a_user_not_seen_before) and never overwrites a known member/user; hydrated members do enter GuildRecord.members without touching member_count, as in the original.
  • minor — avatar is the avatar hash (Option<String>), not a URL; the plan leaves the type open. Voice 16 builds the image through avatar_url.

Verdict: APPROVE — no blocking findings, local ci green.

## Independent review — Voice 6 (core-voice-states), head d245b6f Reviewed `2be0cff..d245b6f` cold, against the plan's Task 6, spec §5.1 and the fork's `VoiceGatewayStateMachine.ts` / `VoiceParticipantSortUtils.ts`. **1. Tests named by the plan** — all seven present in `crates/fluxer-core/tests/voice_states.rs` and asserting what the plan says: `ready_seeds_states`, `update_moves_user_between_channels`, `channel_null_removes_connection`, `two_devices_of_one_user_group`, `unknown_user_or_channel_does_not_panic_or_appear_elsewhere`, `guild_delete_drops_states`, proptest `any_sequence_of_updates_keeps_indexes_consistent` (checked against a model, including the empty connection id and guild replace/remove). Six extra tests. 13/13 pass. **2. Interfaces** — `App.voice: Voice { states }`, `VoiceStates::{apply(&VoiceState), in_channel, of_user, by_connection(&str), remove_guild}`, `voice_channel_participants(&App, channel_id) -> Vec<VoiceParticipantRow>` with all 14 fields under the plan's names (`devices: u8`), and `voice_channel_user_count` exist as written and are re-exported from `selectors`. **3. Invariants** — `fluxer-core` gains only the `proptest` dev-dependency (already in the workspace); no iced/wgpu/winit/reqwest/tungstenite, no I/O. No panicking path on server data: no indexing/unwrap in the store or selector, `devices` saturates, and the comparator `collate` is a total preorder (lexicographic over tokens, digit runs as one class), so `sort_by` cannot hit the inconsistent-order panic. No secrets in code or tests. **4. Review Focus 3** — covered: states for an unseen user/channel/guild, without a channel, and with an empty connection id neither panic nor show in any other channel; a state is indexed only under the channel it names. The stale-session rule matches the fork (same guild + channel + session_id, other connection id). **5. CI** — `cargo xtask ci` in the review worktree: all steps passed (screenshot step skipped, `FLUXER_SCREENSHOT_TESTS` unset; this task has no UI). Remote runners not checked. ### Findings - **minor** — `crates/fluxer-core/src/selectors/voice.rs`: `voice_channel_user_count` counts connections, not users, despite its name (a user on two devices counts twice). Matches the original's `ChannelItem.tsx` per the implementer and is documented; Voice 16 must not use it as a distinct-user count. - **minor** — `selectors/voice.rs`: ordering differs from the original in the disclosed ways (no accent folding, no join-order tie-break, no frozen-name snapshot; ties fall to user id). Rows can reorder when a nickname changes while in the channel. Voice 16 or a follow-up should decide whether the snapshot belongs in the view. - **minor** — `selectors/voice.rs`: unknown users are listed (last, as "Unknown User") where the original leaves them out until resolved. Not a phantom in a wrong channel, so Review Focus 3 holds; Voice 16 to filter or keep. - **minor** — `crates/fluxer-core/src/users.rs`: `Users::reduce` is not gated on being logged in, so a `VOICE_STATE_UPDATE` that arrives after logout still hydrates its member's user into `app.users` (the voice store itself correctly drops it). Same pre-existing behaviour as `PRESENCE_UPDATE`; worth one follow-up for the whole reducer rather than a fix here. - **minor** — scope: `guilds.rs`, `users.rs` (hydrate-if-missing) and `Cargo.toml` are outside the task's Files list. The change is small, tested (`member_of_an_update_names_a_user_not_seen_before`) and never overwrites a known member/user; hydrated members do enter `GuildRecord.members` without touching `member_count`, as in the original. - **minor** — `avatar` is the avatar hash (`Option<String>`), not a URL; the plan leaves the type open. Voice 16 builds the image through `avatar_url`. **Verdict: APPROVE** — no blocking findings, local ci green.
charles merged commit d23d6e1648 into voice 2026-11-11 18:30:58 +00:00
Sign in to join this conversation.
No description provided.