﻿# Connect streaming: EndStreamResponse is a protocol envelope, not a model message

Decode Connect's final stream envelope separately from schema-defined messages, retain terminal errors and metadata, and distinguish unary from streaming responses.

Author: Retrivium editorial team
Updated: 2026-11-04
Canonical URL: https://retrivium.ai/journal/guide-connect-endstream-response-envelope/
Language: en

## A Connect response stream has a final control message

The Connect protocol defines an EndStreamResponse as the final enveloped message of a response stream. Its framing flag distinguishes that control message from the response type declared in the service schema.

An inference client therefore should not deserialize every envelope as a model result. The final envelope carries protocol information with a different structure. Treating it as an empty or malformed model message can discard the outcome that explains whether earlier streamed results completed successfully.

## Streaming success cannot come from the opening status

Connect documents a successful HTTP opening status for streaming responses, including streams that later report an error. Once headers are sent, a later application failure is carried through the streaming protocol rather than a replacement HTTP status.

A proposed client keeps stream establishment separate from final RPC success. Intermediate responses may be useful partial results, but their arrival does not establish that the intended operation finished. An interface can display partial output while preserving the terminal failure instead of silently labeling the entire operation successful.

## The final JSON has explicit success and error rules

The protocol serializes EndStreamResponse using JSON. A failed RPC includes an error object; a successful one omits that property. The specification distinguishes omission from invalid null or empty error representations.

A custom decoder needs this control schema even when application messages use protobuf. The payload format for model results does not determine how every control envelope is decoded. Preserve optional trailing metadata according to the protocol rather than merging it into an unrelated generated-answer object.

## Unary and streaming paths are intentionally different

Connect's error guide explains that unary errors can use an error HTTP status and a JSON body, while streaming errors use the final stream representation. A shared client abstraction should normalize the application outcome without pretending that both wire paths are identical.

The Go implementation exposes coded errors and structured detail facilities. A wrapper should preserve their machine category when converting them into an application's own result type. Returning only the last successfully decoded application message can hide a later terminal failure.

## Framing and completion need independent review

Connect's streaming guide describes protocol-specific framing and different trailer encodings across supported protocols. A generic HTTP body viewer is not automatically a complete Connect stream decoder. It can show readable fragments without interpreting the final control information.

A proposed review includes successful termination, a coded terminal error, malformed control data and an incomplete tail. It verifies that final outcome, trailing metadata and model messages remain separate, without asserting that an application-level partial result becomes committed merely because its bytes reached the consumer.

## Primary references

[Connect protocol reference](https://connectrpc.com/docs/protocol/).

[Connect streaming guide](https://connectrpc.com/docs/go/streaming/).

[Connect error handling](https://connectrpc.com/docs/go/errors/).

Related explanations: [Stream completion contracts](/journal/provider-sse-terminal-eof-contract/); [Payload conformance](/journal/provider-structured-output-conformance-tests/).
