{"record":{"id":"d2b6d7c3f9cbd641","repo":"siyuan-note/siyuan","slug":"response-returned-status-s","errorCode":null,"errorMessage":"response returned status %s","messagePattern":"response returned status (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/util/openai_completion.go","lineNumber":683,"sourceCode":"\t\t\t\trefusal.WriteString(content.Refusal)\n\t\t\t}\n\t\t}\n\t}\n\treturn refusal.String()\n}\n\nfunc responseResultError(response openai.CreateResponseResponse) error {\n\tif response.Error != nil && response.Error.Message != \"\" {\n\t\treturn &openai.APIError{Code: response.Error.Code, Message: response.Error.Message}\n\t}\n\tif response.Status == openai.ResponseStatusIncomplete && hasResponseFunctionCall(response.Output) {\n\t\treturn errors.New(\"response ended with an incomplete function call\")\n\t}\n\tswitch response.Status {\n\tcase \"\", openai.ResponseStatusCompleted, openai.ResponseStatusIncomplete:\n\t\treturn nil\n\tdefault:\n\t\treturn fmt.Errorf(\"response returned status %s\", response.Status)\n\t}\n}\n\nfunc hasResponseFunctionCall(output []any) bool {\n\tfor _, raw := range output {\n\t\titem, ok := responseOutputItem(raw)\n\t\tif ok && item.Type == \"function_call\" {\n\t\t\treturn true\n\t\t}\n\t}\n\treturn false\n}\n\nfunc responseEventError(event openai.ResponseStreamEvent, fallback string) error {\n\tif event.Error != nil && event.Error.Message != \"\" {\n\t\treturn &openai.APIError{Code: event.Error.Code, Message: event.Error.Message}\n\t}\n\tif event.Response != nil && event.Response.Error != nil && event.Response.Error.Message != \"\" {","sourceCodeStart":665,"sourceCodeEnd":701,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/8641553a1f07374001902d3ce773285db1292b2d/kernel/util/openai_completion.go#L665-L701","documentation":"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.","triggerScenarios":"CreateOpenAICompletion or the streaming terminal path receives a CreateResponseResponse whose Status field is a non-standard/unexpected value not in {'', completed, incomplete}.","commonSituations":"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.","solutions":["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).","Upgrade the OpenAI SDK/kernel so known-good statuses match the provider's current enum.","Retry the request if the status indicates a transient provider state.","Check for a proxy/gateway injecting nonstandard status strings and remove or fix it."],"exampleFix":"// before\n// pinned old SDK treats new provider status 'failed' as unknown\nrequire github.com/siyuan-note/siyuan // old openai dep\n// after\n// upgrade deps so status enums match the provider\ngo get github.com/sashabaranov/go-openai@latest && go mod tidy","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err != nil && strings.HasPrefix(err.Error(), \"response returned status \") {\n    status := strings.TrimPrefix(err.Error(), \"response returned status \")\n    // branch on the unrecognized status, e.g. retry for 'failed'\n}","preventionTips":["Keep the OpenAI SDK updated for new status enums","Inspect the error message to learn the unknown status value","Avoid proxies that inject nonstandard statuses","Handle provider failure statuses with retries/alerting in the agent loop"],"tags":["openai","response-status","api-compatibility"],"backgroundTag":"unexpected-response-shape","analyzedSha":"8641553a1f07374001902d3ce773285db1292b2d","analyzedAt":"2026-09-11T16:08:28.414Z","contentChangedAt":"2026-09-11T16:08:28.414Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}