Skip to content

fix(llm): upgrade openai-go so SSE comment heartbeats don't abort streams - #821

Closed
Fanzzzd wants to merge 1 commit into
alibaba:mainfrom
Fanzzzd:fix/openai-sse-heartbeat
Closed

Fanzzzd wants to merge 1 commit into
alibaba:mainfrom
Fanzzzd:fix/openai-sse-heartbeat

Conversation

@Fanzzzd

@Fanzzzd Fanzzzd commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Description

Upgrades github.com/openai/openai-go/v3 from v3.41.0 to v3.50.0 (current latest) to pick up an upstream streaming fix. No code changes — the v3 API is backward compatible across this range.

The problem this fixes: v3.41.0's SSE decoder dispatches comment-only SSE blocks as events with empty data. Many proxies and OpenAI-compatible gateways emit comment lines (e.g. : keep-alive) as heartbeats during long generations. When one arrives:

  1. ssestream.Decoder.Next() dispatches an event whose Data is empty (v3.41.0 ssestream.go has no empty-data guard),
  2. Stream.Next() passes that empty payload to json.Unmarshal, which fails with unexpected end of JSON input,
  3. the error is sticky (s.err), so the whole streaming response aborts mid-stream.

Upstream fixed this in v3.43.0: ssestream: skip SSE blocks without data (openai/openai-go#621) — blocks that carried no data lines are now skipped instead of dispatched.

Behavioral change: none. Request and response wire formats are unchanged; the only observable difference is that streaming no longer errors out when a gateway sends comment heartbeats. The go.mod diff beyond openai-go itself (gjson, golang.org/x/*) is exactly what go mod tidy requires for the new SDK version.

Split out of #806 so this uncontroversial dependency fix can be reviewed and merged independently of the replay design discussion there.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)

How Has This Been Tested?

  • make test passes locally (all packages, zero code changes needed against the new SDK)
  • make check passes locally (license headers, go mod tidy, gofmt, go vet)
  • Verified the upstream fix by diffing packages/ssestream/ssestream.go between v3.41.0 and v3.50.0: the only behavioral change is the added if data.Len() == 0 { continue } guard at the event dispatch point.

Checklist

  • My code follows the project's coding style (go fmt, go vet)
  • I have performed a self-review of my code
  • I have added tests that prove my fix is effective or my feature works (n/a — dependency upgrade; the fix is covered by upstream's own tests)
  • New and existing unit tests pass locally with my changes
  • I have updated the documentation accordingly (if applicable) (n/a)
  • I have signed the CLA

Related Issues

Related to #806 (split out of it; that PR will be rebased onto this once merged).

…eams

openai-go v3.41.0 dispatches comment-only SSE blocks (e.g. ": keep-alive"
lines sent by proxies and OpenAI-compatible gateways) as events with empty
data. Stream.Next() then feeds the empty payload to json.Unmarshal, fails
with "unexpected end of JSON input", and aborts the response mid-stream.

Upstream fixed this in v3.43.0 ("ssestream: skip SSE blocks without
data", openai/openai-go#621, commit 114224d) by skipping blocks that
carried no data lines. Upgrade to the current v3.50.0 to pick it up.

No code changes required: the v3 API is backward compatible across this
range, and make test / make check pass unchanged.
@github-actions

Copy link
Copy Markdown
Contributor

✅ OpenCodeReview: Review skipped: no items were selected.

@wu21-web

Copy link
Copy Markdown
Contributor

This is covered by the dependabot weekly deps update: Pull Request 880

@Fanzzzd

Fanzzzd commented Aug 14, 2026

Copy link
Copy Markdown
Contributor Author

Happy either way — the reason this PR exists is the specific failure it fixes (SSE comment heartbeats aborting streams), not the bump itself. If #880 is the preferred vehicle I'll close this one; just worth a line there noting the openai-go bump fixes that bug, so the behavior change stays traceable.

@Fanzzzd

Fanzzzd commented Aug 19, 2026

Copy link
Copy Markdown
Contributor Author

Closing as promised: #880 merged with openai-go v3.51.0, which covers the floor this PR targeted. For traceability — the load-bearing part of that batch for streaming is the openai-go bump; it's what stops SSE comment heartbeats from aborting streams, as described here. Thanks @stay-foolish-forever for the earlier review and @wu21-web for flagging the overlap.

@Fanzzzd Fanzzzd closed this Aug 19, 2026
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.

3 participants