Preserve allocated response item IDs in requests (#60977)

## Why

Providers can echo a bare reserved prefix or return an opaque item ID. Request preparation previously stripped these IDs when they lacked an underscore prefix, even if they carried allocation metadata.

## What changed

- Keep response item IDs with allocation metadata when preparing requests.
- Add `ResponseItemId::with_generation_prefix` to attach a request reservation's allocation while preserving the exact wire ID and recording a matching item-kind prefix and provider suffix.

GitOrigin-RevId: 3249c2669aca11ee5facbd8a246016490a29a4f4
This commit is contained in:
Ruslan Nigmatullin
2026-11-12 02:43:37 +00:00
committed by copyberry
parent 0702ebed4d
commit cbd4944092
2 changed files with 29 additions and 2 deletions
+7 -2
View File
@@ -1317,7 +1317,11 @@ impl ModelClient {
fn prepare_response_items_for_request(&self, input: &mut [ResponseItem]) {
for item in input {
if item.id().is_some_and(|id| !id.is_prefixed()) {
// A provider can echo a bare reserved prefix or return an opaque ID.
if item
.id()
.is_some_and(|id| id.allocation().is_none() && !id.is_prefixed())
{
item.set_id(/*new_id*/ None);
}
if !self.state.content_item_kinds_enabled {
@@ -2744,9 +2748,10 @@ fn map_response_stream(
let routing_affinity = api_stream.routing_affinity.take();
let upstream_request_id = api_stream.upstream_request_id.take();
let interrupt = api_stream.interrupt.take();
let events = crate::model_request::intercept_stream(Box::pin(api_stream), interceptors);
let mut stream = map_response_events(
upstream_request_id,
crate::model_request::intercept_stream(Box::pin(api_stream), interceptors),
events,
session_telemetry,
inference_trace_attempt,
client,