{"record":{"id":"d042fdd162143cd4","repo":"siyuan-note/siyuan","slug":"streamed-function-call-is-missing-from-the-termina","errorCode":null,"errorMessage":"streamed function call is missing from the terminal response","messagePattern":"streamed function call is missing from the terminal response","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/util/openai_completion.go","lineNumber":563,"sourceCode":"func (stream *OpenAICompletionStream) queueResponseTerminal(response openai.CreateResponseResponse) error {\n\tif err := responseResultError(response); err != nil {\n\t\treturn err\n\t}\n\tterminalToolCalls := map[int]struct{}{}\n\tfor index, raw := range response.Output {\n\t\titem, ok := responseOutputItem(raw)\n\t\tif !ok || item.Type != \"function_call\" {\n\t\t\tcontinue\n\t\t}\n\t\tif item.Status == \"incomplete\" || item.Status == \"in_progress\" ||\n\t\t\t(response.Status == openai.ResponseStatusIncomplete && item.Status != \"completed\") {\n\t\t\treturn errors.New(\"response ended with an incomplete function call\")\n\t\t}\n\t\tterminalToolCalls[index] = struct{}{}\n\t}\n\tfor index := range stream.responseToolCalls {\n\t\tif _, ok := terminalToolCalls[index]; !ok {\n\t\t\treturn errors.New(\"streamed function call is missing from the terminal response\")\n\t\t}\n\t}\n\toutput, err := MarshalOpenAIResponseOutput(response.Output)\n\tif err != nil {\n\t\treturn err\n\t}\n\tstream.responseOutput = output\n\n\tfor index, raw := range response.Output {\n\t\titem, ok := responseOutputItem(raw)\n\t\tif !ok || item.Type != \"function_call\" {\n\t\t\tcontinue\n\t\t}\n\t\tcurrent := stream.responseToolCalls[index]\n\t\tif current.ID != \"\" && item.CallID != \"\" && current.ID != item.CallID {\n\t\t\treturn errors.New(\"streamed function call ID does not match the terminal response\")\n\t\t}\n\t\tif current.Function.Name != \"\" && item.Name != \"\" && current.Function.Name != item.Name {","sourceCodeStart":545,"sourceCodeEnd":581,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/util/openai_completion.go#L545-L581","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err != nil {\n    if strings.Contains(err.Error(), \"missing from the terminal response\") {\n        return errProviderProtocol // log and re-issue the request\n    }\n    return err\n}","preventionTips":["Avoid intermediaries that rewrite SSE output items","Test multi-tool-call prompts against your gateway before production","Pin known-good provider API versions"],"tags":["openai","tool-calls","streaming","consistency-check"],"backgroundTag":"unexpected-api-response-shape","analyzedSha":"9f775e8a12daef8255556097396f9b2739078892","analyzedAt":"2026-09-19T03:17:15.984Z","contentChangedAt":"2026-09-19T03:17:15.984Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}