Skip to content

fix(openai): skip truncated Codex OAuth SSE events instead of failing stream#14474

Open
wzharies wants to merge 1 commit intovercel:mainfrom
wzharies:fix/skip-truncated-codex-sse-events
Open

fix(openai): skip truncated Codex OAuth SSE events instead of failing stream#14474
wzharies wants to merge 1 commit intovercel:mainfrom
wzharies:fix/skip-truncated-codex-sse-events

Conversation

@wzharies
Copy link
Copy Markdown

Fixes #14473

The ChatGPT Codex OAuth endpoint returns response.created / response.in_progress / response.completed SSE events with a ~30KB instructions field that often arrives truncated. safeParseJSON returns { success: false } and doStream() treats it as fatal.

This fix detects truncated response.* status events via JSONParseError.isInstance() and skips them. These events are informational and not needed for text streaming. Mirrors the official Codex CLI (Rust) strategy.

Changes

  • packages/openai/src/responses/openai-responses-language-model.ts — 10 lines added in doStream() transform
  • 1 regression test added (254/254 tests pass)

How to verify

Run the test: cd packages/openai && pnpm vitest run -t "truncated"

Or use ChatGPT OAuth with gpt-5.4 — the stream should complete instead of failing with AI_JSONParseError.

@tigent tigent Bot added ai/provider related to a provider package. Must be assigned together with at least one `provider/*` label bug Something isn't working as documented provider/openai Issues related to the @ai-sdk/openai provider labels Apr 15, 2026
@wzharies wzharies force-pushed the fix/skip-truncated-codex-sse-events branch from 7348fd0 to f24760a Compare April 15, 2026 05:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai/provider related to a provider package. Must be assigned together with at least one `provider/*` label bug Something isn't working as documented provider/openai Issues related to the @ai-sdk/openai provider

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(openai): ChatGPT Codex OAuth SSE stream fails on truncated response.* events

2 participants