Skip to content

Conversation

448523760
Copy link

@448523760 448523760 commented Sep 26, 2025

Problem

The is_api_message function in conversation_history.rs had a misalignment between its documentation and implementation:

  • Comment stated: "Anything that is not a system message or 'reasoning' message is considered an API message"
  • Code behavior: Was returning true for ResponseItem::Reasoning, meaning reasoning messages were incorrectly treated as API messages

This inconsistency could lead to reasoning messages being persisted in conversation history when they should be filtered out.

Root Cause

Investigation revealed that reasoning messages are explicitly excluded throughout the codebase:

  1. Chat completions API (lines 267-272 in chat_completions.rs) omits reasoning from conversation history:

    ResponseItem::Reasoning { .. } | ResponseItem::Other => {
        // Omit these items from the conversation history.
        continue;
    }
  2. Existing tests like drops_reasoning_when_last_role_is_user and ignores_reasoning_before_last_user validate that reasoning should be excluded from API payloads

Solution

Fixed the is_api_message function to align with its documentation and the rest of the codebase:

// Before: Reasoning was incorrectly returning true
ResponseItem::Reasoning { .. } | ResponseItem::WebSearchCall { .. } => true,

// After: Reasoning correctly returns false  
ResponseItem::WebSearchCall { .. } => true,
ResponseItem::Reasoning { .. } | ResponseItem::Other => false,

Testing

  • Enhanced existing test to verify reasoning messages are properly filtered out
  • All 264 core tests pass, including 8 chat completions tests that validate reasoning behavior
  • No regressions introduced

This ensures reasoning messages are consistently excluded from API message processing across the entire codebase.

Copy link

github-actions bot commented Sep 26, 2025

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@448523760
Copy link
Author

448523760 commented Sep 26, 2025

I have read the CLA Document and I hereby sign the CLA

@448523760 448523760 force-pushed the copilot/fix-f26cc6d3-48da-44d8-bc1a-27be573b5e4a branch 2 times, most recently from 1f548e2 to ea17182 Compare September 26, 2025 16:18
@448523760
Copy link
Author

recheck

github-actions bot added a commit that referenced this pull request Sep 26, 2025
@448523760
Copy link
Author

@codex review

Copy link
Contributor

Codex Review: Didn't find any major issues. Can't wait for the next one!

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

@448523760
Copy link
Author

Hi @jif-oai, could you please take a look at this PR when you have time?

@448523760 448523760 force-pushed the copilot/fix-f26cc6d3-48da-44d8-bc1a-27be573b5e4a branch from 9d33903 to 0a219fe Compare September 27, 2025 09:38
@448523760 448523760 force-pushed the copilot/fix-f26cc6d3-48da-44d8-bc1a-27be573b5e4a branch from 0a219fe to 94a763b Compare September 28, 2025 04:50
@448523760
Copy link
Author

448523760 commented Sep 28, 2025

rebased onto main

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