{"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":528,"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":510,"sourceCodeEnd":546,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/afa823b6b4e4f183511e0bc0a3be93caa94c7c97/kernel/util/openai_completion.go#L510-L546","documentation":"The terminal item.Arguments must equal the arguments accumulated from deltas or extend them (strings.HasPrefix check) — streamed deltas are treated as a prefix of the final JSON. If the terminal arguments diverge (neither equal nor an extension), the arguments the consumer already rendered are stale and possibly invalid JSON, so the adapter errors.","triggerScenarios":"Providers that rewrite, reformat, or re-serialize argument JSON between streaming and the terminal response; content filters mutating arguments; gateways recomputing output items instead of echoing the streamed ones.","commonSituations":"Gateways that normalize JSON formatting (key ordering, whitespace) during assembly; moderation layers editing arguments post-hoc.","solutions":["Retry the request once — divergences are often transient.","Reproduce against the official OpenAI endpoint; if clean there, upgrade or replace the gateway.","Disable streaming for tool calls on the affected provider.","Report with a captured SSE trace of the streamed versus terminal arguments."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"Discard the streamed argument accumulation and re-issue the request; never JSON-parse the partial arguments; switch to non-streaming for that provider if it persists.","preventionTips":["Use providers that stream argument deltas verbatim","Avoid gateways that normalize JSON during assembly","Capture SSE traces when certifying tool-calling providers"],"tags":["streaming","tool-calls","openai","responses-api","arguments-mismatch"],"backgroundTag":"stream-state-mismatch","analyzedSha":"afa823b6b4e4f183511e0bc0a3be93caa94c7c97","analyzedAt":"2026-08-18T17:04:10.865Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}