{"record":{"id":"29c782c593d06211","repo":"siyuan-note/siyuan","slug":"streamed-function-arguments-do-not-match-the-termi","errorCode":null,"errorMessage":"streamed function arguments do not match the terminal response","messagePattern":"streamed function arguments do not match the terminal response","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/util/openai_completion.go","lineNumber":586,"sourceCode":"\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\n\t\t\tchanged = true\n\t\t}\n\t\tif current.Function.Arguments != item.Arguments && strings.HasPrefix(item.Arguments, current.Function.Arguments) {\n\t\t\tdelta.Function.Arguments = strings.TrimPrefix(item.Arguments, current.Function.Arguments)\n\t\t\tchanged = delta.Function.Arguments != \"\" || changed\n\t\t}\n\t\tif changed {","sourceCodeStart":568,"sourceCodeEnd":604,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/util/openai_completion.go#L568-L604","documentation":"The arguments accumulated from streamed deltas must equal the terminal item's arguments, or the terminal arguments must extend (have as prefix) the streamed ones — missing tails are then emitted as an extra chunk. This error fires when the terminal arguments diverge from what was streamed (neither equal nor a prefix match), so the assembled JSON cannot be trusted.","triggerScenarios":"At terminal reconciliation: item.Arguments != current.Function.Arguments AND item.Arguments does not start with current.Function.Arguments — i.e. the provider's final arguments differ from/contradict the streamed delta concatenation.","commonSituations":"Buggy SSE gateways resending or altering delta content; protocol changes where deltas were dropped (e.g. by a proxy filtering events); vendors streaming sanitized arguments but returning raw ones terminally; non-OpenAI backends behind a Chat-Completions-to-Responses shim.","solutions":["Capture the raw SSE stream and compare deltas vs the final arguments to find where they diverge","Update the provider/SDK/gateway so streamed deltas exactly compose the final arguments","Disable intermediary transformation (proxies, logging middleware) that may drop or rewrite delta events","Retry the request; treat the turn as failed rather than executing arguments of unknown integrity"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err != nil {\n    if strings.Contains(err.Error(), \"arguments do not match\") {\n        return errProviderProtocol // log raw SSE, retry without executing tools\n    }\n    return err\n}","preventionTips":["Do not run middleware that drops or transforms SSE delta events","Validate accumulated arguments as JSON before executing tools","Compare raw deltas vs final arguments when evaluating new gateways"],"tags":["openai","tool-calls","arguments-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"}