Skip to content

fix(providers): surface errors sent mid-stream by OpenAI-compatible and Codex APIs - #1702

Open
pcbeingused33 wants to merge 1 commit into
nextlevelbuilder:devfrom
pcbeingused33:fix/openai-stream-midstream-error
Open

pcbeingused33 wants to merge 1 commit into
nextlevelbuilder:devfrom
pcbeingused33:fix/openai-stream-midstream-error

Conversation

@pcbeingused33

Copy link
Copy Markdown
Contributor

Summary

Once a stream has started the HTTP status is already 200, so upstream failures arrive as an error payload inside the SSE stream. The OpenAI-compatible and Codex providers ignored it and returned the partial (or empty) reply as a success; they now return an error, as the Anthropic provider already does.

Root cause:

  • openAIStreamChunk had no error field, so {"error":{...}} chunks (object or string) were parsed as empty chunks.
  • Codex processSSEEvent handled response.failed but not the error event.

"error": null and empty values are ignored, so gateways that always send the field are unaffected.

Type

  • Bug fix

Target Branch

dev

Checklist

  • go build ./... passes
  • go build -tags sqliteonly ./... passes
  • go vet passes (./internal/providers/...)
  • Tests pass: go test -race ./internal/providers/... (providers packages only)
  • No hardcoded secrets or credentials

Test Plan

New tests in openai_stream_error_test.go stream a partial reply followed by an error from a local SSE server. The OpenAI (three payload shapes) and Codex (flat and nested) cases fail without the change and pass with it; a "error": null chunk still succeeds.

🤖 Generated with Claude Code

@clark-cant clark-cant left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary: Fixes a real correctness gap: once an OpenAI-compatible or Codex stream has started (HTTP 200), upstream failures arrive as an in-band error payload, which both providers previously ignored, returning the partial or empty reply as success. Adds a shared streamErrorMessage helper, an Error field on openAIStreamChunk, an error case in the Codex SSE handler, and tests.

Risk level: Low

Mandatory gates

  • Duplicate / prior implementation: clear. No prior streamErrorMessage helper on dev; PR #1701 (same author) targets a different concern (no Ollama replay after emit); the Anthropic provider already returns an error on in-band error events (anthropic_stream.go), which this PR mirrors.
  • Project standards: docs found (AGENTS.md / CLAUDE.md / CONTRIBUTING.md); the change is idiomatic Go and follows existing provider patterns.
  • Strategic necessity: clear value. Silent success on an upstream error is a correctness bug; the fix is small, well-scoped, and covered by tests.

Findings

  • Critical: none.
  • Important: none.
  • Suggestion: in the Codex error case, the final fallback msg = string(event.Code) yields the raw JSON token (for example "server_error" with quotes) when both error and message are empty. Cosmetic only.

Verdict: Approve. No critical or important issues; CI green (go / release-versioning / web) and mergeState CLEAN. Merge left to a maintainer approval.

Posted by /ck:review-pr at 2026-11-26T16:09:19Z

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants