Skip to content

fix(receipt): preserve sender device in delivery receipt to - #649

Merged
jlucaso1 merged 1 commit into
mainfrom
fix/delivery-receipt-preserve-device
May 28, 2026
Merged

jlucaso1 merged 1 commit into
mainfrom
fix/delivery-receipt-preserve-device

Conversation

@jlucaso1

Copy link
Copy Markdown
Collaborator

Summary

  • For multi-device LID senders the incoming <message from=\"USER:DEV@lid\"> carries an explicit device. The receipt was being addressed with info.source.chat (= from.to_non_ad()), stripping the device before send.
  • The LID server kept replaying the stanza from the offline queue and eventually closed the stream with <stream:error><ack class=\"message\"/></stream:error>. This is the residual cause of the disconnects that PR fix(offline): transport-ack stanzas with only unrecognized enc types #648 did not cover.
  • whatsmeow buildBaseReceipt echoes node.Attrs[\"from\"] verbatim (encoder writes AD-JID with device byte). WA Web sendDeliveryReceiptsAfterDecryption resolves to via extractJidFromJidWithType(widToJidWithType(from)) which for lidDevice returns deviceJid literally (device intact). Match that by addressing to with info.source.sender for DM / peer / self fanout. Group and status@broadcast keep info.source.chat since the group/status JID has no device.

Empirical confirmation (prod log)

  • Senders whose from had no device (e.g. 185323896221943@lid, 119009819262985@lid) were acked successfully.
  • The three residual stream:errors all came from from=...:7@lid, the only LID-routed DMs in the log with an explicit device.

Test plan

  • cargo fmt --all, cargo clippy --all --tests (clean)
  • cargo test -p whatsapp-rust (572 passed, 0 failed)
  • cargo test -p e2e-tests --test offline_receipts --test offline_messages (8 passed)
  • New unit tests for: LID DM with device preserves device in to; LID DM without device unchanged; group to stays group_jid with participant; peer_msg to keeps device; status to stays status@broadcast with participant + context.

For multi-device LID senders the wire `<message from="USER:DEV@lid">` arrives
with an explicit device. `build_delivery_receipt_node` was assembling
`<receipt to=info.source.chat>` where `chat = from.to_non_ad()`, so the
device was stripped before send. The LID server then replayed the stanza
from the offline queue and eventually closed the stream with
`<stream:error><ack class="message"/></stream:error>`.

whatsmeow `buildBaseReceipt` echoes `node.Attrs["from"]` verbatim and the
encoder writes an AD-JID with the device byte. WA Web
`sendDeliveryReceiptsAfterDecryption` resolves `to` via
`extractJidFromJidWithType(widToJidWithType(from))`, which for `lidDevice`
returns `deviceJid` literally (device intact); the WAP encoder then writes
`WapJid.createJidU(user, LID, device)`. Both keep the device.

Match that: for non-group / non-status receipts, address `to` with
`info.source.sender` (which is `from.clone()` and keeps the device). Group
and status@broadcast receipts stay on `info.source.chat` since the group
JID / status JID never carries a device.

Verified empirically against a prod log: senders whose `from` had no device
acked successfully; the three stream:errors all carried `from=...:7@lid`.
@coderabbitai

coderabbitai Bot commented May 28, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@jlucaso1, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 10 minutes and 54 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 5e8d6caf-157b-472c-9a00-3200e2740557

📥 Commits

Reviewing files that changed from the base of the PR and between dfc0dcb and 9ac7863.

📒 Files selected for processing (1)
  • src/receipt.rs
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/delivery-receipt-preserve-device

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions

Copy link
Copy Markdown

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

@jlucaso1
jlucaso1 merged commit b7bdacf into main May 28, 2026
10 checks passed
@jlucaso1
jlucaso1 deleted the fix/delivery-receipt-preserve-device branch May 28, 2026 13:51
jlucaso1 added a commit that referenced this pull request May 29, 2026
…fail gate

Address the remaining review nits (all verified; no code blocker found):

- handle_decrypt_failure self-fanout short-circuit now gates on
  `is_self_fanout() && should_send_delivery_receipt()`, matching the normal ack
  path's eligibility (coderabbit). is_self_fanout() stays the load-bearing
  prefix; the extra check only affects the unreachable empty-id case.

- own_bot_author_dm_acks_not_sender_receipt: added a short settle window so a
  future regression that emitted a receipt on a later tick can't slip past the
  negative assertion. (No current race: ack_received_message is synchronous and
  the bot-author branch returns before the receipt branch.)

- bot_self_fanout test now uses a device-bearing sender and asserts the device
  survives into the receipt `to` (end-to-end guard for #649, previously only
  covered by the isolated builder unit test).

- is_self_fanout_matches_only_own_dm_with_recipient: isolated coverage for each
  exclusion, including the load-bearing chat.is_group() guard with
  is_group=false (the own-from parser path).

- as_wire_str_round_trips_through_parse: guards ReceiptType::as_wire_str (the
  hand-maintained inverse of parse) against hyphen/underscore drift.
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.

1 participant