#2647·rig

bug: openai responses replay moves interleaved reasoning before assistant text

Author: kanyesthakerCreated Sep 30, 2026Updated Sep 30, 2026
Labelsbug
  • I have looked for existing issues (including closed) about this

Bug Report

The OpenAI Responses request conversion changes the order of reasoning and text items in an assistant message. This occurs in published rig-core 0.43.0, including the changes from #2639, and subsequently causes missing reasoning errors.

For an assistant message with this content order:

reasoning rs_1 -> text msg_1 -> reasoning rs_2

Rig builds the next OpenAI request with this order:

reasoning rs_1 -> reasoning rs_2 -> text msg_1

We found this while investigating an OpenAI Responses failure in our app, which uses Rig 0.42.0 with gpt-6.1-sol. After a tool result, the next request failed with:

Item 'msg_...' of type 'message' was provided without its required 'reasoning' item: 'rs_...'.

Our application converts Rig messages to its own stored format and back, but we verified the conversion using only native Rig types and reproduced the issue.

Reproduction

Below example just passes data through the API (no actual model calls)

Cargo.toml:

toml
[package]
name = "rig-order-repro"
version = "0.1.0"
edition = "2024"

[dependencies]
rig-core = { version = "=0.43.0", default-features = false }
serde_json = "1"

src/main.rs:

rust
use rig_core::{
    completion::{CompletionRequest, Message},
    message::{AssistantContent, Reasoning, ReasoningContent, Text},
    providers::openai::responses_api::{
        CompletionRequest as OpenAIRequest, ResponsesRequestParams,
    },
};
fn reasoning(id: &str) -> AssistantContent {
    AssistantContent::Reasoning(
        Reasoning {
            id: Some(id.into()),
            content: vec![ReasoningContent::Encrypted(format!("encrypted-{id}"))],
        }
        .sealed("openai"),
    )
}
fn main() -> Result<(), Box<dyn std::error::Error>> {
    let assistant = Message::Assistant {
        id: Some("msg_1".into()),
        content: vec![
            reasoning("rs_1"),
            AssistantContent::Text(Text::new("Checking the computer.")),
            reasoning("rs_2"),
        ],
    };
    let mut request = CompletionRequest::new(Message::user("Inspect the computer."));
    request.chat_history.push(assistant);
    request.chat_history.push(Message::user("Continue."));
    let output = OpenAIRequest::try_from(ResponsesRequestParams {
        model: "gpt-6.1-sol".into(),
        request,
        system_instructions_placement: Default::default(),
        issuers: vec!["openai".into()],
    })?;
    let wire = serde_json::to_value(output)?;
    let ids = wire["input"]
        .as_array()
        .ok_or("missing input array")?
        .iter()
        .filter_map(|item| item["id"].as_str())
        .collect::<Vec<_>>();
    println!("Input assistant order: rs_1, msg_1, rs_2");
    println!("Rig 0.43.0 OpenAI request order: {:?}", ids);
    Ok(())
}

Expected behavior

The request should retain the original relative order of reasoning, text, and tool call items when it replays an assistant response. Here, the item IDs should remain:

rs_1, msg_1, rs_2

OpenAI's reasoning guide says that manually managed history must retain the response output items between the last user message and the tool result.

Screenshots

console output from the above repro

Input assistant order: rs_1, msg_1, rs_2
Rig 0.43.0 OpenAI request order: ["rs_1", "rs_2", "msg_1"]

Additional context

  • The TryFrom<Message> for Vec<InputItem> conversion in src/providers/openai/responses_api/mod.rs collects reasoning and other items separately, then places the reasoning items first. This behavior is present in both 0.42.0 and 0.43.0.
  • PR #2639 fixes assistant message IDs and phase preservation. Its limitations section explicitly notes that reasoning between two messages still replays before both. This report concerns that remaining order limitation.
  • Issue #1892 addressed reasoning that was appended after assistant text during streaming. It explains why putting reasoning first helped that case. Here, the original output has reasoning on both sides of text, so placing all reasoning first changes that sequence.