1:1 retry resend produces a malformed stanza — server rejects with smax-invalid (479) (regression in 7.x)
Summary
On 7.0.0-rc14, answering a retry receipt for a one-to-one message produces a stanza containing the message twice, in two mutually exclusive shapes: a direct <enc> node and a <participants> fan-out for the same device. The server rejects it with smax-invalid (479) and the message is never delivered.
6.7.23 is unaffected — the code path does not exist there.
Environment
@whiskeysockets/[email protected]- Node 20, Linux
- One-to-one chat, LID-addressed
- Line numbers below refer to the built
lib/in the published package
What happens
- We send a message to a LID-addressed 1:1 chat. The server accepts it (
receipt type=sender). - The recipient's device cannot decrypt it and sends a retry receipt from its device-specific jid (
<user>:1@lid). sendMessagesAgainresolves the message and callsrelayMessagewithparticipantset.- The resend goes out and the server rejects it:
sending message to 1 devices
smax-invalid (479): stanza rejected by serverReproduces every time a 1:1 retry receipt is answered. We first assumed our own getMessage was at fault; supplying it correctly only moved the failure from "message not available" to this rejection.
Cause
relayMessage has a group/status branch and a 1:1 else branch (messages-send.js:586), and then — separately, after both — an if (isRetryResend) block at :670. On a 1:1 retry, both run:
:604—if (!isRetryResend)skips device enumeration, leaving the single device entry:641-655— this loop is not guarded byisRetryResend, so that entry lands inotherRecipients:656-662—createParticipantNodes(otherRecipients, …)→ first encryption, producing aparticipantsnode:670-721— the retry block encrypts the same message again for the sameparticipant.jid→ second encryption — and pushes a bareencnode directly intobinaryNodeContent:723-736—participants.lengthis 1, so theparticipantsnode is appended as well
Resulting stanza:
<message to="USER:1@lid" device_fanout="false" id="...">
<enc v="2" type="..." count="1">...</enc>
<participants>
<to jid="USER:1@lid"><enc v="2" type="..."/></to>
</participants>
<device-identity .../>
</message>An ordinary 1:1 send produces exactly one of those two shapes.
Second consequence, independent of the rejection: the same plaintext is encrypted twice under the same session, advancing the Double Ratchet two steps for one message. Even if the server accepted the stanza, the peer could decrypt only one of the two, and the extra step desynchronises the session further.
Origin
The isRetryResend block is new in 7.x — 6.7.23 contains zero occurrences of isRetryResend or participant.count. It was introduced by PR 2507 (fix(retry): process keys bundle and embed SKDM on resend), which targeted group retries — SKDM is group sender-key material. The block guards its group-specific work internally (if (isGroupOrStatus) at :673), but the block itself is not guarded against the 1:1 participants path having already built a node.
Suggested fix
Either:
- guard the devices loop at
:641with!isRetryResend, or - skip the retry block when
participants.length > 0
Whichever matches the intended design — the goal is that a 1:1 retry resend emits one encryption of the message, in one node shape.
Not the cause (checked)
- Device-specific addressing.
to = participant.jid(:761) is intended for a retry:sendMessagesAgainsetssendToAll = !jidDecode(participant)?.device(messages-recv.js:1075), so a device-addressed retry is deliberately answered to that one device withdevice_fanout: 'false'. 6.7.23 does the same and is accepted. useUserDevicesCache— never set on this path, and enumeration is skipped anyway.participant.count— echoed into the directencnode's attrs (:718), which is correct there.
Possibly related, likely a separate issue
The retry cache appears to be keyed inconsistently: messages-send.js:880 writes via addRecentMessage(destinationJid, msgId, message) using the bare jid, while messages-recv.js:1051 reads with getRecentMessage(remoteJid, id) where remoteJid is the device-specific jid from the retry key. That is a guaranteed miss for any device-addressed retry, so the cache never serves a 1:1 retry and it always falls through to getMessage.
message-retry-manager.js:83 already maintains messageKeyIndex.set(id, keyStr), an id→key index that would make the lookup device-agnostic; getRecentMessage does not use it.
Happy to split this into its own issue if preferred.
Source: WhiskeySockets/Baileys