[JS] compat-oai: Responses transport drops built-in tool-call items - breaks stateless multi-turn and discards image generation output
Part of #6002. Applies to the Responses transport landing in #6006 / #6148.
The Responses transport converts only reasoning, message, and function_call output items into Genkit parts. Built-in tool-call items (web_search_call, code_interpreter_call, image_generation_call, mcp_call, mcp_approval_request, ...) fall through the conversion loop with no part emitted, which causes two related failures:
1. Stateless multi-turn replay breaks with built-in tools (major).
The transport pins store: false and replays the full history each turn. OpenAI's conversation-state rules for stateless reasoning-model requests require every item in the response's output array to be preserved on replay, and the API enforces reasoning/tool-item pairing in both directions (the Item 'rs_...' of type 'reasoning' was provided without its required following item 400 family). Since built-in tool items are never converted to parts, they can never be replayed: a reasoning model with config: { tools: [{ type: 'web_search' }] } (an explicitly supported passthrough) emits [reasoning, web_search_call, message], and every turn after the first replays [reasoning(id, encrypted), assistant-text] with the web_search_call missing -> 400.
2. image_generation_call output is silently discarded (major).
The conversion loop's assumption that "the caller-visible result arrives in the message item alongside them" does not hold for image generation: the generated image lives in the item's own result field and there is no message item carrying it. The model generates the image, the call is billed, and the plugin returns a message with no media part and no error. mcp_approval_request items are likewise dropped, dead-ending MCP approval flows.
Fix direction:
- Round-trip built-in tool-call items through part metadata the same way reasoning items already ride
metadata.itemId/metadata.encryptedContent, re-emitting them verbatim from history conversion - or reject built-in tools in config until replay is supported, so the failure is loud instead of a confusing 400 on turn two. - Map
image_generation_call.resultto amediapart, and handle the remaining skipped item types deliberately per type.
Found by adversarial review of the combined #6006 + #6148 diff; single-turn built-in tool use (citations via metadata.annotations) works and is covered by tests - the gap is multi-turn replay and item types whose results are not mirrored into a message item.
Triage: P2 · M · stop: needs design decision
Area: js
Root cause: The OpenAI Responses transport referenced by this issue (#6006 and #6148) has not landed on main yet (js/plugins/compat-oai/src/model.ts currently only implements the Chat Completions API), and handling built-in tool-call output items requires a contract decision on Genkit Part and metadata representation.
Options:
- Round-trip built-in tool items via
Partandmetadata(recommended once #6006/#6148 land): Mapimage_generation_callto amediapart (data:image/...;base64,...) with item metadata for replay, representmcp_approval_requestas a structuredcustomortoolRequestpart, and persist intermediate built-in tool items (web_search_call,code_interpreter_call,mcp_call) inPart.metadataso stateless history conversion re-emits them in order. - Reject unsupported built-in tools in config: Throw
INVALID_ARGUMENTwhenconfig.toolsincludes built-in tools that cannot be replayed statelessly or mapped to Genkit parts.
Details
- Checked
js/plugins/compat-oai/src/model.ts,js/plugins/compat-oai/src/index.ts, andjs/plugins/compat-oai/src/openai/index.tsat commit9a7d0b6: onlyclient.chat.completions.createandclient.beta.chat.completions.streamexist onmain. - No Responses API transport (
client.responses),metadata.itemId, ormetadata.encryptedContenthandling is present injs/plugins/compat-oaiyet. - Once the Responses transport lands on
main, Option 1 preserves stateless multi-turn compatibility with reasoning models (store: false) and surfacesimage_generation_call.resultmedia output without breaking single-turn built-in tool usage.
Run a8de04ca-188d-4e19-8c82-afe57246de28 · Cloud Run logs