fix(telegram): flush buffered final answer when reasoning delivery is skipped [AI-assisted]#1342
Open
BingqingLyu wants to merge 2 commits into
Open
fix(telegram): flush buffered final answer when reasoning delivery is skipped [AI-assisted]#1342BingqingLyu wants to merge 2 commits into
BingqingLyu wants to merge 2 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
streaming: "partial"is enabled for Telegram and the model produces a turn with both a thinking block and a text block after a tool call, OpenClaw silently drops the text block (fixes [Bug]: streaming: partial drops text block when assistant turn contains [thinking, text] openclaw/openclaw#53384).flushBufferedFinalAnswer()call before the earlyreturnin the segment delivery loop (bot-message-dispatch.ts) wheninfo.kind === "final". A matching regression test was added.Change Type (select all)
Scope (select all touched areas)
Linked Issue/PR
Root Cause / Regression History (if applicable)
deliverPayload(bot-message-dispatch.ts) processes reasoning and answer segments from a final payload. When a prior turn setactivePreviewLifecycleByLane.reasoning = "complete"(because the answer segment processing at lines 678–683 sawreasoningLane.hasStreamedMessage = true), the reasoning delivery in the next turn returns"skipped"(lifecycle is "complete" → falls tosendPayloadwhich fails). When reasoning is skipped,noteReasoningDelivered()is never called, soreasoningStatusstays"hinted". The answer segment then hitsshouldBufferFinalAnswer() === trueand is buffered. The loop exits via theif (segments.length > 0) { return; }early-return without flushing the buffer.flushBufferedFinalAnswer()call was missing from this early-return path. It existed in thesuppressedReasoningOnlypath directly below (line 696) but not in the segment-processed path.suppressedReasoningOnlybranch already had the flush, making the omission in the segment branch the gap.Regression Test Plan (if applicable)
extensions/telegram/src/bot-message-dispatch.test.ts— "delivers final answer text when reasoning delivery is skipped in combined think-tag payload after tool boundary"onReasoningStreamthen delivers an answer-only final (marking reasoning lifecycle "complete"). AfteronAssistantMessageStart, Turn 2 delivers<think>…</think>answer. The reasoningsendPayloadis mocked to fail ({ delivered: false }), leaving the answer buffered. Without the fix the test fails (answer never delivered); with the fix it passes.User-visible / Behavior Changes
After a tool call in a Telegram conversation with
streaming: partialand a reasoning-capable model, the assistant's text reply will now be delivered instead of silently dropped.Security Impact (required)
Repro + Verification
Environment
streaming: "partial"channels.telegram.streaming: "partial",reasoningLevel: "stream"Steps
streaming: "partial"and a reasoning-capable model.Expected
Actual (before fix)
Evidence
Test fails before fix:
Test passes after fix:
Tests 1 passed (73)Human Verification (required)
bot-message-dispatchtests still pass;pnpm checkclean.noteReasoningDeliveredpath, not the skipped path).suppressedReasoningOnlypath (already had flush, unchanged).Review Conversations
Compatibility / Migration
Failure Recovery (if this breaks)
fix(telegram): flush buffered final answer when reasoning delivery is skipped.Risks and Mitigations
flushBufferedFinalAnswer()is now called even when the buffer is empty (it returns early iftakeBufferedFinalAnswer()returns undefined), so there is no functional risk for the normal (non-bug) path.flushBufferedFinalAnsweris a no-op when no answer is buffered.AI-Assisted PR Checklist
pnpm test:extension telegram(1020 passed),pnpm check,pnpm buildall greenreasoningStepState,activePreviewLifecycleByLane,flushBufferedFinalAnswer, anddeliverLaneTextcall chain