#2781·Baileys

1:1 retry resend produces a malformed stanza — server rejects with smax-invalid (479) (regression in 7.x)

Author: bronyssCreated Aug 25, 2026Updated Sep 20, 2026

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

  1. We send a message to a LID-addressed 1:1 chat. The server accepts it (receipt type=sender).
  2. The recipient's device cannot decrypt it and sends a retry receipt from its device-specific jid (<user>:1@lid).
  3. sendMessagesAgain resolves the message and calls relayMessage with participant set.
  4. The resend goes out and the server rejects it:
sending message to 1 devices
smax-invalid (479): stanza rejected by server

Reproduces 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 by isRetryResend, so that entry lands in otherRecipients
  • :656-662 — createParticipantNodes(otherRecipients, …) → first encryption, producing a participants node
  • :670-721 — the retry block encrypts the same message again for the same participant.jid → second encryption — and pushes a bare enc node directly into binaryNodeContent
  • :723-736 — participants.length is 1, so the participants node 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 :641 with !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: sendMessagesAgain sets sendToAll = !jidDecode(participant)?.device (messages-recv.js:1075), so a device-addressed retry is deliberately answered to that one device with device_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 direct enc node'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.