Skip to content

fix(telegram): gate reasoning previews to stream sessions#61266

Merged
vincentkoc merged 2 commits intoopenclaw:mainfrom
vincentkoc:issue-telegram-reasoning-preview
Apr 5, 2026
Merged

fix(telegram): gate reasoning previews to stream sessions#61266
vincentkoc merged 2 commits intoopenclaw:mainfrom
vincentkoc:issue-telegram-reasoning-preview

Conversation

@vincentkoc
Copy link
Copy Markdown
Member

Summary

  • Problem: Telegram currently allocates a reasoning preview lane whenever answer preview streaming is enabled, even when the session is not explicitly set to reasoning:stream.
  • Why it matters: that wider callback surface makes it possible for hidden <think> or backend reasoning deltas to surface as Telegram preview messages on normal sessions.
  • What changed: gate Telegram reasoning preview creation strictly to sessions whose persisted reasoning level is stream, and add a regression test that verifies no reasoning preview callback is exposed otherwise.
  • What did NOT change (scope boundary): this PR does not remove intentional Telegram reasoning previews for reasoning:stream sessions, and it does not change shared model reasoning semantics.

Change Type (select all)

  • Bug fix
  • Feature
  • Refactor required for the fix
  • 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

  • Closes #
  • Related #
  • This PR fixes a bug or regression

Root Cause (if applicable)

  • Root cause: extensions/telegram/src/bot-message-dispatch.ts enabled the reasoning draft lane with canStreamAnswerDraft || streamReasoningDraft, so normal answer preview streaming created a reasoning-preview callback even when the session reasoning level was off.
  • Missing detection / guardrail: no regression test asserted that Telegram must not expose onReasoningStream outside explicit reasoning:stream sessions.
  • Contributing context (if known): some backends and model outputs can produce reasoning-style deltas or <think> traces, so an overly broad Telegram preview lane is risky.

Regression Test Plan (if applicable)

  • Coverage level that should have caught this:
    • Unit test
    • Seam / integration test
    • End-to-end test
    • Existing coverage already sufficient
  • Target test or file: extensions/telegram/src/bot-message-dispatch.test.ts
  • Scenario the test should lock in: normal Telegram sessions do not expose a reasoning preview callback and only create the answer preview lane unless the session reasoning level is stream.
  • Why this is the smallest reliable guardrail: the bug is localized to Telegram preview-lane setup.
  • Existing test that already covers this (if any): existing reasoning preview tests cover explicit reasoning:stream behavior, but not the off/default case.
  • If no new test is added, why not: N/A

User-visible / Behavior Changes

  • Telegram no longer surfaces hidden reasoning traces as preview bubbles on normal streaming sessions.
  • Explicit reasoning:stream Telegram sessions keep their separate reasoning preview lane.

Diagram (if applicable)

Before:
[normal Telegram preview streaming] -> [answer lane + reasoning lane allocated] -> [possible accidental reasoning preview]

After:
[normal Telegram preview streaming] -> [answer lane only]
[reasoning:stream session] -> [answer lane + reasoning lane]

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)
  • If any Yes, explain risk + mitigation:

Repro + Verification

Environment

  • OS: macOS
  • Runtime/container: local Codex worktree
  • Model/provider: OpenAI Codex / GPT-5.4 suspicion path reviewed in code
  • Integration/channel (if any): Telegram
  • Relevant config (redacted): friend sample config reviewed separately; issue here is session-state + lane wiring, not the static config itself

Steps

  1. Run a normal Telegram session without reasoning:stream.
  2. Stream a reply containing hidden reasoning fragments or backend reasoning deltas.
  3. Observe whether Telegram creates a separate reasoning preview bubble.

Expected

  • Normal sessions should not expose a Telegram reasoning preview lane.

Actual

  • Before this patch, Telegram allocated the reasoning lane whenever normal answer preview streaming was enabled.

Evidence

Attach at least one:

  • Failing test/log before + passing after
  • Trace/log snippets
  • Screenshot/recording
  • Perf numbers (if relevant)

Human Verification (required)

What you personally verified (not just CI), and how:

  • Verified scenarios: traced the Telegram reasoning-lane setup, shared onReasoningStream routing, and added a regression test for the default/off session case.
  • Edge cases checked: explicit reasoning:stream sessions still allocate the reasoning preview lane; default/off sessions now only allocate the answer preview lane.
  • What you did not verify: the targeted pnpm test:serial run for the new Telegram regression test reached RUN but did not yield a clean exit signal in this workspace.

Review Conversations

  • I replied to or resolved every bot review conversation I addressed in this PR.
  • I left unresolved only the conversations that still need reviewer or maintainer judgment.

Compatibility / Migration

  • Backward compatible? (Yes)
  • Config/env changes? (No)
  • Migration needed? (No)
  • If yes, exact upgrade steps:

Risks and Mitigations

  • Risk: if some Telegram flow was implicitly relying on a reasoning lane during non-stream sessions, this narrows that behavior.
    • Mitigation: explicit reasoning:stream sessions remain unchanged, which is the intended feature boundary.

AI / Testing Notes

  • AI-assisted: yes
  • Testing: lightly tested locally; targeted pnpm test:serial reached RUN but did not return a clean exit signal in this workspace.

@vincentkoc vincentkoc self-assigned this Apr 5, 2026
@openclaw-barnacle openclaw-barnacle Bot added channel: telegram Channel integration: telegram size: XS maintainer Maintainer-authored PR labels Apr 5, 2026
@vincentkoc vincentkoc marked this pull request as ready for review April 5, 2026 09:17
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Apr 5, 2026

Greptile Summary

This PR fixes a bug in the Telegram integration where a reasoning preview lane was incorrectly allocated for any session with answer preview streaming enabled — not just those explicitly set to reasoning:stream. The fix is a one-line change in bot-message-dispatch.ts (line 216) that simplifies canStreamReasoningDraft from canStreamAnswerDraft || streamReasoningDraft to just streamReasoningDraft, making the lane creation gate consistent with the downstream onReasoningStream callback guard that was already correctly conditioned on reasoningLane.stream.

Key changes:

  • extensions/telegram/src/bot-message-dispatch.ts: Gate reasoning draft lane creation strictly to resolvedReasoningLevel === "stream" sessions, eliminating the spurious lane for normal streaming sessions.
  • extensions/telegram/src/bot-message-dispatch.test.ts: Adds a focused regression test (line 542–559) that asserts onReasoningStream is undefined in replyOptions and that createTelegramDraftStream is called exactly once (answer lane only) when the session has no explicit reasoning:stream setting.
  • CHANGELOG.md: Entry correctly appended at the end of the ### Fixes section for the active version block, with proper attribution.

Confidence Score: 4/5

Safe to merge — the fix is minimal, correct, and well-tested with a direct regression assertion.

One-line logic fix with a targeted regression test. The downstream callback guard at line 773 was already correct; this aligns the lane creation condition with it. No edge cases for explicit reasoning:stream sessions are affected. Score is 4 rather than 5 only because the author noted the local test run did not return a clean exit signal, so CI green is the final confirmation.

No files require special attention.

Reviews (1): Last reviewed commit: "Merge branch 'main' into issue-telegram-..." | Re-trigger Greptile

@vincentkoc vincentkoc merged commit 4954d02 into openclaw:main Apr 5, 2026
20 of 31 checks passed
lovewanwan pushed a commit to lovewanwan/openclaw that referenced this pull request Apr 28, 2026
ogt-redknie pushed a commit to ogt-redknie/OPENX that referenced this pull request May 2, 2026
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: telegram Channel integration: telegram maintainer Maintainer-authored PR size: XS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant