Skip to content

About

Break your LLM streaming client on purpose, offline: 27 fixed SSE streams and a local fake server for OpenAI-style clients

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

streamfault

CI

Break your LLM streaming client on purpose, offline. No model, no API key, no paid requests.

A streamed response can stop halfway and still look like success. Measured with the official OpenAI Python SDK, versions 2.54.0 and 3.49.0, against the fixtures in this repo:

  • A stream that ends cleanly after {"city": "Par returns that half-written tool call. Nothing is raised.
  • A stream that starts with a UTF-8 BOM loses its first chunk. "Hello, world!" comes back as ", world!". Nothing is raised.

If an agent runs tool calls from a stream like that, it runs garbage. streamfault gives you 27 fixed streams, 14 of them broken in ways real streams break, so you can find out what your client does before production does.

Try it in a minute

Needs a Rust toolchain, or Docker.

$ git clone https://github.com/MohibShaikh/streamfault && cd streamfault
$ cargo run -q -- replay chat-eof-mid-text
scenario:  chat-eof-mid-text (chat_completions, via fragments)
http end:  clean-eof (body ends normally)
verdict:   incomplete
reason:    no finish_reason and no [DONE]: the input ended cleanly
text:      "Hello, world"
evidence:  events=2 terminal_marker=none finish=none transport_truncated=false unterminated_last_line=false
expected:  incomplete -> match
client:    Report an incomplete stream instead of returning "Hello, world" as a finished answer.

HTTP reports a normal end, and the answer was still cut off. That is the case most clients miss.

Install the binary with cargo install --git https://github.com/MohibShaikh/streamfault. Without Rust, use Docker:

$ docker build -t streamfault .
$ docker run --rm -p 127.0.0.1:8787:8787 streamfault            # the fake server, reachable from this machine only
$ docker run --rm streamfault replay chat-eof-mid-text          # any other command

Point any SDK at it

Start the fake server and put the scenario name in the base URL. It works with any language whose SDK lets you set a base URL.

$ streamfault serve
streamfault listening on http://127.0.0.1:8787
SDK base URL: http://127.0.0.1:8787/s/<scenario>/v1   (e.g. http://127.0.0.1:8787/s/chat-text/v1)
from openai import OpenAI
client = OpenAI(base_url="http://127.0.0.1:8787/s/chat-eof-in-tool-args/v1", api_key="not-a-real-key")
import OpenAI from "openai";
const client = new OpenAI({ baseURL: "http://127.0.0.1:8787/s/chat-eof-in-tool-args/v1", apiKey: "not-a-real-key" });

The server binds 127.0.0.1 by default and refuses a non-loopback --addr unless you also pass --allow-non-loopback. It never makes outbound connections, ignores the key, model and prompt, and answers CORS preflight so browser clients work. Behind an HTTP proxy, set NO_PROXY=127.0.0.1. Only the Python snippet above was run here; the TypeScript one shows the same setting and was not run.

What is in the box

Kind Count Examples
Plain controls 4 text and one tool call, for both APIs
Valid but awkward 7 a UTF-8 character cut between reads, a leading BOM, CRLF and bare CR line endings
Parallel tool calls 3 two calls with interleaved argument chunks, one variant with the second call cut short
Cut off 6 connection dropped inside tool-call arguments, clean end with no terminal event
Errors and limits 7 an error event mid-stream, response.failed, finish_reason=length, invalid final arguments

13 are streams a correct client must accept and 14 are broken. streamfault list shows all 27 with their expected verdict, and streamfault show <name> says what a client should do with each.

Rust code can skip HTTP and feed the exact byte fragments to a parser, which is the only way to test a specific read boundary:

let s = streamfault::scenario::find("chat-utf8-split").unwrap();
for fragment in &s.fragments { /* feed your parser */ }

Bring your own streams

The catalog is a directory you can edit. Export it, add a .sse file and a manifest entry, and every command uses your version:

$ streamfault export my-fixtures
$ curl -N https://your-provider/... > my-fixtures/prod-incident.sse
$ # add {"name": "prod-incident", "api": "chat_completions", "file": "prod-incident.sse"} to my-fixtures/manifest.json
$ streamfault --fixtures my-fixtures serve

Only name, api and file are required. Leave out expected and the reference consumer fills in its own verdict. To judge a capture without adding it, run streamfault classify --api chat capture.sse. It exits 0, 10 or 11 for complete, incomplete and error.

How a stream is judged

Verdict Chat Completions Responses
complete finish_reason of stop, tool_calls or function_call, then data: [DONE] a response.completed event
incomplete either one missing, or any other finish_reason such as length response.incomplete, or no terminal event
error a data: {"error": ...} payload an error or response.failed event

Tool-call arguments must also parse as JSON. A clean HTTP EOF never counts as completion: 12 of the 27 scenarios end cleanly and are incomplete or erroneous. The full rules are in docs/reference.md.

Commands

Command What it does
list, show <scenario> browse scenarios and what a client should do with each
bytes <scenario> [--fragments] print the exact body, or each fragment escaped
replay <scenario> or --all, [--http] run the reference consumer and compare with the expected outcome
classify --api chat|responses <file> judge a stream you captured
export <dir>, verify <dir> write the fixtures, or check a copy against the catalog
serve the fake server. --framing close hides aborts from the HTTP layer

Fixtures are deterministic. The same name gives the same bytes on every run and every build.

Examples

$ cargo run -q --example naive_vs_careful        # a 20-line reader, wrong on 13 of 15 chat scenarios
$ python3 examples/python/stdlib_client.py       # a careful consumer, right on 27/27 scenarios and 72/72 edge cases
$ python3 examples/python/openai_sdk_probe.py    # what your installed openai SDK does with each scenario

The naive reader gets the two plain controls right and fails everything else, which is how such code passes a happy-path test.

What was tested

Two versions of openai-python were run against these synthetic fixtures on loopback: 2.54.0 with httpx 0.28.1, and 3.49.0 with httpx2 2.16.0, both on Python 3.13.5. Full output is in observed/. These are measured results, and they say nothing about what any real provider sends.

  • chat-bom returns ", world!" in both versions.
  • chat-eof-mid-text and chat-eof-in-tool-args return partial output with finish_reason None in both versions, from iteration and from get_final_completion().
  • chat-parallel-tool-calls-second-truncated returns one intact call and one cut-off call, with finish_reason=tool_calls, in both versions.
  • When a Responses body ends cleanly without response.completed, get_final_response() raises RuntimeError. Plain iteration raises nothing, even for an error event.
  • An aborted connection raises httpx.RemoteProtocolError in 2.54.0 and APIConnectionError in 3.49.0. That is the only difference between the two versions across all 27 scenarios.

Reported by others and not run here: openai-go#1056 on the BOM, and openai-python#4063 on the early EOF, where commenters report reproducing it on 3.31.0 and 3.34.0. Both were open when last checked on 2026-11-12. docs/reference.md keeps measured results, source reading and outside reports apart.

cargo test -- --include-ignored passes 48 tests, covering direct fragments, the loopback HTTP server and the CLI.

Limitations

  • OpenAI wire formats only: streaming Chat Completions and Responses over HTTP/1.0 and 1.1. No Anthropic or Gemini formats, no TLS, HTTP/2, Realtime or non-streaming replies.
  • Fixtures are hand-written to the documented shapes, not captured from a provider.
  • With the default chunked framing the server writes one HTTP chunk per fragment, but it cannot control where your client's reads split. For exact boundaries, use the fragments directly.
  • No stalls, TCP resets, or 429 and 5xx responses.
  • The reference consumer covers the fixtures and the listed edge cases. It is not a schema validator for arbitrary provider output.
  • SDK results cover two versions of one SDK on one machine.

License

MIT OR Apache-2.0. See LICENSE-MIT and LICENSE-APACHE.

About

Break your LLM streaming client on purpose, offline: 27 fixed SSE streams and a local fake server for OpenAI-style clients

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages