[GH-ISSUE #3039] [Issue]: ChatGPT subscription streaming silently returns truncated/filtered output as a clean completion #1610

Closed
opened 2026-10-21 05:40:38 +07:00 by bsakaguchi · 2 comments
Owner

Originally created by @kolacheee on GitHub (Jun 29, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/3039

Originally assigned to: @SpicyMarinara on GitHub.

What's wrong

The ChatGPT-subscription provider always routes through the Responses API and always streams, so the interactive streaming generator is the main code path for those chats. In that generator, the response.incomplete SSE event — emitted when generation stops at max_output_tokens or a content filter — is handled by a bare logger.warn and break, with no signal to the caller. The partial text already yielded is presented as a normal, complete reply with no truncation or content-filter indicator. A ChatGPT Pro user who hits a length cap or a content filter gets a silently cut-off answer indistinguishable from a finished one, and auto-continue logic that keys off finishReason cannot detect it. The non-streaming Responses helpers already map status === 'incomplete' to finishReason: 'length'; the streaming path does not.

How to reproduce (try it yourself)

  1. Configure an openai_chatgpt connection (Codex/ChatGPT login).
  2. Send a chat request whose generation will exceed max_output_tokens (or trip a content filter), so the Responses stream ends with response.incomplete.

You'll see: the generator yields the partial text and returns normally; only a server-side warn is logged. The client receives the truncated text with no truncation indicator, and the message is persisted with generationInfo.finishReason = null (generate.routes.ts:7007).

Expected: the truncation surfaces as finishReason: "length", recorded and detectable like the non-streaming Responses path.

Where it is

packages/server/src/services/llm/providers/openai.provider.ts: the streaming chatResponses() response.incomplete handler (lines 1870-1875, only logs + break); generator signature with no finish-reason channel (line 1683); forced stream for ChatGPT-subscription (lines 1599-1606). Contrast: non-streaming parseResponsesResult/chatCompleteResponses map incomplete→length (lines 2263, 2114, 2138). Consumer: generate.routes.ts:6543-6595 (streaming send captures only usage) and :7007 (persisted).

What's happening

The streaming generator has no out-of-band channel for finishReason, and the response.incomplete case only logs. Because the ChatGPT-subscription provider forces streaming for every request, the truncation/content-filter signal is dropped on the primary interactive path for that provider. (Note: chatComplete() callers delegate to the non-streaming helper, which handles incomplete correctly — so this is specific to the streaming chat()/chatResponses() generator, which is the main interactive send.)

Suggested fix

Surface the signal through the existing LLMUsage.finishReason channel and teach the route to read it. Two edits:

  1. openai.provider.ts, replace the response.incomplete handler (1870-1875) so it extracts usage, emits encrypted reasoning, runs the no-text fallback (mirroring response.completed at 1845-1861), and marks the finish reason:
case "response.incomplete": {
  const resp = parsed.response as Record<string, unknown> | undefined;
  const reason = (resp?.incomplete_details as Record<string, unknown>)?.reason ?? "unknown";
  logger.warn("[OpenAI Responses] Stream ended with response.incomplete (reason=%s)", reason);
  if (resp) {
    streamUsage = this.extractResponsesUsage(resp);
    this.emitEncryptedReasoning(resp, options);
    if (!yieldedAny) {
      const fallback = this.extractResponsesText(resp);
      if (fallback) { yieldedAny = true; yield fallback; }
    }
  }
  streamUsage = { ...(streamUsage ?? { promptTokens: 0, completionTokens: 0, totalTokens: 0 }), finishReason: "length" };
  break;
}
  1. generate.routes.ts:6595, propagate the reason out of the returned usage in the streaming branch: after usage = result.value;, add if (result.value.finishReason) finishReason = result.value.finishReason;.

Regressions avoided: do NOT append a sentinel to the yielded token stream — that stream is the assistant message body (accumulated into fullResponse, persisted/displayed), so a sentinel would corrupt visible content. Do NOT emit a distinct content_filter finish reason — the codebase's truncation detectors only recognize "length" (game.routes.ts:1639, workspace-agent.service.ts:581), and the non-streaming Responses siblings already collapse both incomplete reasons to "length"; the filter reason is still logged via the existing warn. The route edit is required because, without it, the streaming branch never assigns the outer finishReason from usage.finishReason (contrast the tool branches at 6400/6538), so the signal would still never reach generationInfo.finishReason. The happy response.completed path is unchanged (still returns usage with no finish reason → persisted null, as today).

Related: one of a family of provider-level "finish/stop reason dropped → truncation reported as a clean stop" issues filed together (Gemini non-streaming, Anthropic non-streaming, OpenAI streaming, ChatGPT-subscription streaming). Same root-cause class, separate per-provider fix.


AI-investigated against v2.0.6; cited lines read and confirmed. Please verify before fixing.

Originally created by @kolacheee on GitHub (Jun 29, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/3039 Originally assigned to: @SpicyMarinara on GitHub. **What's wrong** The ChatGPT-subscription provider always routes through the Responses API and always streams, so the interactive streaming generator is the main code path for those chats. In that generator, the `response.incomplete` SSE event — emitted when generation stops at `max_output_tokens` or a content filter — is handled by a bare `logger.warn` and `break`, with no signal to the caller. The partial text already yielded is presented as a normal, complete reply with no truncation or content-filter indicator. A ChatGPT Pro user who hits a length cap or a content filter gets a silently cut-off answer indistinguishable from a finished one, and auto-continue logic that keys off `finishReason` cannot detect it. The non-streaming Responses helpers already map `status === 'incomplete'` to `finishReason: 'length'`; the streaming path does not. **How to reproduce (try it yourself)** 1. Configure an `openai_chatgpt` connection (Codex/ChatGPT login). 2. Send a chat request whose generation will exceed `max_output_tokens` (or trip a content filter), so the Responses stream ends with `response.incomplete`. You'll see: the generator yields the partial text and returns normally; only a server-side warn is logged. The client receives the truncated text with no truncation indicator, and the message is persisted with `generationInfo.finishReason = null` (`generate.routes.ts:7007`). Expected: the truncation surfaces as `finishReason: "length"`, recorded and detectable like the non-streaming Responses path. **Where it is** `packages/server/src/services/llm/providers/openai.provider.ts`: the streaming `chatResponses()` `response.incomplete` handler (lines 1870-1875, only logs + `break`); generator signature with no finish-reason channel (line 1683); forced stream for ChatGPT-subscription (lines 1599-1606). Contrast: non-streaming `parseResponsesResult`/`chatCompleteResponses` map incomplete→length (lines 2263, 2114, 2138). Consumer: `generate.routes.ts:6543-6595` (streaming send captures only usage) and `:7007` (persisted). **What's happening** The streaming generator has no out-of-band channel for `finishReason`, and the `response.incomplete` case only logs. Because the ChatGPT-subscription provider forces streaming for every request, the truncation/content-filter signal is dropped on the primary interactive path for that provider. (Note: `chatComplete()` callers delegate to the non-streaming helper, which handles incomplete correctly — so this is specific to the streaming `chat()`/`chatResponses()` generator, which is the main interactive send.) **Suggested fix** Surface the signal through the existing `LLMUsage.finishReason` channel and teach the route to read it. Two edits: 1. **`openai.provider.ts`**, replace the `response.incomplete` handler (1870-1875) so it extracts usage, emits encrypted reasoning, runs the no-text fallback (mirroring `response.completed` at 1845-1861), and marks the finish reason: ```ts case "response.incomplete": { const resp = parsed.response as Record<string, unknown> | undefined; const reason = (resp?.incomplete_details as Record<string, unknown>)?.reason ?? "unknown"; logger.warn("[OpenAI Responses] Stream ended with response.incomplete (reason=%s)", reason); if (resp) { streamUsage = this.extractResponsesUsage(resp); this.emitEncryptedReasoning(resp, options); if (!yieldedAny) { const fallback = this.extractResponsesText(resp); if (fallback) { yieldedAny = true; yield fallback; } } } streamUsage = { ...(streamUsage ?? { promptTokens: 0, completionTokens: 0, totalTokens: 0 }), finishReason: "length" }; break; } ``` 2. **`generate.routes.ts:6595`**, propagate the reason out of the returned usage in the streaming branch: after `usage = result.value;`, add `if (result.value.finishReason) finishReason = result.value.finishReason;`. **Regressions avoided:** do NOT append a sentinel to the yielded token stream — that stream is the assistant message body (accumulated into `fullResponse`, persisted/displayed), so a sentinel would corrupt visible content. Do NOT emit a distinct `content_filter` finish reason — the codebase's truncation detectors only recognize `"length"` (`game.routes.ts:1639`, `workspace-agent.service.ts:581`), and the non-streaming Responses siblings already collapse both incomplete reasons to `"length"`; the filter reason is still logged via the existing warn. The route edit is required because, without it, the streaming branch never assigns the outer `finishReason` from `usage.finishReason` (contrast the tool branches at 6400/6538), so the signal would still never reach `generationInfo.finishReason`. The happy `response.completed` path is unchanged (still returns usage with no finish reason → persisted null, as today). *Related: one of a family of provider-level "finish/stop reason dropped → truncation reported as a clean stop" issues filed together (Gemini non-streaming, Anthropic non-streaming, OpenAI streaming, ChatGPT-subscription streaming). Same root-cause class, separate per-provider fix.* --- *AI-investigated against v2.0.6; cited lines read and confirmed. Please verify before fixing.*
Author
Owner

@SpicyMarinara commented on GitHub (Jun 29, 2026):

Claiming this for the current staging sweep in draft PR #3053 (branch codex/issue-sweep-3033-3052).

<!-- gh-comment-id:4834987800 --> @SpicyMarinara commented on GitHub (Jun 29, 2026): Claiming this for the current staging sweep in draft PR #3053 (branch `codex/issue-sweep-3033-3052`).
Author
Owner

@SpicyMarinara commented on GitHub (Jun 29, 2026):

Fixed in PR #3053 on branch codex/issue-sweep-3033-3052 (commit bfb1bc76). Closing this issue as addressed; the PR remains open for staging review/merge.

<!-- gh-comment-id:4835087637 --> @SpicyMarinara commented on GitHub (Jun 29, 2026): Fixed in PR #3053 on branch `codex/issue-sweep-3033-3052` (commit bfb1bc76). Closing this issue as addressed; the PR remains open for staging review/merge.
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#1610
No description provided.