siyuan-note/siyuan · error

response returned status %s

Error message

response returned status %s

What it means

responseResultError is the final status gate for a Responses-API result: statuses "", 'completed', and 'incomplete' (without a function call) are accepted, and any other status string is rejected with this formatted error. It surfaces unrecognized or failed provider statuses (e.g. 'failed', 'cancelled', 'queued' leaking into a result payload) as an explicit error rather than silently returning the payload.

Source

Thrown at kernel/util/openai_completion.go:683

				refusal.WriteString(content.Refusal)
			}
		}
	}
	return refusal.String()
}

func responseResultError(response openai.CreateResponseResponse) error {
	if response.Error != nil && response.Error.Message != "" {
		return &openai.APIError{Code: response.Error.Code, Message: response.Error.Message}
	}
	if response.Status == openai.ResponseStatusIncomplete && hasResponseFunctionCall(response.Output) {
		return errors.New("response ended with an incomplete function call")
	}
	switch response.Status {
	case "", openai.ResponseStatusCompleted, openai.ResponseStatusIncomplete:
		return nil
	default:
		return fmt.Errorf("response returned status %s", response.Status)
	}
}

func hasResponseFunctionCall(output []any) bool {
	for _, raw := range output {
		item, ok := responseOutputItem(raw)
		if ok && item.Type == "function_call" {
			return true
		}
	}
	return false
}

func responseEventError(event openai.ResponseStreamEvent, fallback string) error {
	if event.Error != nil && event.Error.Message != "" {
		return &openai.APIError{Code: event.Error.Code, Message: event.Error.Message}
	}
	if event.Response != nil && event.Response.Error != nil && event.Response.Error.Message != "" {

View on GitHub (pinned to 8641553a1f)

Solutions

  1. Read the status value embedded in the error message to identify what the provider returned and address it specifically (e.g. 'failed' → inspect provider logs).
  2. Upgrade the OpenAI SDK/kernel so known-good statuses match the provider's current enum.
  3. Retry the request if the status indicates a transient provider state.
  4. Check for a proxy/gateway injecting nonstandard status strings and remove or fix it.

Example fix

// before
// pinned old SDK treats new provider status 'failed' as unknown
require github.com/siyuan-note/siyuan // old openai dep
// after
// upgrade deps so status enums match the provider
go get github.com/sashabaranov/go-openai@latest && go mod tidy
Defensive patterns

Strategy: try-catch

Try / catch

if err != nil && strings.HasPrefix(err.Error(), "response returned status ") {
    status := strings.TrimPrefix(err.Error(), "response returned status ")
    // branch on the unrecognized status, e.g. retry for 'failed'
}

Prevention

When it happens

Trigger: CreateOpenAICompletion or the streaming terminal path receives a CreateResponseResponse whose Status field is a non-standard/unexpected value not in {'', completed, incomplete}.

Common situations: Provider added a new status value the pinned SDK doesn't know; a proxy synthesizes nonstandard statuses; an OpenAI-compatible backend returning 'failed'/'cancelled' statuses in the response body instead of an HTTP error.

Related errors


AI-assisted analysis of siyuan-note/siyuan@8641553a1f (2026-09-11). Data as JSON: /api/errors/d2b6d7c3f9cbd641. Report an issue: GitHub.