Skip to content

fix(context_engine): preserve reasoning fields in history projection#101

Open
0xKT wants to merge 1 commit into
mainfrom
fix/issue_89_preserve_reasoning
Open

fix(context_engine): preserve reasoning fields in history projection#101
0xKT wants to merge 1 commit into
mainfrom
fix/issue_89_preserve_reasoning

Conversation

@0xKT

@0xKT 0xKT commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Change description

DeepSeek thinking mode rejects a follow-up turn whose replayed assistant message carried a tool call, with "reasoning_content must be passed back to the API". The two history-projection allowlists dropped reasoning_content / thinking_blocks, so the rebuilt assistant history lost them.

Both keys are now preserved in _history_from_messages (Curator) and _ALLOWED_KEYS (HistoryTrimmer); the provider gate still strips thinking_blocks for non-Anthropic targets. The token estimators (estimate_prompt_tokens / estimate_message_tokens) now count both fields as well, so the preserved payload does not overflow the trim budget on long multi-turn thinking chains.

Type of change

  • Bug fix
  • New feature
  • Document
  • Others

Related issues

Fixes #89

Checklists

Development

  • Lint rules pass locally
  • Application changes have been tested thoroughly
  • Automated tests covering modified code pass

Security

  • Security impact of change has been considered
  • Code follows security best practices and guidelines

Code review

  • Pull request has a descriptive title and context useful to a reviewer. Screenshots or screencasts are attached as necessary

DeepSeek thinking mode rejects a follow-up turn whose replayed assistant
message carried a tool call: "reasoning_content must be passed back to the
API". The two history-projection allowlists dropped reasoning_content and
thinking_blocks, so the rebuilt history lost them. Add both keys to
_history_from_messages (Curator) and _ALLOWED_KEYS (HistoryTrimmer); the
provider gate still strips thinking_blocks for non-Anthropic targets.

Also count both fields in estimate_prompt_tokens and estimate_message_tokens
so the preserved payload does not overflow the trim budget on long
multi-turn thinking chains.

Co-authored-by: Claude (claude-opus-4-8) <noreply@anthropic.com>
@0xKT 0xKT requested review from arelchan, chuanruihu and shallyan July 8, 2026 08:28
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.

deepseek thinking mode breaks on follow-up turns because curator strips reasoning_content from assistant history

1 participant