siyuan-note/siyuan · error
streamed function name does not match the terminal response
Error message
streamed function name does not match the terminal response
What it means
The adapter compares the function name accumulated from stream deltas (current.Function.Name) with the terminal item.Name whenever both are non-empty. A mismatch means the streamed deltas and the final response disagree about which function to call, so dispatching on either value alone is unsafe and the stream fails.
Source
Thrown at kernel/util/openai_completion.go:524
}
}
output, err := MarshalOpenAIResponseOutput(response.Output)
if err != nil {
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) {View on GitHub (pinned to afa823b6b4)
Solutions
- Retry the request once — transient inconsistencies often clear.
- Reproduce against the official OpenAI endpoint; if clean there, upgrade or replace the gateway.
- Disable streaming for tool calls on the affected provider.
- Capture an SSE trace and report the name divergence.
Defensive patterns
Strategy: retry
Try / catch
Drop the partial stream state and re-issue the request; if the same function name keeps diverging, route that provider's tool calls through non-streaming requests.
Prevention
- Verify gateway tool-schema handling before enabling streaming tools
- Keep gateway and SDK versions aligned
- Alert on repeated stream-versus-terminal mismatches
When it happens
Trigger: Gateways that rename or alias functions between streaming and finalization; parallel calls with server-side index swaps pairing the wrong name with accumulated state; event middleware rewriting function names.
Common situations: OpenAI-compatible gateways with tool-name normalization; mid-stream failover to a backend with a different tool schema.
Related errors
- streamed function call is missing from the terminal response
- streamed function call ID does not match the terminal respon
- streamed function arguments do not match the terminal respon
- 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/fa1bf43a2858f411.
Report an issue: GitHub.