siyuan-note/siyuan · error

response stream terminal event is missing response

Error message

response stream terminal event is missing response

What it means

On response.completed / response.incomplete the adapter requires event.Response to carry the full final Response object so it can reconcile deltas, tool calls, usage, and emit the closing chunk. A terminal event without a payload leaves the final state unknowable, so the adapter fails the stream rather than guess.

Source

Thrown at kernel/util/openai_completion.go:469

			call := stream.responseToolCalls[index]
			call.Index = &index
			call.Type = openai.ToolTypeFunction
			call.Function.Arguments += event.Delta
			stream.responseToolCalls[index] = call
			response.Choices = []openai.ChatCompletionStreamChoice{{
				Index: 0,
				Delta: openai.ChatCompletionStreamChoiceDelta{ToolCalls: []openai.ToolCall{{
					Index: &index,
					Type:  openai.ToolTypeFunction,
					Function: openai.FunctionCall{
						Arguments: event.Delta,
					},
				}}},
			}}
			return response, nil
		case openai.ResponseStreamEventCompleted, openai.ResponseStreamEventIncomplete:
			if event.Response == nil {
				return openai.ChatCompletionStreamResponse{}, errors.New("response stream terminal event is missing response")
			}
			if err = stream.queueResponseTerminal(*event.Response); err != nil {
				return openai.ChatCompletionStreamResponse{}, err
			}
			stream.responsesDone = true
			response = stream.pending[0]
			stream.pending = stream.pending[1:]
			return response, nil
		case openai.ResponseStreamEventFailed:
			return openai.ChatCompletionStreamResponse{}, responseEventError(event, "response failed")
		case openai.ResponseStreamEventError:
			return openai.ChatCompletionStreamResponse{}, responseEventError(event, "response stream failed")
		}
		return response, nil
	}
}

func (stream *OpenAICompletionStream) queueResponseTerminal(response openai.CreateResponseResponse) error {

View on GitHub (pinned to afa823b6b4)

Solutions

  1. Reproduce with the official OpenAI endpoint; if it only fails on your gateway, the gateway drops the terminal payload — upgrade or fix it.
  2. Capture the raw SSE frames (temporary logging) to confirm response.completed lacks the response object.
  3. Switch that provider to the Chat Completions protocol ("openai") instead of "openai-responses".
  4. Retry once — some providers send a well-formed terminal event on a second attempt.

Example fix

// before
{"apiBase": "https://my-gateway/v1", "protocol": "openai-responses"}

// after: compliant endpoint for the responses protocol, or chat completions on the gateway
{"apiBase": "https://api.openai.com/v1", "protocol": "openai-responses"}
{"apiBase": "https://my-gateway/v1", "protocol": "openai"}
Defensive patterns

Strategy: fallback

Validate before calling

// smoke-test a provider before enabling the responses protocol for it
probe, err := client.CreateResponseStream(ctx, openai.CreateResponseRequest{Model: model, Input: "ping"})
if err == nil {
	for {
		ev, evErr := probe.Recv()
		if evErr != nil {
			break
		}
		if ev.Type == openai.ResponseStreamEventCompleted && ev.Response == nil {
			return errors.New("provider terminal events lack the response payload")
		}
	}
	probe.Close()
}

Try / catch

On this error, mark the provider config as responses-incompatible and route subsequent calls through the Chat Completions protocol or non-streaming CreateResponse; do not retry-loop a deterministic protocol gap.

Prevention

When it happens

Trigger: An OpenAI-compatible provider or proxy emits response.completed with the response field omitted or null; SDK deserialization that drops the field; event rewriters or transforms between gateway and client stripping the payload.

Common situations: Switching the AI provider to self-hosted gateways (older vLLM/LiteLLM/one-api builds) with partial Responses-API support; version skew between the gateway and the go-openai SDK.

Related errors


AI-assisted analysis of siyuan-note/siyuan@afa823b6b4 (2026-08-18). Data as JSON: /api/errors/93ecf1d99a20c7bf. Report an issue: GitHub.