AI-assisted: Fix OpenAI Responses 400 after model switch (orphaned reasoning item)#1562
Merged
steipete merged 1 commit intoJan 24, 2026
Conversation
301089e to
1a9f186
Compare
Contributor
|
This is a pi issue. |
Contributor
|
Can you attach session logs where this happened? |
Session logs from issue #1540Here are anonymized session logs demonstrating the bug (from the original reporter): {
"description": "Session logs demonstrating issue #1540 - OpenAI reasoning block causes 400 error",
"context": {
"session_type": "Discord channel",
"initial_model": "anthropic/claude-sonnet-4-5",
"switched_to": "openai/gpt-5.2-codex",
"clawdbot_version": "2026.1.16-2"
},
"sequence": [
{
"step": 1,
"description": "User switches model mid-session from Anthropic to OpenAI",
"command": "/model gpt-5.2-codex"
},
{
"step": 2,
"description": "First GPT-5.2-codex response generates thinkingSignature with OpenAI reasoning format",
"log": {
"type": "message",
"timestamp": "2026-01-23T20:32:52.772Z",
"message": {
"role": "assistant",
"content": [
{
"type": "thinking",
"thinking": "**Reading playbook contents**\n\nI am preparing to read the playbook file to retrieve and display its contents as requested.",
"thinkingSignature": {
"id": "rs_07274b660fef5363006973daf27e348190bc09ed53bcc7fa0b",
"type": "reasoning",
"encrypted_content": "[REDACTED - base64 encrypted reasoning content]",
"summary": [
{
"type": "summary_text",
"text": "**Reading playbook contents**..."
}
]
}
}
],
"api": "openai-responses",
"provider": "openai",
"model": "gpt-5.2-codex",
"stopReason": "toolUse"
}
}
},
{
"step": 3,
"description": "All subsequent requests fail with 400 error - orphaned reasoning item",
"logs": [
{
"timestamp": "2026-01-23T20:35:36.968Z",
"message": {
"role": "assistant",
"api": "openai-responses",
"provider": "openai",
"model": "gpt-5.2-codex",
"stopReason": "error",
"errorMessage": "400 Item 'rs_07274b660fef5363006973daf27e348190bc09ed53bcc7fa0b' of type 'reasoning' was provided without its required following item."
}
},
{
"timestamp": "2026-01-23T20:35:58.979Z",
"message": {
"role": "assistant",
"api": "openai-responses",
"provider": "openai",
"model": "gpt-5.2-codex",
"stopReason": "error",
"errorMessage": "400 Item 'rs_07274b660fef5363006973daf27e348190bc09ed53bcc7fa0b' of type 'reasoning' was provided without its required following item."
}
},
{
"timestamp": "2026-01-23T20:39:49.894Z",
"message": {
"role": "assistant",
"api": "openai-responses",
"provider": "openai",
"model": "gpt-5.2-codex",
"stopReason": "error",
"errorMessage": "400 Item 'rs_07274b660fef5363006973daf27e348190bc09ed53bcc7fa0b' of type 'reasoning' was provided without its required following item."
}
}
]
}
],
"root_cause": "The thinkingSignature contains an OpenAI reasoning block ID (rs_...) that gets replayed to the API. OpenAI Responses API requires reasoning blocks to be followed by their corresponding content item. When the history is re-submitted, the orphaned reasoning ID causes a 400 error.",
"workaround_applied": "Manually edited transcript to remove thinkingSignature fields and error messages"
}The bug also reproduced a second time in the same session with a different reasoning ID ( |
steipete
added a commit
that referenced
this pull request
Jan 24, 2026
Contributor
|
Landed via temp rebase onto main.\n\n- Gate: pnpm lint && pnpm build && pnpm test\n- Land commit: 202d7af\n- Merge commit: 202d7af\n\nThanks @roshanasingh4! |
steipete
added a commit
that referenced
this pull request
Jan 24, 2026
dominicnunez
pushed a commit
to dominicnunez/openclaw
that referenced
this pull request
Feb 26, 2026
dustin-olenslager
pushed a commit
to dustin-olenslager/ironclaw-supreme
that referenced
this pull request
Mar 24, 2026
lovewanwan
pushed a commit
to lovewanwan/openclaw
that referenced
this pull request
Apr 28, 2026
ogt-redknie
pushed a commit
to ogt-redknie/OPENX
that referenced
this pull request
May 2, 2026
github-actions Bot
pushed a commit
to Desicool/openclaw
that referenced
this pull request
May 9, 2026
jameslcowan
pushed a commit
to jameslcowan/openclaw
that referenced
this pull request
Jun 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #1540: switching mid-session from Anthropic → OpenAI Responses (e.g.
openai-codex-responses) can corrupt the replayed transcript and trigger:400 Item 'rs_XXXX' of type 'reasoning' was provided without its required following item.This PR sanitizes session history for OpenAI Responses APIs by downgrading orphaned OpenAI
reasoningsignatures stored inthinkingSignature(e.g.{"id":"rs_...","type":"reasoning"}) into plain text (or dropping empty blocks), preventing invalid history re-submission.Changes
downgradeOpenAIReasoningBlocks()and wire into transcript sanitization foropenai-responses+openai-codex-responses.Testing
pnpm vitest run src/agents/pi-embedded-helpers.downgradeopenai-reasoning.test.tsAI transparency
Closes #1540