Capture local attachments before queuing turn input (#61962)

## Why

Queued input can outlive its local attachment files. Reading those files only when rendering a model message can lose media submitted while turn admission is pending.

## What changed

- Introduce `ResolvedUserInput` to carry captured image bytes, audio data URLs, or read errors through session queues and agent input.
- Resolve client attachments on the submitting host before queuing, using a blocking task for local file reads.
- Render messages from captured payloads while preserving original paths and text spans for display, along with image position mappings.

## Testing

Add coverage for rendering and serialization after source files are removed, steered audio retained during pending admission, and local audio errors and display content.

GitOrigin-RevId: 4bbb6bda44167439a8cfdae15d3c476a7b1d336b
This commit is contained in:
Adam Perry @ OpenAI
2026-11-17 04:08:00 +00:00
committed by copyberry
parent 65a4450886
commit d8d840d32a
50 changed files with 1060 additions and 573 deletions
@@ -5,6 +5,7 @@ use crate::agent::control::render_input_preview;
use crate::tools::handlers::multi_agents_spec::create_send_input_tool_v1;
use codex_protocol::protocol::MultiAgentVersion;
use codex_tools::ToolSpec;
use codex_user_input::ResolvedUserInput;
pub(crate) struct Handler;
@@ -49,6 +50,10 @@ impl Handler {
let receiver_thread_id = parse_agent_id_target(&args.target)?;
let input_items = parse_collab_input(args.message, args.items)?;
let prompt = render_input_preview(&input_items);
let input_items = input_items
.into_iter()
.map(ResolvedUserInput::from_client)
.collect();
let local_agent_control = session
.services
.local_agent_runtime
@@ -16,6 +16,7 @@ use crate::tools::handlers::multi_agents_spec::SpawnAgentToolOptions;
use crate::tools::handlers::multi_agents_spec::create_spawn_agent_tool_v1;
use codex_protocol::protocol::MultiAgentVersion;
use codex_tools::ToolSpec;
use codex_user_input::ResolvedUserInput;
#[derive(Default)]
pub(crate) struct Handler {
@@ -80,6 +81,10 @@ async fn handle_spawn_agent(
"Agent depth limit reached. Solve the task yourself.".to_string(),
));
}
let input_items = input_items
.into_iter()
.map(ResolvedUserInput::from_client)
.collect();
session
.emit_turn_item_started(
turn,
@@ -74,6 +74,7 @@ use codex_protocol::protocol::TurnAbortedEvent;
use codex_protocol::protocol::TurnCompleteEvent;
use codex_protocol::user_input::UserInput;
use codex_state::DirectionalThreadSpawnEdgeStatus;
use codex_user_input::ResolvedUserInput;
use core_test_support::TempDirExt;
use opentelemetry_sdk::metrics::InMemoryMetricExporter;
use opentelemetry_sdk::metrics::data::AggregatedMetrics;
@@ -1336,10 +1337,7 @@ async fn multi_agent_v2_send_message_accepts_root_target_from_child() {
.control(session.session_id())
.spawn_agent_with_metadata(
(*turn.config).clone(),
vec![UserInput::Text {
text: "inspect this repo".to_string(),
text_elements: Vec::new(),
}],
vec![ResolvedUserInput::text("inspect this repo".to_string())],
SessionSource::SubAgent(SubAgentSource::ThreadSpawn {
parent_thread_id: root.thread_id,
depth: 1,
@@ -1417,10 +1415,7 @@ async fn multi_agent_v2_followup_task_rejects_root_target_from_child() {
.control(session.session_id())
.spawn_agent_with_metadata(
(*turn.config).clone(),
vec![UserInput::Text {
text: "inspect this repo".to_string(),
text_elements: Vec::new(),
}],
vec![ResolvedUserInput::text("inspect this repo".to_string())],
SessionSource::SubAgent(SubAgentSource::ThreadSpawn {
parent_thread_id: root.thread_id,
depth: 1,
@@ -1584,10 +1579,7 @@ async fn multi_agent_v2_list_agents_filters_by_relative_path_prefix() {
.control(session.session_id())
.spawn_agent_with_metadata(
config.clone(),
vec![UserInput::Text {
text: "research".to_string(),
text_elements: Vec::new(),
}],
vec![ResolvedUserInput::text("research".to_string())],
SessionSource::SubAgent(SubAgentSource::ThreadSpawn {
parent_thread_id: root.thread_id,
depth: 1,
@@ -1605,10 +1597,7 @@ async fn multi_agent_v2_list_agents_filters_by_relative_path_prefix() {
.control(session.session_id())
.spawn_agent_with_metadata(
config,
vec![UserInput::Text {
text: "build".to_string(),
text_elements: Vec::new(),
}],
vec![ResolvedUserInput::text("build".to_string())],
SessionSource::SubAgent(SubAgentSource::ThreadSpawn {
parent_thread_id: root.thread_id,
depth: 2,
@@ -4154,10 +4143,7 @@ async fn multi_agent_v2_interrupt_agent_rejects_self_target_by_id() {
.control(session.session_id())
.spawn_agent_with_metadata(
(*turn.config).clone(),
vec![UserInput::Text {
text: "inspect this repo".to_string(),
text_elements: Vec::new(),
}],
vec![ResolvedUserInput::text("inspect this repo".to_string())],
SessionSource::SubAgent(SubAgentSource::ThreadSpawn {
parent_thread_id: root.thread_id,
depth: 1,
@@ -4222,10 +4208,7 @@ async fn multi_agent_v2_interrupt_agent_rejects_self_target_by_task_name() {
.control(session.session_id())
.spawn_agent_with_metadata(
(*turn.config).clone(),
vec![UserInput::Text {
text: "inspect this repo".to_string(),
text_elements: Vec::new(),
}],
vec![ResolvedUserInput::text("inspect this repo".to_string())],
SessionSource::SubAgent(SubAgentSource::ThreadSpawn {
parent_thread_id: root.thread_id,
depth: 1,