Skip to content

fix(cli): hide thinking end tokens#12109

Closed
Githubguy132010 wants to merge 4 commits into
Kilo-Org:mainfrom
Githubguy132010:githubguy132010-fix-thinking-end-token-leak
Closed

fix(cli): hide thinking end tokens#12109
Githubguy132010 wants to merge 4 commits into
Kilo-Org:mainfrom
Githubguy132010:githubguy132010-fix-thinking-end-token-leak

Conversation

@Githubguy132010

Copy link
Copy Markdown
Contributor

Issue

Fixes #11982

Context

Some BYOK reasoning models, including MiniMax M3, emit model-specific thinking terminators as visible text deltas. These markers appeared in the final assistant message because providers do not consistently classify them as reasoning content.

Implementation

Filter known thinking end markers at the AI SDK stream adapter boundary before text reaches session processing. The filter buffers only a possible marker suffix so delimiters split across streaming chunks are removed without delaying ordinary text, and flushes unmatched partial text when a text block ends.

Screenshots / Video

N/A — no visual changes.

How to Test

Manual/local verification

  • Agent executed bun test ././test/kilocode/reasoning-token.test.ts ././test/session/llm.test.ts from packages/opencode (33 tests passed).
  • Agent executed bun run typecheck from packages/opencode successfully.
  • Agent executed root bun run lint successfully (pre-existing warnings only).
  • Agent executed bun run script/check-opencode-annotations.ts successfully.

Reviewer test steps

  1. Stream text deltas containing <|end▁of▁thinking|>, including with the marker split between deltas.
  2. Confirm the final visible text excludes the marker.
  3. Stream ordinary text ending with a partial tag-like < and confirm it is preserved when the text block ends.

Blocked checks and substitute verification

  • None.

Checklist

  • Issue linked above, or exception explained
  • Tests/verification described
  • Screenshots/video included for visual changes, or marked N/A
  • Changeset considered for user-facing changes
  • I personally reviewed the diff and can explain the changes, including any AI-assisted work.

Get in Touch

GitHub: @Githubguy132010

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Comment thread packages/opencode/src/kilocode/reasoning-token.ts Outdated
Comment thread packages/opencode/src/session/llm/ai-sdk.ts Outdated
Comment thread packages/opencode/src/session/llm/ai-sdk.ts Outdated
@kilo-code-bot

kilo-code-bot Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Files Reviewed (4 files)
  • packages/opencode/src/kilocode/reasoning-token.ts
  • packages/opencode/src/session/llm.ts
  • packages/opencode/src/session/llm/ai-sdk.ts
  • packages/opencode/test/kilocode/reasoning-token.test.ts
Previous Review Summaries (2 snapshots, latest commit 07e2e0b)

Current summary above is authoritative. Previous snapshots are kept for context only.

Previous review (commit 07e2e0b)

Status: 2 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 2
SUGGESTION 0
Issue Details (click to expand)

WARNING

File Line Issue
packages/opencode/src/kilocode/reasoning-token.ts 11 Terminal cleanup leaves per-block state behind
packages/opencode/src/session/llm/ai-sdk.ts 264 Error termination still drops buffered ordinary text

Fix these issues in Kilo Cloud

Files Reviewed (3 files)
  • packages/opencode/src/kilocode/reasoning-token.ts - 1 issue
  • packages/opencode/src/session/llm/ai-sdk.ts - 1 issue
  • packages/opencode/test/kilocode/reasoning-token.test.ts - 0 issues

Previous review (commit d6daabb)

Status: 3 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 3
SUGGESTION 0
Issue Details (click to expand)

WARNING

File Line Issue
packages/opencode/src/kilocode/reasoning-token.ts 10 Literal marker text is removed outside provider terminator positions
packages/opencode/src/session/llm/ai-sdk.ts 18 Provider-controlled IDs can resolve inherited dictionary properties and corrupt output
packages/opencode/src/session/llm/ai-sdk.ts 116 Buffered ordinary text is lost when a stream terminates without text-end

Fix these issues in Kilo Cloud

Files Reviewed (4 files)
  • .changeset/quiet-thoughts-end.md - 0 issues
  • packages/opencode/src/kilocode/reasoning-token.ts - 1 issue
  • packages/opencode/src/session/llm/ai-sdk.ts - 2 issues
  • packages/opencode/test/kilocode/reasoning-token.test.ts - 0 issues

Reviewed by gpt-5.6-sol-20260709 · Input: 59.6K · Output: 6.5K · Cached: 316.6K

Review guidance: REVIEW.md from base branch main

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Comment thread packages/opencode/src/kilocode/reasoning-token.ts
Comment thread packages/opencode/src/session/llm/ai-sdk.ts
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@chrarnoldus chrarnoldus self-assigned this Jul 13, 2026
@chrarnoldus

Copy link
Copy Markdown
Collaborator

This is a provider-side issue, we shouldn't fix it in the client.

@Githubguy132010
Githubguy132010 deleted the githubguy132010-fix-thinking-end-token-leak branch July 16, 2026 14:50
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.

Thinking end tokens leak into the message

2 participants