Commit Graph
1 Commits
Author SHA1 Message Date
yetone 29bfd5dc8b gateway: a Responses stream magpie ends is a whole response.failed (plugins#852)
When a Responses stream ended short or was cut, passthrough wrote a
response.failed with only object, status and error. Grok Build reads
the Responses stream through async-openai's types. Their Response needs
id, created_at, model, object, output and status, and the event needs
sequence_number. So a Grok plugin stream cut by the vendor ended in
"serialization error: missing field `created_at`" instead of the error
(lxyer's report behind plugins#852).

Now passthrough writes a whole response.failed:
- usageSniffer keeps the stream's response id, created_at and the next
  sequence_number;
- if responsesTextCalls renumbered the events on the way out, the
  failure follows the last number the client got;
- id, created_at, model and the error are filled in.
Before any event there is a fresh resp_ id and the time now.
The Chat and Gemini failures are unchanged. The translator paths
already end through responsesEncoder, which writes a whole response,
and nothing else writes a Responses streamFailure.

Run:
- On mote, at this tree: gofmt -l; go vet ./... on darwin, linux nogui
  and windows; builds for all three; go test -tags nogui -timeout 45m
  ./...: 87 packages ok, one red,
  TestCancelledSignInEndsItsFetch in internal/plugin, which this change
  doesn't reach (open as #5264). That run was at the base 0fc3455e2.
  Rebased on 00198b26e (#5655, gateway): gofmt -l, vet on all three
  systems and go test ./internal/gateway again: ok. Rebased again on
  cdf734757 (automode text, OpenMausBot): vet, build and
  -run 'StreamFailure|AutoMode|Automode|Anthropic' ./internal/gateway ok.
- Red on the old code (the tests at 0fc3455e2's gateway.go and
  sniff.go): TestResponsesStreamFailureIsAWholeResponse ("no
  sequence_number", "response.created_at missing") and
  TestResponsesStreamFailureBeforeAnyEvent.
- Real Grok Build 1.0.67 on mote (`grok -p`, api_backend responses)
  against a fake server replaying each ending:
  - the old frame: "missing field 'created_at'";
  - a whole response without sequence_number: "missing field
    'sequence_number'";
  - the new frame, after text, after response.created, and bare: read,
    and retried as server_error, with no serde error.

Not tried: Grok Build 1.0.77 (the reporter's), and a live Grok stream
cut by the vendor.
2026-11-08 11:03:09 +08:00