[PR #643] [MERGED] Fix silent empty responses from OpenAI models #4710

Closed
opened 2026-10-22 04:10:00 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/643
Author: @kolacheee
Created: 5/10/2026
Status: ✅ Merged
Merged: 5/10/2026
Merged by: @SpicyMarinara

Base: main ← Head: claude/objective-rhodes-ab4062


📝 Commits (3)

  • 5eb05d0 Fix silent empty responses from OpenAI models (refusals, failures, incomplete)
  • 019fe5a Merge branch 'main' into claude/objective-rhodes-ab4062
  • 08c7c7f Address OpenAI refusal handling review

📊 Changes

1 file changed (+87 additions, -6 deletions)

View changed files

📝 packages/server/src/services/llm/providers/openai.provider.ts (+87 -6)

📄 Description

Linked Issue

Closes #644

Why this change

A user reported GPT-5.5 consistently returning empty responses. Investigation revealed multiple code paths where model responses could silently become empty — particularly when models refuse requests or when the Responses API returns non-standard completion states. While the specific GPT-5.5 case was routed through the Responses API (which already handled response.refusal.delta), the Chat Completions paths had no refusal handling at all, and neither API path handled failure/incomplete states.

What changed

  • Fixes refusal-only responses producing empty output. When OpenAI models refuse a request via the Chat Completions API, the refusal text is sent in delta.refusal (not delta.content). The stream parser only checked delta.content, so refusal-only responses silently became 0-char empty responses shown to users as "The AI returned an empty response."
  • Adds response.failed and response.incomplete event handling to Responses API streams. Previously these events were silently swallowed — if the API returned a failed or incomplete response, the user got an empty response with no diagnostic information in server logs.
  • Extracts refusal content from non-streaming Responses API responses. The extractResponsesText() method now checks refusal content parts and the top-level refusal field as fallbacks when no regular text output is found.

Affected code paths (all in openai.provider.ts)

Path Issue Fix
chat() streaming (Chat Completions) delta.refusal ignored Yield delta.refusal as text
chatComplete() streaming (Chat Completions) delta.refusal ignored Accumulate delta.refusal into content
chatComplete() non-streaming (Chat Completions) message.refusal ignored Fall back to message.refusal when content is null
extractResponsesText() (Responses API) Refusal content parts and top-level refusal ignored Extract both as fallbacks
chatResponses() streaming (Responses API) response.failed/response.incomplete silently swallowed; no fallback text extraction from response.completed Log warnings; extract text from completed response when nothing was streamed
chatCompleteResponses() streaming (Responses API) Missing response.refusal.delta handler; no response.failed/response.incomplete handling; no fallback extraction Add all three

Validation

  • Manually verify with an OpenAI model (e.g., GPT-4o) that triggers a refusal — the refusal text should now appear as the response instead of "empty response"
  • Manually verify with GPT-5.5 that normal responses still stream correctly
  • Manually verify that non-OpenAI providers (Anthropic, Google) are unaffected
  • Check server logs for [OpenAI Responses] warning messages when a response fails or is incomplete

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed
  • Version/release files updated (only if this PR includes a version bump)

Summary by CodeRabbit

Bug Fixes

  • Improved handling of model refusals, now properly displayed as text to users.
  • Enhanced fallback text extraction when API responses contain incomplete or missing output data.
  • Strengthened error handling and logging for failed or incomplete streaming response scenarios.

Review Change Stack

Summary by CodeRabbit

Release Notes

  • Bug Fixes
    • Improved handling of AI model refusals to display them as user-visible text.
    • Enhanced fallback text extraction when API responses don't include expected output.
    • Better error state handling for streaming API responses.

Review Change Stack


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Pasta-Devs/Marinara-Engine/pull/643 **Author:** [@kolacheee](https://github.com/kolacheee) **Created:** 5/10/2026 **Status:** ✅ Merged **Merged:** 5/10/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `main` ← **Head:** `claude/objective-rhodes-ab4062` --- ### 📝 Commits (3) - [`5eb05d0`](https://github.com/Pasta-Devs/Marinara-Engine/commit/5eb05d0c07155e10fba97f517743b6ad2657a318) Fix silent empty responses from OpenAI models (refusals, failures, incomplete) - [`019fe5a`](https://github.com/Pasta-Devs/Marinara-Engine/commit/019fe5a37f2af44b99377a13e1d07c902e8dd1b9) Merge branch 'main' into claude/objective-rhodes-ab4062 - [`08c7c7f`](https://github.com/Pasta-Devs/Marinara-Engine/commit/08c7c7fe30d14d27671711a0a18fcb7476a333b9) Address OpenAI refusal handling review ### 📊 Changes **1 file changed** (+87 additions, -6 deletions) <details> <summary>View changed files</summary> 📝 `packages/server/src/services/llm/providers/openai.provider.ts` (+87 -6) </details> ### 📄 Description ## Linked Issue Closes #644 ## Why this change A user reported GPT-5.5 consistently returning empty responses. Investigation revealed multiple code paths where model responses could silently become empty — particularly when models refuse requests or when the Responses API returns non-standard completion states. While the specific GPT-5.5 case was routed through the Responses API (which already handled `response.refusal.delta`), the Chat Completions paths had no refusal handling at all, and neither API path handled failure/incomplete states. ## What changed - **Fixes refusal-only responses producing empty output.** When OpenAI models refuse a request via the Chat Completions API, the refusal text is sent in `delta.refusal` (not `delta.content`). The stream parser only checked `delta.content`, so refusal-only responses silently became 0-char empty responses shown to users as "The AI returned an empty response." - **Adds `response.failed` and `response.incomplete` event handling to Responses API streams.** Previously these events were silently swallowed — if the API returned a failed or incomplete response, the user got an empty response with no diagnostic information in server logs. - **Extracts refusal content from non-streaming Responses API responses.** The `extractResponsesText()` method now checks refusal content parts and the top-level `refusal` field as fallbacks when no regular text output is found. ### Affected code paths (all in `openai.provider.ts`) | Path | Issue | Fix | |------|-------|-----| | `chat()` streaming (Chat Completions) | `delta.refusal` ignored | Yield `delta.refusal` as text | | `chatComplete()` streaming (Chat Completions) | `delta.refusal` ignored | Accumulate `delta.refusal` into content | | `chatComplete()` non-streaming (Chat Completions) | `message.refusal` ignored | Fall back to `message.refusal` when `content` is null | | `extractResponsesText()` (Responses API) | Refusal content parts and top-level `refusal` ignored | Extract both as fallbacks | | `chatResponses()` streaming (Responses API) | `response.failed`/`response.incomplete` silently swallowed; no fallback text extraction from `response.completed` | Log warnings; extract text from completed response when nothing was streamed | | `chatCompleteResponses()` streaming (Responses API) | Missing `response.refusal.delta` handler; no `response.failed`/`response.incomplete` handling; no fallback extraction | Add all three | ## Validation - [x] Manually verify with an OpenAI model (e.g., GPT-4o) that triggers a refusal — the refusal text should now appear as the response instead of "empty response" - [x] Manually verify with GPT-5.5 that normal responses still stream correctly - [x] Manually verify that non-OpenAI providers (Anthropic, Google) are unaffected - [x] Check server logs for `[OpenAI Responses]` warning messages when a response fails or is incomplete ## Docs and release impact - [x] No docs changes needed - [ ] Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed - [ ] Version/release files updated (only if this PR includes a version bump) ## Summary by CodeRabbit ## Bug Fixes * Improved handling of model refusals, now properly displayed as text to users. * Enhanced fallback text extraction when API responses contain incomplete or missing output data. * Strengthened error handling and logging for failed or incomplete streaming response scenarios. [![Review Change Stack](https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg)](https://app.coderabbit.ai/change-stack/Pasta-Devs/Marinara-Engine/pull/643) <!-- end of auto-generated comment: release notes by coderabbit.ai --> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Release Notes * **Bug Fixes** * Improved handling of AI model refusals to display them as user-visible text. * Enhanced fallback text extraction when API responses don't include expected output. * Better error state handling for streaming API responses. [![Review Change Stack](https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg)](https://app.coderabbit.ai/change-stack/Pasta-Devs/Marinara-Engine/pull/643) <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-22 04:10:00 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#4710
No description provided.