Skip to content

fix(agent): treat a think-only turn as non-actionable - #2751

Merged
zhouyu123666 merged 4 commits into
chaterm:mainfrom
zhouyu123666:fix/agent-think-only-turn
Dec 4, 2026
Merged

zhouyu123666 merged 4 commits into
chaterm:mainfrom
zhouyu123666:fix/agent-think-only-turn

Conversation

@zhouyu123666

@zhouyu123666 zhouyu123666 commented Dec 3, 2026 •

Copy link
Copy Markdown
Collaborator

Related Issue

Refs #2746

Description

MiniMax M2 models (and GLM) return their reasoning inline as a leading <think>...</think> block in content on the OpenAI-compatible endpoint, unless the request sets reasoning_split: true (MiniMax docs). parseAssistantMessageV2 did not treat that block specially, which caused two problems:

  • A turn that only contained reasoning, with no answer and no tool call, was parsed as a normal text block. handleTextBlock then emitted it as completion_result, so the task stopped halfway and waited for the user. This matches the report: the agent stops after a few steps, and sometimes works in a new session.
  • Tool tags mentioned inside the reasoning (for example "I should call <execute_command>") were scanned as tool openers.

Changes in parse-assistant-message.ts:

  • Add LEADING_THINK_BLOCK, which matches a <think> or <thinking> block at the start of the message, including an unclosed block while the stream is still inside the reasoning. Only a leading block counts, which matches how markdownRenderer.vue already renders thinking content.
  • parseAssistantMessageV2 skips over that block without looking for tool tags. The block stays in the text content, so the UI display is unchanged.
  • hasUsableTextContent strips the leading block before deciding whether a turn is usable. A think-only turn now goes through the existing empty-response retry path (handleEmptyAssistantResponse + noToolsUsed), the same path used for markup-only residue in 873a6d8.

Not verified: I have not run this against a live MiniMax endpoint. The fix is checked at the parser level with constructed outputs.

Checklist

  • npm run lint && npm run format && npm run typecheck all pass; tests added/updated as needed.
    • Added 6 tests in parse-assistant-message.test.ts. 3 of them fail without the fix. Changed lines are fully covered.
    • Full vitest run: 4804 passed, 2 failed. The failures are in proxy/undici-dispatcher.test.ts and proxy/https-system-proxy.integration.test.ts. They also fail on main locally (Node 26 rejects an IP address as TLS ServerName, ERR_INVALID_ARG_VALUE) and are unrelated to this change.
  • If UI or user-visible change: i18n and README updated. (No new user-facing text.)

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of <think> and <thinking> blocks so content inside them is not mistaken for tool calls.
    • Reasoning-only turns are now correctly recognized as having no usable response, while turns with a subsequent answer or tool call remain usable.
    • Unclosed reasoning blocks and ordinary mentions of “think” in prose are handled without incorrectly parsing or rejecting the message.
  • Tests
    • Added coverage for reasoning blocks, tool-call parsing, and usable-response detection.

MiniMax and GLM models can return their reasoning inline as a leading
<think> block in the content stream. The parser scanned that block for
tool tags, so a tool name mentioned while thinking could start a tool
call, and a turn that only contained reasoning was treated as the final
answer, which stopped the task halfway.

Skip the leading reasoning block when parsing tool tags and ignore it
when deciding whether a turn is usable, so a think-only turn goes
through the existing empty-response retry path.

Refs: chaterm#2746
@coderabbitai

coderabbitai Bot commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 43dbf2b and 49508e4.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review

Note

.coderabbit.yml has unrecognized properties

CodeRabbit is using all valid settings from your configuration. Unrecognized properties (listed below) have been ignored and may indicate typos or deprecated fields that can be removed.

Parsing warnings: 2

Validation error: Unrecognized keys: "walkthrough", "disable", "collapse_when_outdated", "collapse_when_resolved", "max_comments_per_review", "max_files_per_review" at "reviews"; Unrecognized key: "enabled" at "chat"
Configuration instructions

  • Please see the configuration documentation for more information.
  • You can also validate your configuration using the online YAML validator.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

No actionable comments were generated in the recent review.

Walkthrough

Changes

The parser recognizes leading <think> and <thinking> blocks, including unclosed blocks. It retains the block in the text span and does not scan its contents for tool tags. The usability check removes a leading reasoning block before checking for remaining text.

Layer / File(s) Summary
Parse reasoning blocks and check turn usability
src/main/agent/core/assistant-message/parse-assistant-message.ts, src/main/agent/core/assistant-message/parse-assistant-message.test.ts
The parser skips tool-tag scanning inside a leading reasoning block. The usability check removes that block before checking for remaining text. Tests cover closed and unclosed blocks, tool calls after reasoning, reasoning-only turns, and ordinary prose that mentions <think>.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Possibly related PRs

  • chaterm/Chaterm#2740: This PR also changes assistant-turn usability checks and parseAssistantMessageV2.

Suggested reviewers: lijinxiao1982, fishyu-mushroom

Merge Risk: Minimal · previous review add39

This change stops reasoning-only turns from being treated as final answers and stops tool names mentioned in reasoning from being parsed as tool calls. No merge-blocking risk was identified, and the new parser tests cover the changed behavior.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title "fix(agent): treat a think-only turn as non-actionable" names the main change. The PR makes parseAssistantMessageV2 skip a leading / block when scanning for tool tags, and m…
Description check Passed The description follows the repository template. It includes the related issue (Refs discussion #2746, not the template's 'Resolves #(issue_number)' form), a detailed Description section explaining th…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "fix(agent): treat a think-only turn as non-actionable" names the main change. The PR makes parseAssistantMessageV2 skip a leading <think>/<thinking> block when scanning for tool tags, and makes hasUsableTextContent strip that block so a reasoning-only turn goes through the empty-response retry path. The title is concise, specific, and follows a conventional commit style.

Full details: Description check

Explanation

The description follows the repository template. It includes the related issue (Refs discussion #2746, not the template's 'Resolves #(issue_number)' form), a detailed Description section explaining the root cause, the changes in parse-assistant-message.ts, and testing notes. The checklist is filled in. The lint/format/typecheck item is checked and the i18n item is marked not applicable with a reason. The related issue line uses 'Refs' rather than 'Resolves', which is a minor deviation and does not affect the check.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 71d8435 and add3964.

Files selected for processing: 2

  • src/main/agent/core/assistant-message/parse-assistant-message.test.ts
  • src/main/agent/core/assistant-message/parse-assistant-message.ts

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 5 remain after this review.

@codecov

codecov Bot commented Dec 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@zhouyu123666
zhouyu123666 merged commit cb9427b into chaterm:main Dec 4, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants