siyuan-note/siyuan · error
streamed function arguments do not match the terminal respon
Error message
streamed function arguments do not match the terminal response
What it means
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.
Source
Thrown at kernel/util/openai_completion.go:528
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 {
return errors.New("streamed function name does not match the terminal response")
}
if current.Function.Arguments != item.Arguments &&
!strings.HasPrefix(item.Arguments, current.Function.Arguments) {
return errors.New("streamed function arguments do not match the terminal response")
}
delta := openai.ToolCall{Type: openai.ToolTypeFunction}
deltaIndex := index
delta.Index = &deltaIndex
changed := false
if current.ID == "" && item.CallID != "" {
delta.ID = item.CallID
changed = true
}
if current.Function.Name == "" && item.Name != "" {
delta.Function.Name = item.Name
changed = true
}
if current.Function.Arguments != item.Arguments && strings.HasPrefix(item.Arguments, current.Function.Arguments) {
delta.Function.Arguments = strings.TrimPrefix(item.Arguments, current.Function.Arguments)
changed = delta.Function.Arguments != "" || changed
}
if changed {View on GitHub (pinned to afa823b6b4)
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.
Defensive patterns
Strategy: retry
Try / catch
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.
Prevention
- Use providers that stream argument deltas verbatim
- Avoid gateways that normalize JSON during assembly
- Capture SSE traces when certifying tool-calling providers
When it happens
Trigger: 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.
Common situations: Gateways that normalize JSON formatting (key ordering, whitespace) during assembly; moderation layers editing arguments post-hoc.
Related errors
- streamed function call is missing from the terminal response
- streamed function call ID does not match the terminal respon
- streamed function name does not match the terminal response
- response stream ended before a terminal event
- response stream terminal event is missing response
AI-assisted analysis of siyuan-note/siyuan@afa823b6b4 (2026-08-18).
Data as JSON: /api/errors/29c782c593d06211.
Report an issue: GitHub.