siyuan-note/siyuan · error
streamed function call is missing from the terminal response
Error message
streamed function call is missing from the terminal response
What it means
During terminal reconciliation, every function call that was streamed incrementally (tracked in stream.responseToolCalls by output index) must appear in the final response.Output at that index. This error fires when an index known to the streamer has no corresponding function_call item in the terminal output, meaning the provider dropped or reordered a tool call.
Solutions
- Update the OpenAI SDK / provider so streamed output indices match the final output array
- Test against the official OpenAI endpoint to isolate gateway-specific index behavior
- Retry the request; if reproducible, report to the OpenAI-compatible provider
- Treat as fatal for this turn and re-issue the request instead of executing partial tool calls
Defensive patterns
Strategy: try-catch
Try / catch
if err != nil {
if strings.Contains(err.Error(), "missing from the terminal response") {
return errProviderProtocol // log and re-issue the request
}
return err
} Prevention
- Avoid intermediaries that rewrite SSE output items
- Test multi-tool-call prompts against your gateway before production
- Pin known-good provider API versions
When it happens
Trigger: A response.output_item.added / response.function_call_arguments.delta was received for output index N, but the terminal response.Output at index N either is absent, is not a function_call, or items shifted so map indices no longer align.
Common situations: Provider gateways that renumber output items; streaming proxies dropping output items; SDK/protocol drift between streamed item indexing and final output array; multi-tool-call responses where the model abandoned one call.
Understand the failure class
Background: "invalid response format", "malformed payload", "missing data field": when an API returns 200 but the response shape is wrong — this error's family across 23 libraries.
Related errors
- response ended with an incomplete function call
- streamed function arguments do not match the terminal…
- streamed function call ID does not match the terminal…
- streamed function name does not match the terminal response
- streamed response text does not match the terminal response
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/d042fdd162143cd4.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/util/openai_completion.go:563
func (stream *OpenAICompletionStream) queueResponseTerminal(response openai.CreateResponseResponse) error {
if err := responseResultError(response); err != nil {
return err
}
terminalToolCalls := map[int]struct{}{}
for index, raw := range response.Output {
item, ok := responseOutputItem(raw)
if !ok || item.Type != "function_call" {
continue
}
if item.Status == "incomplete" || item.Status == "in_progress" ||
(response.Status == openai.ResponseStatusIncomplete && item.Status != "completed") {
return errors.New("response ended with an incomplete function call")
}
terminalToolCalls[index] = struct{}{}
}
for index := range stream.responseToolCalls {
if _, ok := terminalToolCalls[index]; !ok {
return errors.New("streamed function call is missing from the terminal response")
}
}
output, err := MarshalOpenAIResponseOutput(response.Output)
if err != nil {
return err
}
stream.responseOutput = output
for index, raw := range response.Output {
item, ok := responseOutputItem(raw)
if !ok || item.Type != "function_call" {
continue
}
current := stream.responseToolCalls[index]
if current.ID != "" && item.CallID != "" && current.ID != item.CallID {
return errors.New("streamed function call ID does not match the terminal response")
}
if current.Function.Name != "" && item.Name != "" && current.Function.Name != item.Name {View on GitHub (pinned to 9f775e8a12)