Skip to content

WhatsApp: filter reasoning messages from delivery (fixes #25214, #24328)#25804

Closed
Lucenx9 wants to merge 7 commits intoopenclaw:mainfrom
Lucenx9:fix/whatsapp-reasoning-leak
Closed

WhatsApp: filter reasoning messages from delivery (fixes #25214, #24328)#25804
Lucenx9 wants to merge 7 commits intoopenclaw:mainfrom
Lucenx9:fix/whatsapp-reasoning-leak

Conversation

@Lucenx9
Copy link
Contributor

@Lucenx9 Lucenx9 commented Feb 24, 2026

Summary

  • Problem: When thinking=low (or any thinking mode) is enabled, the model's reasoning/thinking blocks were being sent to WhatsApp users as visible messages (issues Reasoning/thinking blocks leak into WhatsApp messages #25214, WhatsApp: Internal reasoning exposed as user message #24328).
  • Why it matters: Users were seeing internal model reasoning that should be hidden, causing confusion and poor UX.
  • What changed: Added a filter in deliverWebReply to detect and skip messages that start with "Reasoning:" prefix.
  • What did NOT change: Normal messages that happen to contain "Reasoning:" in the middle are still delivered. Only messages that START with "Reasoning:" are filtered.

Change Type (select all)

  • Bug fix
  • Feature
  • Refactor
  • Docs
  • Security hardening
  • Chore/infra

Scope (select all touched areas)

  • Gateway / orchestration
  • Skills / tool execution
  • Auth / tokens
  • Memory / storage
  • Integrations
  • API / contracts
  • UI / DX
  • CI/CD / infra

Linked Issue/PR

User-visible / Behavior Changes

WhatsApp users will no longer see internal reasoning messages when using models with reasoning capabilities.

Security Impact (required)

  • New permissions/capabilities? (No)
  • Secrets/tokens handling changed? (No)
  • New/changed network calls? (No)
  • Command/tool execution surface changed? (No)
  • Data access scope changed? (No)

Repro + Verification

Environment

  • OS: Linux (tested via unit tests)
  • Channel: WhatsApp Web

Steps

  1. Enable thinking mode with a reasoning-capable model (e.g., thinking=low)
  2. Send a message via WhatsApp
  3. The reasoning block should NOT appear in the delivered message

Expected

  • Only the final answer is delivered to WhatsApp

Actual (before fix)

  • Reasoning block was visible: Reasoning:\n_some internal thinking_

Evidence

  • Failing test/log before + passing after

Added 3 new tests:

  1. Filters out reasoning messages from delivery
  2. Filters out reasoning messages with leading whitespace
  3. Delivers normal messages that contain Reasoning: prefix in the middle

All 12 tests pass (9 existing + 3 new).

Human Verification (required)

  • Verified scenarios:
    • Reasoning message is filtered and not delivered
    • Message with "Reasoning:" in the middle is still delivered
    • Empty/null text is handled correctly
  • Edge cases checked:
    • Leading whitespace before "Reasoning:"
    • Multiple lines of reasoning
  • What you did not verify:
    • Actual WhatsApp Web integration (only unit tests)

Compatibility / Migration

  • Backward compatible? (Yes)
  • Config/env changes? (No)
  • Migration needed? (No)

Failure Recovery (if this breaks)

  • How to disable/revert this change quickly: Revert commit 122dba75c
  • Known bad symptoms reviewers should watch for: Messages that should be delivered are being filtered

Risks and Mitigations

  • Risk: Rare false positive where a user message starts with "Reasoning:"
    • Mitigation: The check only matches the exact prefix "Reasoning:" which is an internal formatting used by OpenClaw. User messages are unlikely to start with this exact string.

Greptile Summary

This PR filters out reasoning messages from WhatsApp delivery to prevent internal model thinking from being visible to end users.

  • Added isReasoningMessage() helper that checks if text starts with Reasoning: prefix after trimming whitespace
  • Early return in deliverWebReply() when reasoning message detected
  • Comprehensive test coverage for reasoning filtering, whitespace handling, and false positives

The fix aligns WhatsApp with other channels (Discord, Matrix, Telegram) that already filter reasoning content. The implementation is simple, focused, and well-tested.

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • Simple, focused bug fix with excellent test coverage and clear documentation. The logic is straightforward (prefix check), tests cover edge cases (whitespace, false positives), and the implementation follows existing patterns in the codebase for other channels.
  • No files require special attention

Last reviewed commit: 9e23685

(3/5) Reply to the agent's comments like "Can you suggest a fix for this @greptileai?" or ask follow-up questions!

@openclaw-barnacle openclaw-barnacle bot added channel: whatsapp-web Channel integration: whatsapp-web size: S size: M and removed size: S labels Feb 24, 2026
@Lucenx9 Lucenx9 force-pushed the fix/whatsapp-reasoning-leak branch from 3b5acd4 to 9e23685 Compare February 24, 2026 21:25
@steipete
Copy link
Contributor

Reviewed end-to-end and reimplemented on main instead of merging this branch directly.

Why not merge as-is:

  • This PR bundles unrelated changes in src/infra/tailnet.ts, src/infra/infra-runtime.test.ts, and src/test-helpers/ssrf.ts alongside the WhatsApp reasoning fix.
  • Landed version is scoped only to the WhatsApp reasoning leak path.

Landed in main via commit:

  • 039713c3e (fix: suppress reasoning payload leakage in whatsapp replies)

What was implemented:

  • src/web/auto-reply/deliver-reply.ts
    • Suppress payloads where replyResult.isReasoning === true.
    • Suppress text payloads that begin with Reasoning: (after leading whitespace trim).
  • src/web/auto-reply/deliver-reply.test.ts
    • Added regressions for isReasoning suppression.
    • Added regressions for Reasoning: prefix suppression.
    • Added guard test ensuring mid-text Reasoning: is still delivered.
  • CHANGELOG.md
    • Added user-facing fix note for WhatsApp reasoning safety.

Verification:

  • pnpm lint && pnpm build && pnpm test (full gate) passed.
  • Focused regression: pnpm test src/web/auto-reply/deliver-reply.test.ts passed.

This resolves #25214 and #24328. Thanks for the report and initial patch, @Lucenx9.

@steipete
Copy link
Contributor

Implemented and landed on main as commit 039713c with scoped changes/tests; closing this PR in favor of the landed commit.

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.

Reasoning/thinking blocks leak into WhatsApp messages WhatsApp: Internal reasoning exposed as user message

2 participants