{"record":{"id":"470edccce291ec4d","repo":"siyuan-note/siyuan","slug":"streamed-function-call-id-does-not-match-the-termi","errorCode":null,"errorMessage":"streamed function call ID does not match the terminal response","messagePattern":"streamed function call ID does not match the terminal response","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/util/openai_completion.go","lineNumber":579,"sourceCode":"\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 {\n\t\t\treturn errors.New(\"streamed function name does not match the terminal response\")\n\t\t}\n\t\tif current.Function.Arguments != item.Arguments &&\n\t\t\t!strings.HasPrefix(item.Arguments, current.Function.Arguments) {\n\t\t\treturn errors.New(\"streamed function arguments do not match the terminal response\")\n\t\t}\n\t\tdelta := openai.ToolCall{Type: openai.ToolTypeFunction}\n\t\tdeltaIndex := index\n\t\tdelta.Index = &deltaIndex\n\t\tchanged := false\n\t\tif current.ID == \"\" && item.CallID != \"\" {\n\t\t\tdelta.ID = item.CallID\n\t\t\tchanged = true\n\t\t}\n\t\tif current.Function.Name == \"\" && item.Name != \"\" {\n\t\t\tdelta.Function.Name = item.Name","sourceCodeStart":561,"sourceCodeEnd":597,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/util/openai_completion.go#L561-L597","documentation":"At terminal reconciliation the library compares each streamed function call's ID (call_id) with the matching item in the final response.Output. A mismatch means the streamed call_id and the authoritative terminal call_id differ, so tool results would be attributed to the wrong call — the library fails fast instead.","triggerScenarios":"stream.responseToolCalls[index].ID is non-empty, the terminal item.CallID is non-empty, and the two strings differ for the same output index.","commonSituations":"OpenAI-compatible gateways generating new call IDs between stream and final payload; provider bug or API version change in call_id format; caching intermediaries mixing responses from different requests.","solutions":["Verify you are not mixing responses (disable response caching/multiplexing intermediaries)","Upgrade the provider/SDK so streamed and terminal call IDs match","Retry the request; if it only happens on one gateway, file a bug with that provider","Pin a known-good API version for the provider"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err != nil {\n    if strings.Contains(err.Error(), \"call ID does not match\") {\n        return errProviderProtocol // discard partial tool state, retry\n    }\n    return err\n}","preventionTips":["Disable response caching/rewriting intermediaries","Use the official endpoint or a compliant gateway","Log call_id from stream start and terminal event for debugging"],"tags":["openai","tool-calls","id-mismatch","streaming"],"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"}