Skip to content

fix: preserve participant JID server in extractDeviceJids for LID support#8

Open
99ecarvalho wants to merge 1 commit into
evolution-foundation:masterfrom
99ecarvalho:fix/lid-jid-encoding
Open

fix: preserve participant JID server in extractDeviceJids for LID support#8
99ecarvalho wants to merge 1 commit into
evolution-foundation:masterfrom
99ecarvalho:fix/lid-jid-encoding

Conversation

@99ecarvalho
Copy link
Copy Markdown

@99ecarvalho 99ecarvalho commented May 17, 2026

Problem

After WhatsApp's LID (Linked Identity) migration, group messages fail with SessionError: No sessions because participant JIDs returned by extractDeviceJids lose their original @lid domain and are incorrectly re-encoded as @s.whatsapp.net.

This happens because extractDeviceJids only destructures user from jidDecode(), discarding the server field. When messages-send.ts later calls jidEncode(), it uses a blanket isLid flag to decide the domain — but in mixed groups (where some participants are @lid and others are @s.whatsapp.net), this produces wrong JIDs for some participants.

Fix

  1. src/WABinary/jid-utils.ts: Add optional server field to JidWithDevice type
  2. src/Utils/signal.ts: Extract and propagate server from jidDecode() in extractDeviceJids
  3. src/Socket/messages-send.ts: Use each device's actual server (falling back to the existing isLid logic) in both patchMessageBeforeSending and the sender key distribution loop

Testing

Tested against Evolution API v2.2.3 with WhatsApp accounts that have undergone the LID migration. Group messages and DMs to @lid contacts now succeed without session errors.

Summary by Sourcery

Preserve and propagate the original JID server for participant device JIDs so that group message sending works correctly for both LID and non-LID accounts.

Bug Fixes:

  • Fix incorrect re-encoding of participant device JIDs that caused missing sessions when sending group messages after LID migration.

Enhancements:

  • Extend the JidWithDevice type and device extraction logic to carry an optional server field, enabling per-device domain selection when encoding JIDs.

…port

After WhatsApp's LID migration, group messages fail with
'SessionError: No sessions' because participant JIDs from
extractDeviceJids lose their original @lid domain and are
incorrectly re-encoded as @s.whatsapp.net.

- Add optional 'server' field to JidWithDevice type
- Extract and propagate 'server' from jidDecode in extractDeviceJids
- Use per-device server in patchMessageBeforeSending and sender key
  distribution instead of blanket isLid flag
@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented May 17, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Propagates the JID server component through device extraction and message sending so that device JIDs preserve their original @lid vs @s.whatsapp.net domains, fixing mixed-domain group messaging after WhatsApp LID migration.

File-Level Changes

Change Details Files
Propagate server component from decoded JIDs when extracting device JIDs for signal sessions.
  • Extend JidWithDevice type to include an optional server field so device objects can carry their JID domain.
  • In extractDeviceJids, destructure server from jidDecode(id) alongside user.
  • Include server in the extracted device entries pushed into the result array, preserving each participant’s original JID domain.
src/WABinary/jid-utils.ts
src/Utils/signal.ts
Use each device JID’s own server when encoding JIDs for message patching and sender key distribution.
  • In the group message send path, when building the device JIDs array passed to patchMessageBeforeSending, call jidEncode with d.server if present, otherwise fall back to the existing isLid-based server selection.
  • In the sender key distribution loop, destructure server from each device and use it when encoding the JID, again falling back to the isLid heuristic if no server is present.
  • Ensure both message encryption and sender key establishment respect mixed @lid and @s.whatsapp.net group membership without altering domains.
src/Socket/messages-send.ts

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've left some high level feedback:

  • The fallback logic d.server || (isLid ? 'lid' : 's.whatsapp.net') is now duplicated in two places in messages-send.ts; consider extracting a small helper to derive the effective server from a JidWithDevice to avoid divergence in future changes.
  • Now that JidWithDevice carries an optional server, it might be worth scanning other producers/consumers of this type to ensure they either populate or intentionally ignore server, so behavior is consistent across all send paths (not just extractDeviceJids).
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The fallback logic `d.server || (isLid ? 'lid' : 's.whatsapp.net')` is now duplicated in two places in `messages-send.ts`; consider extracting a small helper to derive the effective server from a `JidWithDevice` to avoid divergence in future changes.
- Now that `JidWithDevice` carries an optional `server`, it might be worth scanning other producers/consumers of this type to ensure they either populate or intentionally ignore `server`, so behavior is consistent across all send paths (not just `extractDeviceJids`).

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants