zhaoyaoyuan's relay ends its Chat stream with `data:[DONE]`, no space
after the colon, which SSE allows. holdWriter.see only knew
"data: [DONE]", so the try never counted as ended, and pi, which stops
reading at [DONE], was logged 499 "the agent canceled the request" for
a reply it had whole (48 of 58 requests through that relay).
streamEnds now lists every spelling a relay sends: data: with and
without the space, event: message_stop with and without it, and the
JSON type markers with and without a space after the colon (Python
relays write `"type": "message_stop"`). The SSE markers are anchored to
the start of a line, and the stream's first byte counts as one, so a
reply whose text quotes "data:[DONE]" no longer ends it (the old
unanchored "data: [DONE]" did).
Siblings: every other SSE reader in the gateway, middleware, redact and
library (sniff, sse.readSSE, ttft, streamEvent, loop_guard, member,
chattidy, textcalls, toolsearch, grok_*, gemini_signature, codex_limits,
qoder, provider/test.go) cuts "data:" and trims the space already, so
holdWriter.see was the only one with a spelling written in.
Not changed: an agent that hangs up on the finish_reason chunk, before
[DONE] (the repro script's --early mode), is still 499. The usage chunk
and [DONE] come after finish_reason in Chat, and the OpenAI SDK pi uses
reads on to [DONE].
Run:
- TestHangUpAfterStreamEndIsNotCanceled goes through the real Handler
with an upstream that writes the reporter's stream tail and an agent
that hangs up the moment [DONE] / message_stop reaches it. With the
old streamEnds: chat unspaced, chat unspaced CRLF and anthropic
unspaced FAIL "a reply the agent had whole was logged as 499 \"the
agent canceled the request\", out=31"; chat spaced passes on both.
- TestHoldWriterSeesEveryStreamEnd cuts each stream at every byte. Old
code: "chat unspaced cut at 1: ended = false, want true". With the
markers unanchored: "text about DONE cut at 1: ended = true, want false".
- gofmt -l, go vet (darwin), GOOS=linux go vet -tags nogui, GOOS=windows
go vet on internal/gateway: clean.
- go test -tags nogui ./internal/gateway -count=1: ok (371s).
Not tried: the reporter's relay itself, or the built binary with pi.