Skip to content

fix(telegram): add reasoning filter to slash command delivery path#38689

Closed
okuyam2y wants to merge 1 commit intoopenclaw:mainfrom
okuyam2y:fix/telegram-slash-reasoning-filter
Closed

fix(telegram): add reasoning filter to slash command delivery path#38689
okuyam2y wants to merge 1 commit intoopenclaw:mainfrom
okuyam2y:fix/telegram-slash-reasoning-filter

Conversation

@okuyam2y
Copy link
Copy Markdown

@okuyam2y okuyam2y commented Mar 7, 2026

Summary

  • Problem: bot-native-commands.ts handles slash commands (/reset, /model, etc.) via dispatchReplyWithBufferedBlockDispatcher, but its deliver callback had no reasoning text filtering. Gemini Flash thinking content (delivered as <think> tags in text) leaks to Telegram users after slash commands, even when reasoning display is off.
  • Why it matters: Users see raw internal reasoning text (Reasoning:\n_thinking content_) in Telegram after /reset and other slash commands.
  • What changed: Added splitTelegramReasoningText filtering to the slash command deliver callback, matching the behavior already present in bot-message-dispatch.ts (regular messages). Reasoning-only payloads with media still deliver media with empty text.
  • What did NOT change (scope boundary): bot-message-dispatch.ts (regular message path), reasoning-lane-coordinator.ts (split logic), reasoning level configuration. Slash commands always suppress reasoning text (no /reasoning on support in this path).

Change Type (select all)

  • Bug fix

Scope (select all touched areas)

  • Integrations

Linked Issue/PR

User-visible / Behavior Changes

Slash command responses in Telegram no longer include leaked reasoning/thinking text from Gemini Flash models when reasoning display is off (the default).

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: macOS
  • Runtime/container: Node 22, OpenClaw gateway via launchd
  • Model/provider: google/gemini-2.5-flash (Google AI native provider)
  • Integration/channel: Telegram DM
  • Relevant config: thinkingDefault: off, reasoningLevel: off (default)

Steps

  1. Configure OpenClaw with Gemini 2.5 Flash and Telegram channel
  2. Send /reset in Telegram DM
  3. Observe the greeting response

Expected

Only the greeting text appears (e.g. "Hello! Is there anything I can help you with?")

Actual (before fix)

A separate message with Reasoning:\n_The user has started a new session..._ appears before the greeting

Evidence

  • Trace/log snippets

Raw stream log before fix shows <think> content in text_delta events, and the text delivered to Telegram includes reasoning prefix. After fix, only answer text is delivered.

The key diagnostic: appendRawStream debug logging in bot-message-dispatch.ts showed zero tg_ events for /reset responses, proving the delivery went through bot-native-commands.ts instead — which had no reasoning filter.

Human Verification (required)

  • Verified scenarios: /reset with Gemini 2.5 Flash on Telegram — reasoning text no longer appears
  • Edge cases checked: reasoning-only + media payloads (deliver media with empty text, matching bot-message-dispatch.ts behavior)
  • What I did not verify: Other slash commands with reasoning-capable models (expected same behavior since they share the same deliver callback)

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 (single file, single function change)
  • Files/config to restore: src/telegram/bot-native-commands.ts
  • Known bad symptoms reviewers should watch for: Slash command responses being silently dropped (would indicate splitTelegramReasoningText false-positiving on non-reasoning text)

Risks and Mitigations

  • Risk: splitTelegramReasoningText could false-positive on legitimate text starting with "Reasoning:" prefix
    • Mitigation: Same risk exists in bot-message-dispatch.ts which has been running in production. The split function uses specific pattern matching (Reasoning:\n_..._) not a broad substring match.
  • Risk: Slash commands always suppress reasoning regardless of /reasoning on setting
    • Mitigation: Slash commands don't have reasoning level UI/state. If reasoning display support is added to slash commands in the future, this filter should be updated to check resolvedReasoningLevel.

bot-native-commands.ts handles slash commands (/reset, /model, etc.)
via dispatchReplyWithBufferedBlockDispatcher, but its deliver callback
had no reasoning text filtering. bot-message-dispatch.ts (regular
messages) already filters via splitTelegramReasoningText.

This causes Gemini Flash thinking content (delivered as <think> tags
in text) to leak to Telegram users after slash commands like /reset,
even when reasoning display is off.

Add splitTelegramReasoningText filtering to the deliver callback:
- Pure reasoning text → skip delivery (or deliver media with empty text)
- Mixed reasoning + answer → deliver answer only

Relates: openclaw#37890, openclaw#26466

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@openclaw-barnacle openclaw-barnacle bot added channel: telegram Channel integration: telegram size: XS labels Mar 7, 2026
okuyam2y added a commit to okuyam2y/openclaw that referenced this pull request Mar 7, 2026
…aw#38689)

