Skip to content

Conversation

@wahyuwidgetworks
Copy link

Summary

Fixes critical bug preventing group message sends in LID-addressed WhatsApp groups. Baileys v6.7.19 incorrectly includes sender's own devices in sender key distribution list, causing WhatsApp to reject messages with "not-acceptable" error.

Problem

  • Affected: Instance 6287777635515 (inbox 1) and 6287785582370 (inbox 16) sending to LID group 120363407389509612@g.us
  • Error: "The message could not be sent. Please check your connection. [object Object]"
  • Impact: Complete inability to send messages to LID-addressed groups
  • Severity: HIGH - blocking customer communication

Root Cause

Baileys messages-send.js (lines 363-372) has no sender filtering for group messages:

  • Gets ALL participants including sender
  • Fetches devices for ALL participants (no exclusion)
  • Tries to send sender keys to sender's own devices → WhatsApp rejects with "not-acceptable"

In contrast, 1:1 message path properly separates meJids vs otherJids.

Solution

Applied patch to node_modules/baileys/lib/Socket/messages-send.js:

  • Extracts sender's user ID from both phone JID and LID formats
  • Filters sender's own devices from senderKeyJids array
  • Uses same pattern as non-group message path (line ~396)

Patch file: patches/baileys+6.7.19+lid-group-send.patch

Changes

  1. Dockerfile (line 4, line 11)

    • Added patch binary to Alpine packages
    • Added patch application step after npm ci
  2. CHANGELOG.md

    • Documented Baileys senderKeyJids filtering fix
  3. patches/baileys+6.7.19+lid-group-send.patch (new)

    • Unified diff patch filtering sender devices from group sender key distribution
  4. docs/troubleshooting/11-12-25-group-chat-not-acceptable-error.md (new)

    • Complete root cause analysis
    • Evidence and testing performed
    • Deployment issues and resolutions

Deployment Notes

⚠️ Patch File Format Issues Resolved:

  • Issue 1: Missing patch binary in Alpine → Fixed by adding to apk install
  • Issue 2: Malformed patch (incomplete trailing context) → Fixed with proper unified diff format
  • Issue 3: Incorrect indentation → Fixed to match Baileys source (20/16 spaces)

Patch applies during Docker build after npm ci installs fresh Baileys from npm.

Testing Plan

  1. ✅ Code analysis confirms root cause
  2. ✅ Patch format validated (commit: 518f76d)
  3. Next: Build Docker image to verify patch applies correctly
  4. Next: Deploy to staging, test group message send in conversation 400/401
  5. Next: Deploy to production if staging succeeds

Upstream Status

Related Issues

  • Fixes group send failures for LID-addressed groups
  • Related to LID normalization work in conversation split fix (task.md line 21)

Verification

After deployment to staging:

# Send message from Prospek inbox 1 to group 120363407389509612@g.us
# Expected: Message sends successfully without "not-acceptable" error
# Check logs for: "sending new sender key" should NOT include sender's own JIDs

Baileys v6.7.19 includes sender's own devices in senderKeyJids when
sending to LID-addressed groups, causing WhatsApp to reject with
'not-acceptable' error.

This patch filters sender's own devices from the senderKeyJids list
before sending group messages, following the same pattern Baileys
uses for non-group messages (meJids vs otherJids filtering).

Changes:
- Add Baileys patch in patches/baileys+6.7.19+lid-group-send.patch
- Update Dockerfile to apply patch after npm ci
- Extract meUser from meId and meLid from authState.creds
- Skip sender's own devices in senderKeyJids loop

Fixes: #issue-number
Related: WhiskeySockets/Baileys#1690, EvolutionAPI#1768
…tion

Alpine Linux does not include 'patch' by default. Without this,
the Baileys LID group send patch would silently fail during build,
leaving the fix unapplied in production images.

Changes:
- Add 'patch' to apk install list
- Remove '|| echo' fallback to fail fast on patch errors
- Use unified diff format without git headers
- Change from -p1 to -p0 for correct path stripping
- Ensures patch applies correctly during Docker build
Fixes malformed patch error during Docker build by adding complete
trailing context lines to the unified diff format.

- Previous patch ended prematurely at line 21 causing "malformed patch at line 19" error
- Added proper trailing context (lines showing unchanged code after modifications)
- Patch now correctly shows 8→14 line transformation (adding 6 lines of sender filtering)
- Updated documentation with deployment issues encountered and solutions

Related to LID group send failure fix for "not-acceptable" error.
Fixed indentation mismatch between patch file and actual Baileys source.
The patch file must match the exact spacing (20 spaces for line 360-361,
16 spaces for line 362-363) in the original Baileys file.

Previous version had incorrect spacing (13-17 spaces) causing patch
application to fail with "malformed patch at line 19" error.
@chatgpt-codex-connector
Copy link

💡 Codex Review

RUN patch -p0 < patches/baileys+6.7.19+lid-group-send.patch

P1 Badge Patch command uses wrong strip level

The Docker build now runs patch -p0 < patches/baileys+6.7.19+lid-group-send.patch, but the patch file still targets paths prefixed with a/…/b/… (--- a/node_modules/baileys/lib/Socket/messages-send.js, +++ b/node_modules/...). With -p0 the patch utility looks for a/node_modules/..., which does not exist in the build context, so the RUN step will fail (“can't find file to patch”) and the Baileys fix is never applied, breaking image builds.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

The patch file had git-style a/ and b/ prefixes which don't work with
patch -p0. The patch utility would look for "a/node_modules/..." which
doesn't exist, causing "can't find file to patch" error during build.

Fixed by removing the prefixes so patch -p0 looks for the correct path:
node_modules/baileys/lib/Socket/messages-send.js
@wahyuwidgetworks
Copy link
Author

@codex please review again

@chatgpt-codex-connector
Copy link

Codex Review: Didn't find any major issues. Nice work!

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@wahyuwidgetworks wahyuwidgetworks merged commit 9f2b0c2 into production-v2.3.2 Dec 11, 2025
1 check passed
@wahyuwidgetworks wahyuwidgetworks deleted the fix/baileys-lid-group-senderkey-patch branch December 11, 2025 08:48
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