Skip to content

fix(ai): split streamed reasoning when only </think> arrives - #1001

Merged
altic-dev merged 2 commits into
altic-dev:mainfrom
Lstarsky0:fix/streaming-orphan-think-close
Oct 1, 2026
Merged

altic-dev merged 2 commits into
altic-dev:mainfrom
Lstarsky0:fix/streaming-orphan-think-close

Conversation

@Lstarsky0

Copy link
Copy Markdown
Contributor

Description

With streaming, a response shaped like reasoning</think>answer keeps the reasoning in the content. Qwen3 Thinking-2507 answers this way by design (its chat template already opens <think> in the prompt), and a server that doesn't split reasoning out passes it straight through. StandardThinkingParser never sees an opening tag, emits everything as content, and finalize only strips the tag, so AI cleanup of a dictation, which always streams, inserts the model's reasoning along with the answer.

The non-streaming path already splits this in stripThinkingTags. This does the same in StandardThinkingParser.finalize when no opening tag was seen, so a stray close after a real <think> block (#836) is still left alone.

Type of Change

  • 🐞 Bug fix
  • ✨ New feature
  • 💥 Breaking change
  • 🧹 Chore
  • 📝 Documentation update

Related Issue or Discussion

Related to #836, same parsing on the non-streaming side. No separate issue.

Testing

  • Tested on Intel Mac
  • Tested on Apple Silicon Mac
  • Tested on macOS version: 27.0
  • Ran linter locally: swiftlint --strict --config .swiftlint.yml (clean)
  • Ran formatter locally: swiftformat --config .swiftformat Sources (not installed here)
  • Ran tests locally: CI's xcodebuild test command with the same skip, 1716 tests, 0 failures. The new testTagParserSplitsReasoningWhenOnlyCloseTagStreams fails without the parser change (content comes back as Reasoning.Ready.).

Screenshots / Video

  • No UI/visual changes; screenshots/video are not applicable.

Notes

Model names containing "deepseek" go to SeparateFieldThinkingParser, which doesn't look at inline tags at all, so the same output still leaks there. Left that for a separate change.

Chat templates that open the think block in the prompt (Qwen3
Thinking-2507) stream "reasoning</think>answer". StandardThinkingParser
never saw an opening tag, so the reasoning stayed in the content.
Split on that close in finalize when no opening tag was seen, as
stripThinkingTags already does for non-streaming responses.
@greptile-apps

greptile-apps Bot commented Sep 23, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 5/5

The PR appears safe to merge; the previous closing-tag ordering defect is resolved and no new actionable issues were identified.

Summary

This PR fixes streamed reasoning parsing for models whose chat templates supply the opening thinking tag and whose response contains only the closing tag.

  • Tracks whether the stream contained an explicit opening thinking tag.
  • Splits close-only streams into reasoning and visible content at the earliest supported closing tag.
  • Adds integration coverage for chunk-split and mixed closing-tag responses.
  • The follow-up changes resolve the previous review finding by choosing the earliest closing tag regardless of tag spelling.

Reviews (2) · Last reviewed commit: "fix(ai): split on the earliest closing t..."

Preferring </think> over </thinking> regardless of position hid answer
text when a </thinking> separator was followed by a stray </think>.
stripThinkingTags matches whichever comes first; do the same.
@altic-dev
altic-dev merged commit 14f8457 into altic-dev:main Oct 1, 2026
2 checks passed
@altic-dev altic-dev mentioned this pull request Oct 1, 2026
8 of 12 tasks
renato-dransay added a commit to renato-dransay/FluidVoice that referenced this pull request Oct 1, 2026
Brings in altic-dev/FluidVoice f0ef01c (unbounded FluidMeeting recording
memory growth, altic-dev#1034) and 14f8457 (split streamed reasoning when only
</think> arrives, altic-dev#1001).

Conflict resolution:
- MeetingAudioChunkWriter: adopt upstream's reportWriterFailure episode
  reporting, which covers append, chunk-start and finalization failures.
  It replaces the fork's lastNoChunkFailureDetail dedupe.
- MeetingPCMFormatContractError: adopt upstream's "Unsupported PCM format:
  <reason>." description; keep the fork's MeetingPCMFormatNormalizer.
- MeetingAudioChunkSinkTests: keep both helper recorders and update the
  fork's normalizer tests to the upstream error text.
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