Skip to content

fix: isolate WhatsApp direct sessions by account#76730

Closed
steipete wants to merge 1 commit into
mainfrom
fix/76263-whatsapp-direct-session-isolation
Closed

fix: isolate WhatsApp direct sessions by account#76730
steipete wants to merge 1 commit into
mainfrom
fix/76263-whatsapp-direct-session-isolation

Conversation

@steipete

@steipete steipete commented May 3, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes the WhatsApp direct-message context leak reported in #76263. With the default shared DM scope, inbound WhatsApp DMs could collapse into the agent main session, so distinct contacts shared one session file and model context.

Root Cause

WhatsApp inbound routing passed a direct peer to the generic route resolver, but generic routing defaults session.dmScope to main. That default is useful for personal single-user continuity, but unsafe for WhatsApp shared inbox and SaaS deployments where many senders contact the same account.

What Changed

  • Adds a per-call dmScopeOverride to resolveAgentRoute() so channel plugins can request stricter DM isolation without changing the global config contract.
  • Makes WhatsApp inbound direct chats use account-aware per-contact session keys: agent:<agentId>:whatsapp:<accountId>:direct:<peerId>.
  • Preserves WhatsApp group session behavior.
  • Records last-route metadata on the isolated DM session key, so follow-up delivery context stays aligned with the new session.
  • Updates WhatsApp docs and changelog to document the new direct-chat session contract.

Why Account-Aware

The earlier bundled PR used per-channel-peer, which isolated different contacts on one WhatsApp account but collapsed the same sender across multiple WhatsApp accounts. This PR uses per-account-channel-peer for WhatsApp DMs so both dimensions are isolated.

Scope

WhatsApp inbound DM session routing and last-route metadata only. No outbound newsletter behavior, group session keys, allowlists, auth, provider/model behavior, or non-WhatsApp channel defaults are changed.

Test Plan

  • pnpm exec oxfmt --write --threads=1 src/routing/resolve-route.ts src/routing/resolve-route.test.ts extensions/whatsapp/src/auto-reply/monitor/on-message.ts extensions/whatsapp/src/auto-reply/monitor/inbound-dispatch.ts extensions/whatsapp/src/auto-reply/monitor/inbound-dispatch.test.ts extensions/whatsapp/src/auto-reply.web-auto-reply.last-route.test.ts docs/channels/whatsapp.md CHANGELOG.md
  • pnpm test src/routing/resolve-route.test.ts extensions/whatsapp/src/auto-reply.web-auto-reply.last-route.test.ts extensions/whatsapp/src/auto-reply/monitor/inbound-dispatch.test.ts -- --reporter=verbose
  • pnpm changed:lanes --json
  • GitHub PR CI: green on 6523eb7618b463c249b3b557aa124ffbe6379a06

Linked Issue / Replacement

Fixes #76263.

Replaces the WhatsApp-only portion of closed bundled PR #76326.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation channel: whatsapp-web Channel integration: whatsapp-web size: S maintainer Maintainer-authored PR labels May 3, 2026
@clawsweeper

clawsweeper Bot commented May 3, 2026

Copy link
Copy Markdown
Contributor

Thanks for the context here. I swept through the related work, and this is now duplicate or superseded.

Keep open: the patch appears to address the WhatsApp direct-message session leak, but it still needs contributor real behavior proof, a clean merge result, and maintainer acceptance of compatibility-sensitive session/API changes.

Root-cause cluster
Relationship: fixed_by_candidate
Canonical: #76263
Summary: This PR is the active candidate fix for the open WhatsApp direct-session sharing report; earlier related PRs are closed, merged only for narrower last-route behavior, or partially overlapping.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Canonical path: Close this stale PR. The latest review rated it F, the branch still lacks merge-ready proof, and there has been no human follow-up after the durable review.

So I’m closing this here because the remaining work is already tracked in the canonical issue.

Review details

Best possible solution:

Close this stale PR. The latest review rated it F, the branch still lacks merge-ready proof, and there has been no human follow-up after the durable review.

Do we have a high-confidence way to reproduce the issue?

Yes, source inspection gives a high-confidence path: current main passes WhatsApp direct peers to resolveAgentRoute, and unset session.dmScope still defaults to the shared main scope. I did not establish a live WhatsApp reproduction in this read-only review.

Is this the best way to solve the issue?

Yes as the likely fix shape, but not merge-ready. Account-aware per-contact isolation reuses the existing per-account-channel-peer helper and is narrower than changing the global DM default, but proof, branch refresh, and maintainer acceptance are still needed.

Security review:

Security review cleared: The diff reduces a WhatsApp session-context leak and does not add dependencies, workflows, secrets handling, broad permissions, or downloaded code execution.

AGENTS.md: found and applied where relevant.

What I checked:

  • stale F-rated PR: PR was opened 2026-05-03T14:29:08Z, is older than 60 days, and the latest review rated it F.
  • proof blocker: real behavior proof is mock_only and proof tier is F, so this branch is not merge-ready without contributor follow-up.
  • no human follow-up: live comments and timeline hydrated by apply contain no non-automation activity after the ClawSweeper review.

Likely related people:

  • steipete: Peter has prior current-main routing and inbound last-route history on the same resolver/session path, and authored this account-aware fix branch; he is relevant beyond only opening the PR. (role: feature owner and recent area contributor; confidence: high; commits: 6a8081a7f33e, 9b30ff181c14, 6523eb7618b4; files: src/routing/resolve-route.ts, extensions/whatsapp/src/auto-reply/monitor/inbound-dispatch.ts, extensions/whatsapp/src/auto-reply/monitor/on-message.ts)
  • mcaxtr: Recent merged WhatsApp multi-account state work touched on-message and group session-key surfaces that this account-aware session fix depends on. (role: adjacent WhatsApp multi-account contributor; confidence: high; commits: 458a52610a4d; files: extensions/whatsapp/src/auto-reply/monitor/on-message.ts, extensions/whatsapp/src/group-session-key.ts)
  • Jarvis Deploy: This author added the per-account-channel-peer routing/session-key mode that the PR uses for WhatsApp direct session isolation. (role: introduced related session-key capability; confidence: medium; commits: d499b148423e; files: src/routing/session-key.ts, src/routing/resolve-route.ts, src/routing/resolve-route.test.ts)
  • Ubuntu: This author added the original session.dmScope support for multi-user DM isolation that current WhatsApp direct routing can inherit only through config or bindings. (role: introduced related DM-scope behavior; confidence: medium; commits: ca9688b5cc73; files: src/routing/session-key.ts, src/routing/resolve-route.ts, src/routing/resolve-route.test.ts)

Codex review notes: model internal, reasoning high; reviewed against 010b61746379.

@steipete
steipete force-pushed the fix/76263-whatsapp-direct-session-isolation branch from 1668e29 to 6523eb7 Compare May 3, 2026 14:47
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Jun 14, 2026
@steipete

steipete commented Jul 5, 2026

Copy link
Copy Markdown
Contributor Author

Closing this stale branch per the latest review. The account-scoped WhatsApp session-isolation problem remains valid, but this branch no longer shares current history and the routing/channel ownership has materially changed. Any remaining gap should be rebuilt from current main, tied to #76263, with current routing tests and real multi-account WhatsApp proof.

@steipete steipete closed this Jul 5, 2026
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 docs Improvements or additions to documentation maintainer Maintainer-authored PR merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: S status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: WhatsApp plugin uses single agent:${id}:main lane for all chats — distinct contacts share session/jsonl/context

1 participant