Skip to content

fix(whatsapp): skip updateLastRoute when dmScope isolates DM sessions#24914

Closed
longevityboris wants to merge 1 commit into
openclaw:mainfrom
longevityboris:fix/whatsapp-dmscope-updatelastroute
Closed

fix(whatsapp): skip updateLastRoute when dmScope isolates DM sessions#24914
longevityboris wants to merge 1 commit into
openclaw:mainfrom
longevityboris:fix/whatsapp-dmscope-updatelastroute

Conversation

@longevityboris

@longevityboris longevityboris commented Feb 24, 2026

Copy link
Copy Markdown

Summary

  • When dmScope is set to per-channel-peer (or per-peer, per-account-channel-peer), WhatsApp DM sessions receive isolated session keys that differ from mainSessionKey.
  • However, updateLastRouteInBackground was unconditionally called with mainSessionKey for all DM routes, corrupting the main session's delivery context with the isolated DM's routing info.
  • Gate the updateLastRouteInBackground call on params.route.sessionKey === params.route.mainSessionKey, so it only fires when the DM session is not isolated by dmScope.

This is the same fix pattern as PR #13580 (Telegram), now applied to WhatsApp.

Fixes #24912
Related: #13580

Changes

  • src/web/auto-reply/monitor/process-message.ts: Added params.route.sessionKey === params.route.mainSessionKey guard to the updateLastRouteInBackground call for DM routes.
  • src/web/auto-reply/monitor/process-message.inbound-contract.test.ts: Added two test cases verifying that updateLastRouteInBackground is called when sessionKey === mainSessionKey and skipped when they differ (dmScope isolation).

Test plan

  • Verify existing tests pass (vitest run src/web/auto-reply/monitor/process-message.inbound-contract.test.ts)
  • New test: calls updateLastRouteInBackground for DMs when sessionKey equals mainSessionKey (no dmScope isolation - existing behavior preserved)
  • New test: skips updateLastRouteInBackground for DMs when dmScope isolates session key (dmScope active - bug fix verified)
  • Manual: configure dmScope: per-channel-peer on a WhatsApp account, send DMs from different peers, verify the main session's last-route is not overwritten

🤖 Generated with Claude Code

Greptile Summary

Fixes session corruption bug in WhatsApp DM routing when dmScope isolation is active. When dmScope is configured (e.g., per-channel-peer), isolated DM sessions receive different session keys from the main session, but the code was unconditionally calling updateLastRouteInBackground with mainSessionKey for all DMs, overwriting the main session's delivery context with isolated session routing data.

  • Adds guard condition checking sessionKey === mainSessionKey before updating last route for DMs
  • Preserves existing behavior for non-isolated DMs (when dmScope is not set or set to "main")
  • Mirrors the fix pattern from PR fix(telegram): skip updateLastRoute when dmScope isolates DM sessions #13580 (Telegram)
  • Includes comprehensive test coverage for both isolated and non-isolated scenarios

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • Surgical bug fix with clear logic, comprehensive test coverage, and follows established pattern from previous fix. The change is minimal (adding a single condition check), well-tested, and addresses a specific corruption issue without introducing new complexity or side effects.
  • No files require special attention

Last reviewed commit: 67ba9d6

(2/5) Greptile learns from your feedback when you react with thumbs up/down!

When dmScope is per-channel-peer (or per-peer, per-account-channel-peer),
WhatsApp DMs get isolated session keys. However, updateLastRoute still
unconditionally writes to mainSessionKey, corrupting the main session's
delivery context. Gate the call on sessionKey === mainSessionKey.

Fixes #24912
Related: #13580
@openclaw-barnacle openclaw-barnacle Bot added channel: whatsapp-web Channel integration: whatsapp-web size: S labels Feb 24, 2026
@steipete

Copy link
Copy Markdown
Contributor

AI-assisted stale triage closure (fix-only duplicate sweep).

This PR overlaps with #24949 for #24912 (WhatsApp dmScope updateLastRoute isolation). #24949 is the active path for this fix scope.

Closing this duplicate as AI-closed.

Reopen guidance:

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

Labels

channel: whatsapp-web Channel integration: whatsapp-web size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: WhatsApp DM updateLastRoute overwrites mainSessionKey regardless of dmScope

2 participants