Support image references by file ID in inputs and tool outputs (#45794)

## What changed

- Accept `fileId` alongside the existing `url` form for app-server image inputs, and forward file references to the Responses API as `file_id`. Update generated schemas and client types.
- Preserve file references, image detail hints, and mixed inline/file image ordering through user-message events, thread history, and rollout migration. Retain file images when truncating tool output.
- Pass file references through image preparation without resolving them, while keeping resize-notice numbering correct. Omit them from unsupported TUI display and Guardian image context.
- Reject image-edit requests whose recent-image window includes a file reference, preventing selection of an older inline image instead.

## Testing

Add coverage for serialization, request and rollout preservation, mixed-image history ordering, incomplete ordering metadata, tool-output truncation, and rejection of unsupported image-edit selections.

GitOrigin-RevId: 6ca20a8577155cc934b720803c3b7b3bffdf972a
This commit is contained in:
Krish Chainani authored and copyberry committed 2026-09-15 21:19:08 +00:00
1 parent c51cb968e4
commit 7b8b17b97a
95 files changed
+2434 -324

No files matched your search

+4
View File
@@ -105,6 +105,10 @@ impl SectionCost {
self.image_bytes = self.image_bytes.saturating_add(image_url.len());
self.image_count = self.image_count.saturating_add(1);
}
ContentItem::InputImage {
image: ImageReference::File { .. },
..
} => {}
ContentItem::InputAudio { audio_url } => {
// Guardian currently has no audio contributor. Count a future opaque
// payload conservatively until its consumer supplies modality costs.
+25 -7
View File
@@ -210,20 +210,27 @@ impl CollectedContext {
let items = evidence
.items
.into_iter()
.map(|item| match item {
.filter_map(|item| match item {
UserInput::Text { text, .. } => {
Ok(Budgeted::required(ContentItem::InputText { text }))
Some(Ok(Budgeted::required(ContentItem::InputText { text })))
}
UserInput::Image { image_url, detail } => Ok(Budgeted::optional(
UserInput::Image {
image: ImageReference::Inline { image_url },
detail,
} => Some(Ok(Budgeted::optional(
ContentItem::InputImage {
image: ImageReference::Inline { image_url },
detail,
},
BudgetPriority::Image,
)),
_ => Err(SectionError::UnsupportedDelivery {
))),
UserInput::Image {
image: ImageReference::File { .. },
..
} => None,
_ => Some(Err(SectionError::UnsupportedDelivery {
section: "node_repl_evidence",
}),
})),
})
.collect::<Result<Vec<_>, _>>()?;
(
@@ -288,7 +295,14 @@ impl ComposedContext {
ContentItem::InputImage {
image: ImageReference::Inline { image_url },
detail,
} => UserInput::Image { image_url, detail },
} => UserInput::Image {
image: ImageReference::Inline { image_url },
detail,
},
ContentItem::InputImage {
image: ImageReference::File { .. },
..
} => continue,
ContentItem::InputAudio { .. } | ContentItem::OutputText { .. } => {
return Err(SectionError::UnsupportedDelivery {
section: section.id,
@@ -316,6 +330,10 @@ impl ComposedContext {
}
}));
}
ContentItem::InputImage {
image: ImageReference::File { .. },
..
} => {}
content => user_content.push(content),
}
}
@@ -95,6 +95,10 @@ impl ComposedContext {
image: ImageReference::Inline { image_url },
detail,
} => admit(image_url, detail),
ContentItem::InputImage {
image: ImageReference::File { .. },
..
} => false,
_ => true,
});
}
@@ -281,6 +285,10 @@ fn retain_content(
image: ImageReference::Inline { image_url },
..
} => image_url.len(),
ContentItem::InputImage {
image: ImageReference::File { .. },
..
} => 0,
ContentItem::InputAudio { audio_url } => audio_url.len(),
};
truncations.push(TruncationObservation {
+38 -18
View File
@@ -85,18 +85,26 @@ impl TranscriptImages {
});
};
// TODO(kc) Include file-backed images once Guardian can admit them without resolving or
// applying byte-based checks in Core.
for item in items {
match item {
ResponseItem::Message { role, content, .. }
if matches!(role.as_str(), "user" | "assistant") =>
{
for item in content {
if let ContentItem::InputImage {
image: ImageReference::Inline { image_url },
detail,
} = item
{
include_image(image_url, *detail);
match item {
ContentItem::InputImage {
image: ImageReference::Inline { image_url },
detail,
} => include_image(image_url, *detail),
ContentItem::InputImage {
image: ImageReference::File { .. },
..
}
| ContentItem::InputText { .. }
| ContentItem::InputAudio { .. }
| ContentItem::OutputText { .. } => {}
}
}
}
@@ -106,12 +114,18 @@ impl TranscriptImages {
{
if let Some(content) = output.content_items() {
for item in content {
if let FunctionCallOutputContentItem::InputImage {
image: ImageReference::Inline { image_url },
detail,
} = item
{
include_image(image_url, *detail);
match item {
FunctionCallOutputContentItem::InputImage {
image: ImageReference::Inline { image_url },
detail,
} => include_image(image_url, *detail),
FunctionCallOutputContentItem::InputImage {
image: ImageReference::File { .. },
..
}
| FunctionCallOutputContentItem::InputText { .. }
| FunctionCallOutputContentItem::InputAudio { .. }
| FunctionCallOutputContentItem::EncryptedContent { .. } => {}
}
}
}
@@ -121,12 +135,18 @@ impl TranscriptImages {
}
if input.include_tool_outputs {
for image in input.node_repl_images {
if let ContentItem::InputImage {
image: ImageReference::Inline { image_url },
detail,
} = image
{
include_image(image_url, *detail);
match image {
ContentItem::InputImage {
image: ImageReference::Inline { image_url },
detail,
} => include_image(image_url, *detail),
ContentItem::InputImage {
image: ImageReference::File { .. },
..
}
| ContentItem::InputText { .. }
| ContentItem::InputAudio { .. }
| ContentItem::OutputText { .. } => {}
}
}
}
@@ -98,3 +98,69 @@ fn image_selection_preserves_source_policy_order_and_both_limits() {
}
);
}
/// File-backed images stay out of Guardian without consuming its inline-image capacity.
#[test]
fn file_images_are_omitted_without_displacing_inline_images() {
let file_image = ContentItem::InputImage {
image: ImageReference::File {
file_id: "file_123".to_string(),
},
detail: Some(ImageDetail::High),
};
let history = [
ResponseItem::Message {
id: None,
role: "user".into(),
content: vec![image("first"), file_image.clone(), image("second")],
phase: None,
internal_chat_message_metadata_passthrough: None,
},
ResponseItem::FunctionCallOutput {
id: None,
call_id: Some("screenshot".into()),
name: None,
namespace: None,
output: FunctionCallOutputPayload::from_content_items(vec![
FunctionCallOutputContentItem::InputImage {
image: ImageReference::File {
file_id: "file_tool".to_string(),
},
detail: Some(ImageDetail::High),
},
FunctionCallOutputContentItem::InputImage {
image: ImageReference::Inline {
image_url: "third".into(),
},
detail: Some(ImageDetail::High),
},
]),
internal_chat_message_metadata_passthrough: None,
},
];
let repl = [
file_image,
image("fourth"),
ContentItem::InputImage {
image: ImageReference::File {
file_id: "file_repl".to_string(),
},
detail: Some(ImageDetail::High),
},
];
assert_eq!(
TranscriptImages::collect(
&history,
TranscriptImageInput {
enabled: true,
include_tool_outputs: true,
node_repl_images: &repl,
}
),
TranscriptImages {
images: ["first", "second", "third", "fourth"].map(image).to_vec(),
omitted_bytes: 0,
}
);
}
+14 -7
View File
@@ -9,6 +9,7 @@ use crate::SectionInput;
use crate::SectionScope;
use codex_context_fragments::ContextualUserFragment;
use codex_protocol::models::ContentItemKind;
use codex_protocol::models::ImageReference;
use codex_protocol::user_input::UserInput;
use codex_protocol::user_input::UserInput::Image;
use codex_protocol::user_input::UserInput::Text;
@@ -84,10 +85,15 @@ impl NodeReplContext<'_> {
pub fn render_inputs(&self) -> Vec<UserInput> {
if self.mode != NodeReplReviewEvidenceMode::Multimodal
|| !self.responses.iter().any(|response| {
response
.items
.iter()
.any(|item| matches!(item, Image { .. }))
response.items.iter().any(|item| {
matches!(
item,
Image {
image: ImageReference::Inline { .. },
..
}
)
})
})
{
return vec![text_input(self.render())];
@@ -138,9 +144,10 @@ impl NodeReplContext<'_> {
for item in response.items {
match item {
Text { text, .. } => inputs.push(text_input(format!("{text}\n"))),
Image { image_url, .. } if seen_images.insert(image_url) => {
inputs.push(item.clone())
}
Image {
image: ImageReference::Inline { image_url },
..
} if seen_images.insert(image_url) => inputs.push(item.clone()),
_ => {}
}
}