[PR #1048] [MERGED] Fix GPT provider response shape handling #4900

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

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/1048
Author: @cha1latte
Created: 5/20/2026
Status: ✅ Merged
Merged: 5/20/2026
Merged by: @cha1latte

Base: staging ← Head: fix/issue-1042-gpt-empty-response-v2


📝 Commits (1)

  • d52ba7d Fix GPT provider response shape handling

📊 Changes

1 file changed (+176 additions, -108 deletions)

View changed files

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

📄 Description

Linked issue

Closes #1042

Why this change

  • GPT 5.5 / 5.4 provider responses could surface as an empty generated message when text arrived in an alternate Responses shape, or as Cannot read properties of undefined (reading '0') when an OpenAI-compatible provider returned an HTTP-200 error payload without choices.

What changed

  • Added guarded Chat Completions choices parsing so malformed/error payloads report a clear provider error instead of throwing a raw TypeError.
  • Accepted additional Responses text shapes used by some GPT 5.x-compatible providers, including content parts with type: "text" and streamed response.text.delta events.
  • Treated non-streaming Responses status: "failed" as an actionable provider error while preserving existing output_text, refusal, usage, and normal Chat Completions behavior.

Validation

  • pnpm check passes locally
  • Container (Docker / Podman) built and ran without issue
  • Ran the app, clicked through the changes manually
  • Checked edge cases (light + dark mode, mobile viewport, empty states, error paths)
  • Above manual verification completed (describe below)
  • Read and followed CONTRIBUTING.md

Manual verification notes

  • Codex reproduced the pre-fix behavior with packages\server\node_modules\.bin\tsx.cmd scratch\issue-1042-openai-provider-repro.ts --expect-broken: Responses type: "text" returned null, response.text.delta streamed an empty string, and the no-choices provider payload threw Cannot read properties of undefined (reading '0').
  • Codex reran packages\server\node_modules\.bin\tsx.cmd scratch\issue-1042-openai-provider-repro.ts; it passed with text extracted from alternate Responses parts, streamed response.text.delta, a clear missing-choices provider error, normal output_text extraction, failed Responses status handling, and normal custom Chat Completions.
  • Codex ran pnpm check; impeccable context, lint, shared/server/client builds all passed.
  • No manual browser verification was needed because this is server provider response parsing only.

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)

UI evidence (if applicable)

N/A - no UI changes.


🔄 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/1048 **Author:** [@cha1latte](https://github.com/cha1latte) **Created:** 5/20/2026 **Status:** ✅ Merged **Merged:** 5/20/2026 **Merged by:** [@cha1latte](https://github.com/cha1latte) **Base:** `staging` ← **Head:** `fix/issue-1042-gpt-empty-response-v2` --- ### 📝 Commits (1) - [`d52ba7d`](https://github.com/Pasta-Devs/Marinara-Engine/commit/d52ba7d7000100ead1732355e4e812de362893ab) Fix GPT provider response shape handling ### 📊 Changes **1 file changed** (+176 additions, -108 deletions) <details> <summary>View changed files</summary> 📝 `packages/server/src/services/llm/providers/openai.provider.ts` (+176 -108) </details> ### 📄 Description <!-- Target branch: `staging`. The default base in this UI is `main` (release branch). --> <!-- Change the base to `staging` before submitting unless this is a maintainer-approved mainline change. --> <!-- See CONTRIBUTING.md § Branches. --> ## Linked issue <!-- Every PR should reference a feature request or issue report. If there isn't one yet, open one first to gather opinions: --> <!-- https://github.com/Pasta-Devs/Marinara-Engine/issues/new/choose --> Closes #1042 ## Why this change <!-- What user problem, bug, or goal does this solve? --> - GPT 5.5 / 5.4 provider responses could surface as an empty generated message when text arrived in an alternate Responses shape, or as `Cannot read properties of undefined (reading '0')` when an OpenAI-compatible provider returned an HTTP-200 error payload without `choices`. ## What changed <!-- List the key changes in this PR --> - Added guarded Chat Completions `choices` parsing so malformed/error payloads report a clear provider error instead of throwing a raw TypeError. - Accepted additional Responses text shapes used by some GPT 5.x-compatible providers, including `content` parts with `type: "text"` and streamed `response.text.delta` events. - Treated non-streaming Responses `status: "failed"` as an actionable provider error while preserving existing `output_text`, refusal, usage, and normal Chat Completions behavior. ## Validation <!-- Required: include commands run and/or manual checks performed --> - [ ] `pnpm check` passes locally - [ ] Container (Docker / Podman) built and ran without issue - [ ] Ran the app, clicked through the changes manually - [ ] Checked edge cases (light + dark mode, mobile viewport, empty states, error paths) - [ ] Above manual verification completed (describe below) - [ ] Read and followed `CONTRIBUTING.md` ### Manual verification notes <!-- Describe exactly what you tested in a real browser/app, step by step. --> <!-- ⚠️ If an AI agent filled out or ticked these boxes for you, treat them --> <!-- as a TO-DO LIST, not as proof the work is done. Verify each item yourself --> <!-- before submitting. If you haven't verified it, untick the box. --> - Codex reproduced the pre-fix behavior with `packages\server\node_modules\.bin\tsx.cmd scratch\issue-1042-openai-provider-repro.ts --expect-broken`: Responses `type: "text"` returned `null`, `response.text.delta` streamed an empty string, and the no-`choices` provider payload threw `Cannot read properties of undefined (reading '0')`. - Codex reran `packages\server\node_modules\.bin\tsx.cmd scratch\issue-1042-openai-provider-repro.ts`; it passed with text extracted from alternate Responses parts, streamed `response.text.delta`, a clear missing-choices provider error, normal `output_text` extraction, failed Responses status handling, and normal custom Chat Completions. - Codex ran `pnpm check`; impeccable context, lint, shared/server/client builds all passed. - No manual browser verification was needed because this is server provider response parsing only. ## 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) ## UI evidence (if applicable) N/A - no UI changes. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-22 04:11:34 +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#4900
No description provided.