﻿# Read gRPC trailers before declaring generation successful

Observe the terminal RPC status after reading the stream; valid messages and HTTP success do not establish RPC success.

Author: Retrivium editorial team
Updated: 2026-11-03
Canonical URL: https://retrivium.ai/journal/guide-grpc-trailer-status/
Language: en

A streaming inference RPC delivers several valid messages and then ends with an error status. A wrapper reports success because it stopped checking after the first message or looked only at the HTTP response status. In gRPC, the final RPC outcome belongs to the RPC lifecycle, including its status and trailing metadata.

## Keep HTTP and RPC outcomes separate

The transport can establish a response successfully while the remote procedure later fails. Use the language client's supported status or completion API rather than translating a successful HTTP response directly into application success. A custom gateway that converts RPC to another protocol must preserve the final outcome deliberately. Otherwise partial output can reach the user with no indication that the procedure did not complete as promised.

## Read until the documented completion point

For a server-streaming call, consume messages according to the API and observe the final status when the stream completes. Access to trailers is often meaningful only at that stage. A normal message does not guarantee that another will arrive or that the call will finish successfully. Keep the handling of end-of-messages, final metadata and call error explicit, using the conventions of the installed language library rather than assuming identical behavior across clients.

## Classify partial output carefully

When a non-successful call has delivered useful text, retain that text only with its incomplete status. Do not merge it with a fresh attempt as though both belonged to one verified generation. Record the RPC code, a sanitized description and safe correlation metadata. The description can contain server-generated information and should not be treated as trusted user-facing prose without appropriate handling. Preserve machine-readable status for diagnosis rather than parsing English wording.

## Separate retry policy from status parsing

Correctly observing failure is only the first decision. Whether to retry depends on the code, the application's operation semantics and evidence about prior execution. A transient service error does not automatically make generation idempotent. The caller's deadline and cancellation remain relevant. An implementation should explain why it retried or stopped, and should keep each attempt identifiable. Reading trailers supplies an outcome, not a universal guarantee that duplicate model work cannot happen.

## Test success and late failure

Use a controlled RPC fixture that produces a normal successful stream, a failure before messages and a failure after partial messages. Verify that the wrapper exposes different outcomes and that the public gateway preserves them where conversion is supported. Also test cancellation so it does not appear as an ordinary completed result. Acceptance means the client reports the actual terminal RPC status, handles trailing metadata at the right time and preserves partial-result limitations. It does not require judging whether the generated content was accurate; protocol completion and model quality remain distinct checks.

## Primary references

[gRPC Status Codes](https://grpc.io/docs/guides/status-codes/). Defines RPC status codes and how library-generated and application-generated outcomes are represented.

[gRPC Metadata](https://grpc.io/docs/guides/metadata/). Defines headers and trailers and their role in conveying an RPC outcome.

[gRPC Core Concepts](https://grpc.io/docs/what-is-grpc/core-concepts/). Defines server-streaming call lifecycle and final completion semantics.

Related reading: [Handle final completion correctly in Triton decoupled streaming](/journal/triton-decoupled-stream-completion/); [Terminal request records: reconcile stream, usage and logs](/journal/provider-terminal-request-record-consistency/).
