Skip to content

fix(providers/openai): emit item_reference for reasoning items when store=true#7

Closed
ibetitsmike wants to merge 6 commits intocoder:cj/go1.25from
ibetitsmike:mike/fix-reasoning-websearch-replay
Closed

fix(providers/openai): emit item_reference for reasoning items when store=true#7
ibetitsmike wants to merge 6 commits intocoder:cj/go1.25from
ibetitsmike:mike/fix-reasoning-websearch-replay

Conversation

@ibetitsmike
Copy link
Copy Markdown

When an OpenAI reasoning model (e.g. o4-mini) produces both reasoning output and a provider-executed web_search_call in the same response, the follow-up turn fails because:

  • The web_search_call is replayed via item_reference(toolCallID) when store=true
  • But the reasoning item that preceded it is skipped entirely
  • OpenAI rejects this: "reasoning was provided without its required following item"

Fix: When store=true, emit item_reference for reasoning items using the persisted ItemID from metadata, instead of skipping them. This keeps reasoning and web_search items correctly paired during replay.

store=false behavior is unchanged — reasoning items are still skipped since ephemeral IDs can't be referenced.

Changes

  • providers/openai/responses_language_model.go: Updated reasoning replay case to emit item_reference when store=true
  • providers/openai/openai_test.go: Updated existing reasoning replay test + added combined reasoning + web_search test

Testing

  • TestResponsesToPrompt_ReasoningWithStore — updated, passing
  • TestResponsesToPrompt_ReasoningWithWebSearchCombined — new, passing
  • Full ./providers/openai/ suite — passing

kylecarbs and others added 6 commits March 18, 2026 16:41
Remove kronk provider and examples (every published version requires
go 1.26). Downgrade kaptinlin deps to Go 1.25-compatible versions.
coder/coder and coder/aibridge use the SasSwart perf fork of
openai-go/v3 (deferred body serialization, appendCompact skip).
This fork had a bug where WithJSONSet modifications (used by
NewStreaming to inject "stream": true) were clobbered by the
deferred body serialization. kylecarbs/openai-go includes the
fix from kylecarbs/openai-go#2.

Also adjusts two .OfString accesses since the fork's
ResponseOutputItemUnion.Arguments is a plain string rather
than the upstream union type.
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).
Cherry-picked from #4.

- Reasoning items: Always skip during replay (store=true has them
  persisted; store=false IDs are ephemeral).
- Provider-executed tool calls: Gate item_reference behind the store
  flag; skip when store=false.
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.

3 participants