siyuan-note/siyuan · error

streamed function call ID does not match the terminal…

Error message

streamed function call ID does not match the terminal response

What it means

At terminal reconciliation the library compares each streamed function call's ID (call_id) with the matching item in the final response.Output. A mismatch means the streamed call_id and the authoritative terminal call_id differ, so tool results would be attributed to the wrong call — the library fails fast instead.

Solutions

  1. Verify you are not mixing responses (disable response caching/multiplexing intermediaries)
  2. Upgrade the provider/SDK so streamed and terminal call IDs match
  3. Retry the request; if it only happens on one gateway, file a bug with that provider
  4. Pin a known-good API version for the provider
Defensive patterns

Strategy: try-catch

Try / catch

if err != nil {
    if strings.Contains(err.Error(), "call ID does not match") {
        return errProviderProtocol // discard partial tool state, retry
    }
    return err
}

Prevention

When it happens

Trigger: stream.responseToolCalls[index].ID is non-empty, the terminal item.CallID is non-empty, and the two strings differ for the same output index.

Common situations: OpenAI-compatible gateways generating new call IDs between stream and final payload; provider bug or API version change in call_id format; caching intermediaries mixing responses from different requests.

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/470edccce291ec4d. Report an issue: GitHub.

Appendix: source

Thrown at kernel/util/openai_completion.go:579

	for index := range stream.responseToolCalls {
		if _, ok := terminalToolCalls[index]; !ok {
			return errors.New("streamed function call is missing from the terminal response")
		}
	}
	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

View on GitHub (pinned to 9f775e8a12)