Skip to content

fix(utils): strip Qwen3.6 thinking blocks with close-only tag - #1530

Open
syf2211 wants to merge 1 commit into
sigoden:mainfrom
syf2211:fix/1528-qwen36-thinking-close-tag
Open

syf2211 wants to merge 1 commit into
sigoden:mainfrom
syf2211:fix/1528-qwen36-thinking-close-tag

Conversation

@syf2211

@syf2211 syf2211 commented Jun 25, 2026

Copy link
Copy Markdown

Summary

Fix strip_think_tag() so Qwen3.6 local thinking output is removed before execute (-e) and other code-extraction paths.

Motivation

Qwen3.6 embeds the opening think marker in the chat template, so model output only contains reasoning text followed by </think> without a matching opening tag. The existing regex required <think>..., leaving thinking content in -e output (fixes #1528).

Changes

  • Add THINK_CLOSE_ONLY_RE to strip from start of text through the first </think> when no opening tag is present
  • Keep the existing full-tag regex as the first pass for all other providers
  • Add regression tests for tagged, close-only, and plain outputs

Tests

cargo test test_strip_think
cargo test
  • test_strip_think_tag_with_opening_tag — ok
  • test_strip_think_tag_close_only_qwen36 — ok
  • test_strip_think_tag_without_thinking — ok
  • Full suite: 24 passed

Notes

Close-only stripping only runs when </think> is present and <think> is absent anywhere in the text, matching the Qwen3.6 template behavior described in the issue.

Fixes #1528

ei-grad added a commit to ei-grad/aichat that referenced this pull request Jul 11, 2026
Strip Qwen-style reasoning only when a lone closing think tag forms a
standalone line after a non-empty prefix. Preserve inline, repeated, fenced,
and otherwise ambiguous literal close tags so unrelated answer content is not
removed without the structural reasoning pattern.

Add regression coverage for full tags, close-only output, CRLF and whitespace,
plain responses, literal markers, and fenced adversarial examples. This
materially reworks the close-only handling proposed in:
sigoden#1530

Co-Authored-By: Codex CLI <noreply@openai.com>
ei-grad added a commit to ei-grad/aichat that referenced this pull request Jul 11, 2026
Integrate the exact upstream PR head and preserve its original commit and
authorship. A separate boundary follow-up narrows the matcher so ambiguous,
inline, repeated, and fenced literal tags remain intact.

Source: sigoden#1530
Head: c559c1d
ei-grad added a commit to ei-grad/aichat that referenced this pull request Jul 11, 2026
Retain the close-only Qwen use case from upstream PR sigoden#1530 while requiring a
standalone structural close-tag boundary. Preserve inline, repeated, fenced,
and otherwise ambiguous literal markers, with tests for CRLF, whitespace, and
full tagged responses.

Source: sigoden#1530
Reviewed behavior: ab9e551

Co-Authored-By: Codex CLI <noreply@openai.com>
ei-grad added a commit to ei-grad/aichat that referenced this pull request Jul 11, 2026
Integrate the named boundary-hardening branch after the exact sigoden#1530 import.
The second parent preserves the reviewed matcher and its ambiguous-literal
regression tests as a distinct repair delta.

Source: sigoden#1530
Qwen3.6 local models embed the opening think marker in the chat
template, so model output only includes reasoning text followed by
</think>. strip_think_tag previously required a matching
opening tag, leaving thinking content in -e / execute output.

Also handle close-only blocks when no opening tag is present, and add
regression tests for both tagged and Qwen3.6-style outputs.
@syf2211
syf2211 force-pushed the fix/1528-qwen36-thinking-close-tag branch from c559c1d to fde7163 Compare September 8, 2026 00:26
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.

Qwen3.6 thinking mode without <think> tag

1 participant