fix: preserve non-OpenAI attributes in final streaming chunk

When an upstream server injects custom attributes into SSE streaming chunks,
preserve_upstream_non_openai_attributes() correctly copies them to the
ModelResponseStream for content-bearing chunks - but NOT for the final chunk
(the one with finish_reason set and empty/null content).

This fix adds the preserve_upstream_non_openai_attributes() call in the
received_finish_reason branch, ensuring custom metadata attached to the
last SSE chunk is preserved and passed to the client.

Fixes #23444
This commit is contained in:
Jah-yee 2026-03-12 22:23:21 +08:00
parent 176a2653da
commit 024a5de501

View file

@ -1026,6 +1026,14 @@ class CustomStreamWrapper:
self.sent_last_chunk = True
# Preserve custom attributes from original chunk to final chunk
_original_chunk = response_obj.get("original_chunk")
if _original_chunk:
preserve_upstream_non_openai_attributes(
model_response=model_response,
original_chunk=_original_chunk,
)
return model_response
elif self._has_special_delta_content(model_response):
return self._handle_special_delta_content(model_response)