Match bot-message-dispatch.ts behavior: reasoning-only payloads with
media deliver media with empty text instead of being silently dropped.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8d7d6a73fa

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +729 to +730
} else {
return;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Avoid dropping slash replies that start with "Reasoning:"

This new early return can silently suppress valid slash-command output because it relies on splitTelegramReasoningText, which currently classifies any text beginning with Reasoning:\n as reasoning-only (splitTelegramReasoningText in src/telegram/reasoning-lane-coordinator.ts, lines 71-75). In scenarios where a user prompt intentionally asks for a response section titled “Reasoning:” and no media is attached, this branch exits before deliverReplies is called, so Telegram receives no message at all.

Useful? React with 👍 / 👎.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Mar 7, 2026

Greptile Summary

This PR fixes a reasoning text leak in Telegram's slash command delivery path. The fix adds splitTelegramReasoningText filtering to the deliver callback inside dispatchReplyWithBufferedBlockDispatcher, matching the filtering already present in bot-message-dispatch.ts for regular messages.

The implementation correctly handles the core cases:

  • No reasoning: payload passes through unchanged
  • Reasoning + answer: reasoning text stripped, answer delivered
  • Reasoning-only + media: media delivered with empty text
  • Reasoning-only + no media: early return, no delivery

The change is a single-function, targeted fix that mirrors an established production-validated pattern. Slash commands always suppress reasoning text (no /reasoning on support in this path), which is correctly documented in comments.

Confidence Score: 5/5

  • Safe to merge — targeted, single-function fix that mirrors an existing production-proven pattern from bot-message-dispatch.ts.
  • This is a well-scoped, low-risk change that adds reasoning text filtering to slash commands using the exact same mechanism already validated in production for regular messages. The filtering logic is correct for all practical use cases. The fix directly addresses the reported issue (reasoning text leaking to Telegram users after slash commands) without side effects or regressions.
  • No files require special attention.

Last reviewed commit: 8d7d6a7

okuyam2y added a commit to okuyam2y/openclaw that referenced this pull request Mar 8, 2026
…aw#38689)

Match bot-message-dispatch.ts behavior: reasoning-only payloads with
media deliver media with empty text instead of being silently dropped.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@okuyam2y
Copy link
Copy Markdown
Author

okuyam2y commented Mar 8, 2026

Closing — this fix has been independently merged into upstream main (same code at bot-native-commands.ts L714-743, including the import at L74). Thanks!

@okuyam2y okuyam2y closed this Mar 8, 2026
okuyam2y added a commit to okuyam2y/openclaw that referenced this pull request Mar 10, 2026
…aw#38689)

Match bot-message-dispatch.ts behavior: reasoning-only payloads with
media deliver media with empty text instead of being silently dropped.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
okuyam2y added a commit to okuyam2y/openclaw that referenced this pull request Mar 11, 2026
…aw#38689)

Match bot-message-dispatch.ts behavior: reasoning-only payloads with
media deliver media with empty text instead of being silently dropped.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
okuyam2y added a commit to okuyam2y/openclaw that referenced this pull request Mar 15, 2026
…aw#38689)

Match bot-message-dispatch.ts behavior: reasoning-only payloads with
media deliver media with empty text instead of being silently dropped.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
okuyam2y added a commit to okuyam2y/openclaw that referenced this pull request Mar 15, 2026
…aw#38689)

Match bot-message-dispatch.ts behavior: reasoning-only payloads with
media deliver media with empty text instead of being silently dropped.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
okuyam2y added a commit to okuyam2y/openclaw that referenced this pull request Mar 16, 2026
…aw#38689)

Match bot-message-dispatch.ts behavior: reasoning-only payloads with
media deliver media with empty text instead of being silently dropped.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
okuyam2y added a commit to okuyam2y/openclaw that referenced this pull request Mar 22, 2026
…aw#38689)

Match bot-message-dispatch.ts behavior: reasoning-only payloads with
media deliver media with empty text instead of being silently dropped.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
okuyam2y added a commit to okuyam2y/openclaw that referenced this pull request Mar 23, 2026
…aw#38689)

Match bot-message-dispatch.ts behavior: reasoning-only payloads with
media deliver media with empty text instead of being silently dropped.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
okuyam2y added a commit to okuyam2y/openclaw that referenced this pull request Mar 24, 2026
…aw#38689)

Match bot-message-dispatch.ts behavior: reasoning-only payloads with
media deliver media with empty text instead of being silently dropped.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
okuyam2y added a commit to okuyam2y/openclaw that referenced this pull request Mar 25, 2026
…aw#38689)

Match bot-message-dispatch.ts behavior: reasoning-only payloads with
media deliver media with empty text instead of being silently dropped.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
okuyam2y added a commit to okuyam2y/openclaw that referenced this pull request Mar 25, 2026
…aw#38689)

Match bot-message-dispatch.ts behavior: reasoning-only payloads with
media deliver media with empty text instead of being silently dropped.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
okuyam2y added a commit to okuyam2y/openclaw that referenced this pull request Mar 28, 2026
…aw#38689)

Match bot-message-dispatch.ts behavior: reasoning-only payloads with
media deliver media with empty text instead of being silently dropped.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: telegram Channel integration: telegram size: XS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant