{"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/9f775e8a12daef8255556097396f9b2739078892/kernel/util/openai_completion.go#L665-L701","documentation":"responseResultError accepts only empty, completed, or incomplete statuses (incomplete is handled elsewhere); any other status string — e.g. failed, cancelled, queued — is reported with this formatted error. It surfaces provider-side result statuses the caller must handle as a failed generation.","triggerScenarios":"A Responses API result (from CreateOpenAICompletion or a terminal stream event) carries response.Status outside {\"\", \"completed\", \"incomplete\"} — typically \"failed\" or \"cancelled\".","commonSituations":"Provider rejecting the request mid-generation (invalid tool schema, unsupported parameter) yielding status failed; request cancelled client-side or by timeout; gateway returning non-standard status strings; org policy blocking the request.","solutions":["Read response.Error (or IncompleteDetails) for the provider's failure reason and fix the request accordingly","Retry on transient statuses; check the provider status page on persistent failures","Validate tool definitions/parameters against the API version to avoid status failed","Upgrade the SDK/gateway if it emits non-standard status values","Match on the formatted message or use errors from openai.APIError for structured handling"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err != nil {\n    if strings.Contains(err.Error(), \"response returned status \") {\n        status := extractStatus(err.Error()) // e.g. failed/cancelled\n        log.Printf(\"responses api status: %s\", status)\n        return retryWithBackoff(ctx, req)\n    }\n    return err\n}","preventionTips":["Validate tool schemas and parameters against the current API version","Check response.Error for provider failure details","Retry with backoff on transient provider failures","Pin a stable provider API version"],"tags":["openai","response-status","failed-generation","api"],"backgroundTag":"unexpected-api-response-shape","analyzedSha":"9f775e8a12daef8255556097396f9b2739078892","analyzedAt":"2026-09-19T03:17:15.984Z","contentChangedAt":"2026-09-19T03:17:15.984Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}