Skip to content

cli : persist reasoning_content in chat history - #26362

Merged
ngxson merged 2 commits into
ggml-org:masterfrom
ramicaza:fix-cli-preserve-reasoning-content
Aug 1, 2026
Merged

ngxson merged 2 commits into
ggml-org:masterfrom
ramicaza:fix-cli-preserve-reasoning-content

Conversation

@ramicaza

@ramicaza ramicaza commented Jul 31, 2026 •

Copy link
Copy Markdown
Contributor

Overview

There's a bug where llama-cli essentially ignores --reasoning-preserve arg or templates with preserve_thinking (e.g. Qwen3.6). It was caused by content.reasoning not being filled in on subsequent turns' templates.

llama-cli streams assistant thinking into content.reasoning, but when appending the assistant message to chat history it only stored content.content and not content.reasoning. On the next turn the prompt had no prior thoughts.

Additional information

Manual check:

  • Build llama-cli
  • Run a reasoning model with --reasoning-preserve
  • Turn 1: ask it to pick a secret number 1-100 and only reply "OK ready"
  • Note the number in the thinking / reasoning output
  • Turn 2: guess a wrong number and ask yes/no plus the actual number
  • Confirm turn 2 reasoning/answer matches the turn 1 number

Requirements

  • I have read and agree with the contributing guidelines
  • AI usage disclosure: YES - Cursor used to locate the CLI history append path and apply the one-file change

llama-cli collected reasoning from the stream for display but only
stored assistant content in messages, so --reasoning-preserve could
not re-inject prior thoughts on later turns.

Co-authored-by: Cursor <[email protected]>
@ramicaza
ramicaza requested a review from ngxson as a code owner July 31, 2026 09:16
@ggml-gh-bot

ggml-gh-bot Bot commented Jul 31, 2026

Copy link
Copy Markdown

Hi @ramicaza, thanks for your contribution!

Per our contribution guidelines, the automated PR checker found the following issue(s) that need your attention:

  • PR Template not respected: Please respect the template when creating a new pull request. Make sure to fill out all required sections.

Please note that maintainers reserve the right to make final decisions on PRs. If you believe there is a mistake, please comment below.

@ramicaza

ramicaza commented Jul 31, 2026 •

Copy link
Copy Markdown
Contributor Author

Ok I updated the PR to match the template @ngxson

Comment thread tools/cli/cli-context.cpp Resolved

@ngxson ngxson left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @pwilkin for visibility

@ngxson
ngxson merged commit c629da5 into ggml-org:master Aug 1, 2026
23 of 26 checks passed
satindergrewal pushed a commit to satindergrewal/llama.cpp that referenced this pull request Aug 12, 2026
* cli : persist reasoning_content in chat history

llama-cli collected reasoning from the stream for display but only
stored assistant content in messages, so --reasoning-preserve could
not re-inject prior thoughts on later turns.
cubetitled-ui pushed a commit to cubetitled-ui/llama.cpp that referenced this pull request Aug 14, 2026
* cli : persist reasoning_content in chat history

llama-cli collected reasoning from the stream for display but only
stored assistant content in messages, so --reasoning-preserve could
not re-inject prior thoughts on later turns.
thecodacus pushed a commit to thecodacus/llama.cpp that referenced this pull request Sep 7, 2026
* cli : persist reasoning_content in chat history

llama-cli collected reasoning from the stream for display but only
stored assistant content in messages, so --reasoning-preserve could
not re-inject prior thoughts on later turns.
zbrad pushed a commit to zbrad/llama.cpp that referenced this pull request Sep 10, 2026
* cli : persist reasoning_content in chat history

llama-cli collected reasoning from the stream for display but only
stored assistant content in messages, so --reasoning-preserve could
not re-inject prior thoughts on later turns.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants