Moving a user to another voice channel makes them invisible and stuck reconnecting

(#2977) Bug Open: Confirmed Priority: P1 desktop moderation voice

Thread

Comment by Zaostaly Jezevec
I can reproduce this on a self-hosted instance (API/gateway 2026.1114, desktop 2026.1114.60222 and web 2026.1114.52902) and found the root cause plus a working server-side workaround. Symptom PATCH /guilds/{g}/members/{u} with {"channel_id": ...} returns 200, the user sees "connecting" (orange), then an error, and after ~5 s the client puts them back in the original channel. Same on desktop and web. Console output (both clients):
[VoiceEngineV2AppConnectionHostAdapter] [Warn] Aborting LiveKit room creation after codec probing because attempt is stale {attemptId: 5}
  at handleVoiceServerUpdateAsync -> ... (VOICE_SERVER_UPDATE was received)
[VoiceEngineV2AppConnectionHostAdapter] [Warn] Voice server timeout {guildId, channelId: <target>}
[VoiceReconnectionManager] [Info] Attempting to reconnect to last voice channel {channelId: <original>}
The server side is fine: no errors in api/gateway/LiveKit, and the token request succeeds. Root cause: a race between two gateway events on the client After a move the gateway sends two events for the moved user almost at once:
  1. VOICE_STATE_UPDATE (new channel). The client handles it in MediaEngineFacade.ts (~L1889-1898): it calls disconnectForChannelMove('server') and, in .finally(), recoverConnectionExpectation(...). That starts a new connection attempt.
  2. VOICE_SERVER_UPDATE (token for the new channel). The handler in VoiceEngineV2AppConnectionHostAdapter.ts accepts it, then awaits getRoomVideoDecoderExclusions() and re-checks isLatestConnectionAttempt(attemptId) (~L519-526).
If (2) is processed while (1) is still in flight, the attempt id is bumped by recoverConnectionExpectation and the already running attempt for the token is discarded as stale. The server only sends the token once, so the client waits for a VOICE_SERVER_UPDATE that never comes again, times out after 5 s and reconnects to the old channel. With a fast, local LiveKit the token seems to arrive right after the state update, so this lost the race every time for us. (This is my reading of the client code, I did not trace the exact event order.) This also matches the "Connection succeeded but attempt is stale, disconnecting" log from other self-hosters in this thread. Workaround that works for us In fluxer_gateway/src/guild/voice/guild_voice_move.erl, delay the token dispatch a bit so VOICE_STATE_UPDATE is always handled first. The function already runs in a spawned process, so nothing is blocked:
-define(MOVE_TOKEN_DELAY_MS, 500).

send_captured_voice_server_updates(GuildId, ChannelId, SessionDataList, GuildPid) ->
    timer:sleep(?MOVE_TOKEN_DELAY_MS),
    lists:foreach(...)
With this single change the move worked on our instance (tested once, moving a user via the API; before the change it failed 3 out of 3 times on desktop and web). The fact that a pure delay fixes it supports the race explanation above. It is only a workaround: a proper fix would make the client tolerate either event order (e.g. not invalidate the attempt that is already waiting on the token for the same target channel), or have the server guarantee the order.