Skip to content

fix(openai): skip reasoning items in Responses API replay#181

Merged
andreynering merged 1 commit intocharmbracelet:mainfrom
kylecarbs:fix/openai-reasoning-replay
Mar 19, 2026
Merged

fix(openai): skip reasoning items in Responses API replay#181
andreynering merged 1 commit intocharmbracelet:mainfrom
kylecarbs:fix/openai-reasoning-replay

Conversation

@kylecarbs
Copy link
Contributor

@kylecarbs kylecarbs commented Mar 19, 2026

When Store is enabled, replaying reasoning items (OfReasoning) in the Responses API input causes a validation error:

Item 'rs_xxx' of type 'reasoning' was provided without its
required following item.

The API stores reasoning server-side and cannot pair a reconstructed reasoning item with the output item that originally followed it. The fix skips reasoning parts during replay, letting the conversation continue with visible assistant content (text / tool calls).

  • I have read CONTRIBUTING.md.
  • I have created a discussion that was approved by a maintainer (for new features).

@kylecarbs kylecarbs marked this pull request as ready for review March 19, 2026 15:17
When Store is enabled, replaying reasoning items (OfReasoning) in
the Responses API input causes a validation error:

  Item 'rs_xxx' of type 'reasoning' was provided without its
  required following item.

The API stores reasoning server-side and cannot pair a reconstructed
reasoning item with the output item that originally followed it.
The fix skips reasoning parts during replay, letting the conversation
continue with visible assistant content (text / tool calls).
@kylecarbs kylecarbs force-pushed the fix/openai-reasoning-replay branch from bb0359a to b71e757 Compare March 19, 2026 15:19
kylecarbs added a commit to coder/coder that referenced this pull request Mar 19, 2026
…#23297)

## Problem

When `Store: true` is set for OpenAI Responses API calls (the new
default), multi-turn conversations with reasoning models fail on the
second message:

```
stream response: bad request: Item 'rs_xxx' of type 'reasoning' was provided
without its required following item.
```

The fantasy library was reconstructing full `OfReasoning` input items
(with encrypted content and summary) when replaying assistant messages.
The API cannot pair these reconstructed reasoning items with the output
items that originally followed them because the output items are sent as
plain `OfMessage` without server-side IDs.

## Fix

Updates the fantasy dependency (`kylecarbs/fantasy@cj/go1.25`) to skip
reasoning parts during conversation replay in `toResponsesPrompt`. With
`Store` enabled, the API already has the reasoning persisted server-side
— it doesn't need to be replayed in the input.

Fantasy PR: charmbracelet/fantasy#181

## Testing

Adds `TestOpenAIReasoningRoundTrip` integration test that:
1. Sends a query to `o4-mini` (reasoning model with `Store: true`)
2. Verifies reasoning content is persisted
3. Sends a follow-up message — this was the failing step
4. Verifies the follow-up completes successfully

Requires `OPENAI_API_KEY` env var to run.
Copy link
Member

@andreynering andreynering left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you again @kylecarbs!

@andreynering andreynering merged commit dff62fa into charmbracelet:main Mar 19, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants