Skip to content

Messages sent with prekey (pkmsg) on every send — sessions not reused #403

Description

@ricott1

Summary

Messages sent via client.send_message() always use enc type="pkmsg" (prekey messages) instead of reusing established Signal protocol sessions (enc type="msg"). The WhatsApp server ACKs the messages, but recipients never receive them — likely because the prekey bundles are exhausted or the sessions established during encryption aren't persisted between sends.

Reproduction

  1. Authenticate a new session (QR code pairing)
  2. Send a message to a contact — works initially
  3. Send another message to the same contact — still uses pkmsg
  4. Recipient never sees the messages (server ACKs but delivery fails silently)

Log Evidence

Every outgoing message uses pkmsg for the recipient, even after multiple sends to the same contact:

<!-- First send -->
<message id="3EB041..." to="49157...@s.whatsapp.net" type="text">
  <participants>
    <to jid="49157...@s.whatsapp.net"><enc type="pkmsg" v="2"/></to>
    <to jid="39366...@s.whatsapp.net"><enc type="msg" v="2"/></to>  <!-- own device: reused -->
  </participants>
</message>

<!-- Second send to same contact — still pkmsg, should be msg -->
<message id="3EB0F1..." to="49157...@s.whatsapp.net" type="text">
  <participants>
    <to jid="49157...@s.whatsapp.net"><enc type="pkmsg" v="2"/></to>
    <to jid="39366...@s.whatsapp.net"><enc type="msg" v="2"/></to>
  </participants>
</message>

Note: the sender's own devices correctly use enc type="msg" (established session), so session persistence works for self-devices but not for remote contacts.

Expected Behavior

After the first pkmsg to a contact, subsequent sends should use enc type="msg" (the Signal session established during the first send should be persisted and reused).

Environment

  • whatsapp-rust v0.4.1
  • Custom ProtocolStore implementation backed by SQLite (put_session/get_session using INSERT OR REPLACE)
  • macOS, Rust nightly

Workaround

Deleting the database and re-pairing temporarily fixes it, but the issue recurs after some time.

Possible Cause

The session established during send_message_impl() may not be getting committed to the store, or the session lookup is using a different address format than what was stored. The fact that self-device sessions work correctly suggests the issue is specific to how remote contact sessions are keyed/stored.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions