Repository navigation
fix(sse): anuncia role assistant no 1º delta do stream Responses→Chat - #3911
Conversation
…elta The Responses→Chat translator never emitted role=assistant on the first delta. OpenAI Chat Completions streams open with delta.role=assistant; the Responses API has no role-announcement event, so it must be synthesized on the first emitted chunk. Strict streaming clients (e.g. @langchain/openai's _convertDeltaToMessageChunk, used by n8n's AI Agent) key off the first chunk's role to build an AIMessageChunk. Without it, streamed tool_call deltas are dropped and the agent returns an empty response despite a well-formed upstream function_call. Adds a wrapper that stamps role=assistant on the first non-null emitted chunk, covering every emission path (text + tool_call deltas). TDD: tests/unit/responses-chat-assistant-role-first-chunk.test.ts (red->green). Existing converter suites stay green (32/32).
There was a problem hiding this comment.
Code Review
This pull request introduces a mechanism to synthesize the assistant role on the first emitted delta when translating OpenAI Responses API chunks to OpenAI Chat Completions format. This ensures compatibility with strict streaming clients like LangChain that require a role announcement on the first chunk. A corresponding unit test suite has been added to verify this behavior for both tool calls and text deltas. There are no review comments, and I have no feedback to provide.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
…ses-chat-assistant-role-first-chunk
…e wrapper PR cheaper-inference#3911 own growth: openai-responses.ts 878->903 (+25). Updates the frozen file-size baseline so Fast Quality Gates pass. Co-authored-by: diegosouzapw <diegosouza.pw@gmail.com>
|
Thanks, @diego-anselmo! 🙏 Spot-on fix — the Responses API has no role-announcement event, so translating Responses→Chat without synthesizing |
a5e704f
into
cheaper-inference:release/v3.8.26
…cheaper-inference#3911) Integrated into release/v3.8.26
Summary
Tool calls em streaming de modelos
codex(OpenAI Responses API,targetFormat: openai-responses)são silenciosamente descartados por clients OpenAI estritos. O tradutor de stream Responses→Chat
nunca emite
role: "assistant"no primeiro delta, então o_convertDeltaToMessageChunkdo@langchain/openai(usado pelo AI Agent do n8n) não tipa a mensagem comoAIMessageChunke nuncaacumula os deltas de
tool_call. O agente executa a tool, mas retorna resposta final vazia(
{"output": ""}).Um stream Chat Completions normal abre com
delta.role = "assistant"; a Responses API não temevento de anúncio de role, então o tradutor precisa sintetizá-lo. Este PR carimba
role: "assistant"no primeiro chunk não-nulo emitido (tanto no caminho de texto quanto no detool_call), seguindo o contrato de streaming do Chat Completions. Non-streaming e providers em
formato chat já não eram afetados; só a saída de streaming
openai-responsesmuda.Reprodução
Antes: primeiro chunk
delta:{ "tool_calls":[...] }(sem role) → o langchain descarta a tool call.Depois: primeiro chunk
delta:{ "role":"assistant", "tool_calls":[...] }.Related Issues
Validation
npm run lint— limpo nos arquivos alteradosclaude-code-rendering-fixes,responses-translation-fixes): 34/34 verdes (suite completa + coverage via CI)npm run test:coverage— via CITests Added Or Updated
tests/unit/responses-chat-assistant-role-first-chunk.test.ts(novo) — verificarole=assistantno primeiro delta de tool_call e no primeiro delta de texto, e que ele não se repete nos deltas
seguintes. Escrito em TDD (red→green).
Coverage Notes
open-sse/translator/response/openai-responses.ts; o teste novo exercita o wrapperwithAssistantRoleOnFirstDeltanos dois caminhos de emissão.Reviewer Notes
sem mudar a lógica de tradução por evento.
codex/gpt-5.5streaming com tools: o primeiro chunktool_callsagoratraz
role:"assistant"e o AI Agent do n8n completa o loop tool→resposta.