Skip to content

fix: interleaved reasoning persistence across tool calls#1543

Merged
zerob13 merged 1 commit intodevfrom
codex/toolcall-reasoningcontent
Apr 27, 2026
Merged

fix: interleaved reasoning persistence across tool calls#1543
zerob13 merged 1 commit intodevfrom
codex/toolcall-reasoningcontent

Conversation

@zerob13
Copy link
Copy Markdown
Collaborator

@zerob13 zerob13 commented Apr 27, 2026

Summary

  • Preserve reasoning_content when rebuilding assistant history and resume contexts for interleaved-thinking models.
  • Keep native tool-call messages intact while carrying reasoning through follow-up turns so the next API request can include it again.
  • Add regression coverage for history reconstruction, resume flow, multi-turn tool loops, and AI SDK message mapping.
  • Implementation followed a narrow trace: locate the assistant-message rebuild path, keep reasoning as structured data across tool-call boundaries, then verify the mapped AI SDK payload matches the provider contract.

Testing

  • Added unit and integration-style regressions for contextBuilder, processStream, respondToolInteraction, and aiSdk message mapping.
  • Ran format, i18n, lint, and the related Vitest suites; all passed.

Summary by CodeRabbit

  • Refactor

    • Improved handling of reasoning content preservation across conversation continuity, particularly when the AI uses internal thinking processes alongside tool calls.
  • Tests

    • Added comprehensive test coverage for reasoning content preservation in resumed conversations and tool-call scenarios with interleaved thinking enabled.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 27, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 518fb8be-d6ef-4691-a6f1-d8662f5b715c

📥 Commits

Reviewing files that changed from the base of the PR and between 07375ac and 209c617.

📒 Files selected for processing (5)
  • src/main/presenter/agentRuntimePresenter/contextBuilder.ts
  • test/main/presenter/agentRuntimePresenter/agentRuntimePresenter.test.ts
  • test/main/presenter/agentRuntimePresenter/contextBuilder.test.ts
  • test/main/presenter/agentRuntimePresenter/process.test.ts
  • test/main/presenter/llmProviderPresenter/aiSdkMessageMapper.test.ts

📝 Walkthrough

Walkthrough

Refactors assistant message content assembly in the context builder by centralizing contentParts computation and introducing a helper for applying reasoning metadata. Early returns now preserve reasoning information. Test coverage validates reasoning content preservation across context building, stream processing, and message mapping scenarios for interleaved thinking.

Changes

Cohort / File(s) Summary
Core Logic Refactoring
src/main/presenter/agentRuntimePresenter/contextBuilder.ts
Centralizes contentParts computation and derives assistantContent with conditional logic for provider options. Introduces applyReasoningContent helper for metadata handling. Early returns now preserve reasoning metadata instead of using plain text.
Context & Resume Testing
test/main/presenter/agentRuntimePresenter/agentRuntimePresenter.test.ts, contextBuilder.test.ts, process.test.ts
New test cases covering context building with preserved reasoning, resume flows after tool calls, and multi-round stream processing with reasoning content preservation across interleaved thinking scenarios.
Message Mapping Testing
test/main/presenter/llmProviderPresenter/aiSdkMessageMapper.test.ts
New test validating message mapping produces ordered content array with reasoning blocks preceding text and tool-call parts when both reasoning_content and tool_calls are present.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 Reasoning flows now preserved with care,
Through contexts old and streams so fair,
Helper functions tidy up the way,
Assistant messages dance and play! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: fixing persistence of interleaved reasoning content across tool call boundaries, which aligns with the core objective and implementation changes throughout the PR.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/toolcall-reasoningcontent

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@zerob13 zerob13 marked this pull request as ready for review April 27, 2026 07:07
@zerob13 zerob13 changed the title Fix interleaved reasoning persistence across tool calls fix: interleaved reasoning persistence across tool calls Apr 27, 2026
@zerob13 zerob13 merged commit 91b79b0 into dev Apr 27, 2026
3 checks passed
zerob13 added a commit that referenced this pull request Apr 27, 2026
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.

1 participant