siyuan-note/siyuan · error

streamed function arguments do not match the terminal…

Error message

streamed function arguments do not match the terminal response

What it means

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.

Solutions

  1. Capture the raw SSE stream and compare deltas vs the final arguments to find where they diverge
  2. Update the provider/SDK/gateway so streamed deltas exactly compose the final arguments
  3. Disable intermediary transformation (proxies, logging middleware) that may drop or rewrite delta events
  4. Retry the request; treat the turn as failed rather than executing arguments of unknown integrity
Defensive patterns

Strategy: try-catch

Try / catch

if err != nil {
    if strings.Contains(err.Error(), "arguments do not match") {
        return errProviderProtocol // log raw SSE, retry without executing tools
    }
    return err
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "invalid response format", "malformed payload", "missing data field": when an API returns 200 but the response shape is wrong — this error's family across 23 libraries.

Related errors


AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19). Data as JSON: /api/errors/29c782c593d06211. Report an issue: GitHub.

Appendix: source

Thrown at kernel/util/openai_completion.go:586

		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 9f775e8a12)