Skip to content

fix(providers): fail a stream whose body contains no provider events - #322

Merged
nathanschmid08 merged 1 commit into
Open-Glassbeetle:mainfrom
nova-loop:fix/stream-no-events
Nov 13, 2026
Merged

nathanschmid08 merged 1 commit into
Open-Glassbeetle:mainfrom
nova-loop:fix/stream-no-events

Conversation

@nova-loop

Copy link
Copy Markdown
Contributor

What changed

A streaming completion whose body contains no parseable provider events now fails with ProviderUnavailableError (PROVIDER_UNAVAILABLE). It no longer ends as an empty complete turn. This follows the issue's suggested fix, applied to all four adapters:

  • openai / anthropic / google: each stream loop has a sawAnyEvent flag. The SSE parser (parseSseData / parseSseEvent / parseSseChunk) gets one extra onParsed callback, which it calls right after a payload parses as JSON. The missing-sentinel fallback still yields complete when at least one event was parsed. When none was, it throws ProviderUnavailableError('<Provider> returned no stream events').
  • ollama: the NDJSON loop sets the same flag after each line that parses, and also after the trailing-buffer line. It uses the same guard on the fallback.

On the two decisions the issue raised:

Why

Closes #315

When a proxy or maintenance page answered 200 text/html, you got a 502 on the non-streaming path but a silent empty assistant turn on the streaming path. That empty turn was then replayed as context.

How it was tested

  • New tests in each adapter spec:
    • an HTML maintenance-page body rejects with ProviderUnavailableError / PROVIDER_UNAVAILABLE and a "no stream events" message
    • a zero-byte body rejects the same way
    • a stream whose only event carries no text still ends with complete
  • I ran the new tests against the old adapters first. The 8 rejection tests failed, and they all pass with this change.
  • npx vitest run in apps/api: 119 files, 1909 tests pass. The e2e config (vitest.config.e2e.ts): 25 files, 822 tests pass.
  • npm run lint -w @glassbeetle/api (oxlint): clean. tsc -p tsconfig.build.json --noEmit: clean.
  • Prettier: openai.adapter.spec.ts passes prettier --check. The other six touched files already fail it on main (The format check has never run in CI, and 92 committed files no longer pass it #246). I didn't reformat them, to keep the diff focused.

Anything left out, or worth a second opinion

  • I did not add the Content-Type: text/event-stream check the issue mentions as an extra guard. As the issue says, it can't be the only guard, and some OpenAI-compatible servers label streams loosely. The parsed-event flag covers both the HTML case and the empty-body case, so I kept this PR to that. I'm happy to add the header check as a follow-up if you'd like it.
  • The non-streaming message quality ("Provider request failed.") is unchanged, since the issue calls that out of scope.

Checklist

  • npm run lint -w @glassbeetle/api passes (API changes)
  • npm test passes (API unit + e2e suites; see above)
  • npm run build passes (only the API tsc build was run)
  • Tests cover the change: failing-first tests for each adapter
  • Docs updated if behaviour or a convention changed (no docs describe this fallback)
  • The linked issue's acceptance criteria are met, or the gaps are named above

AI assistance

This change was prepared with AI assistance. An AI coding assistant wrote the code and tests from the issue. I reviewed the diff and ran the checks listed above before opening the PR.

@nathanschmid08

Copy link
Copy Markdown
Contributor

Hi @nova-loop , Thanks for the PR. I appreciate it very much.
I just finished my review and it looks really good, therefore I will merge it now.
Thanks again and enjoy the friday!

@nathanschmid08
nathanschmid08 merged commit aa1df79 into Open-Glassbeetle:main Nov 13, 2026
3 of 4 checks passed
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.

A streaming completion whose provider returns an unparseable body is reported as a successful, empty reply

2 participants