Support image attachments in agents overview background tasks (#44027)

## Why

The agents overview submitted background task prompts as plain text, without image attachments or their text elements.

## What changed

- Enable image pasting in the overview composer and include attachments and text elements in the first task prompt.
- Resolve local image paths and send image bytes when using a remote workspace.
- Reject image inputs for models declared text-only before starting a thread.
- Restore unsent text and attachments after failures, or show image reattachment paths when a newer draft prevents restoration.

## Testing

Add tests for attachment rendering and submission, remote image payloads, draft recovery without overwriting newer text, and text-only model rejection.

GitOrigin-RevId: 08e3db8bace51ec007f5741f1b2be94658cbaea4
This commit is contained in:
Eric Traut authored and copyberry committed 2026-09-09 03:12:46 +00:00
1 parent 7aba218851
commit 2ce38ae6d8
6 files changed
+365 -20

No files matched your search

+89 -8
View File
@@ -13,6 +13,7 @@ use crate::bottom_pane::SelectionItem;
use crate::bottom_pane::SelectionViewParams;
use crate::bottom_pane::popup_consts::standard_popup_hint_line_for_keymap;
use crate::chatwidget::ThreadInputStateRestoreMode;
use crate::chatwidget::UserMessage;
use codex_app_server_protocol::RequestId;
use codex_app_server_protocol::SessionSource;
use codex_app_server_protocol::Thread;
@@ -20,7 +21,10 @@ use codex_app_server_protocol::ThreadHistoryMode;
use codex_app_server_protocol::TurnStartParams;
use codex_app_server_protocol::TurnStartResponse;
use codex_app_server_protocol::UserInput;
use codex_protocol::models::snapshot_local_user_input;
use codex_protocol::openai_models::InputModality;
use codex_protocol::protocol::SubAgentSource;
use codex_protocol::user_input::UserInput as CoreUserInput;
pub(crate) const AGENTS_OVERVIEW_VIEW_ID: &str = "agents-overview";
@@ -615,7 +619,7 @@ impl App {
pub(super) async fn dispatch_agents_overview_task(
&mut self,
app_server: &mut AppServerSession,
prompt: String,
prompt: UserMessage,
cwd: Option<AbsolutePathBuf>,
) {
self.refresh_in_memory_config_from_disk_best_effort("starting a background task")
@@ -720,6 +724,69 @@ impl App {
.or_else(|| self.model_catalog.models.first())
.map(|model| model.model.clone());
}
let model = config.model.as_deref().or_else(|| {
self.model_catalog
.models
.iter()
.find(|model| model.is_default)
.or_else(|| self.model_catalog.models.first())
.map(|model| model.model.as_str())
});
if !prompt.local_images.is_empty()
&& let Some(model) = model
&& self.model_catalog.models.iter().any(|preset| {
preset.model == model && !preset.input_modalities.contains(&InputModality::Image)
})
{
let message = format!(
"Model {model} does not support image inputs. Remove images or switch models."
);
self.restore_agents_overview_prompt(prompt);
self.chat_widget.add_error_message(message);
return;
}
let images = prompt
.local_images
.iter()
.map(|image| {
Ok(CoreUserInput::LocalImage {
path: std::path::absolute(&image.path)?,
detail: None,
})
})
.collect::<std::io::Result<Vec<_>>>();
let images = match images {
Ok(images) => images,
Err(error) => {
self.restore_agents_overview_prompt(prompt);
self.chat_widget
.add_error_message(format!("Failed to prepare image: {error}"));
return;
}
};
let images = if app_server.uses_remote_workspace() && !images.is_empty() {
match tokio::task::spawn_blocking(move || {
let mut images = images;
for image in &mut images {
snapshot_local_user_input(image)?;
}
Ok::<_, std::io::Error>(images)
})
.await
.map_err(std::io::Error::other)
.and_then(|result| result)
{
Ok(images) => images,
Err(error) => {
self.restore_agents_overview_prompt(prompt);
self.chat_widget
.add_error_message(format!("Failed to prepare image: {error}"));
return;
}
}
} else {
images
};
match app_server
.start_thread_with_session_start_source(
&self.local_settings,
@@ -735,8 +802,13 @@ impl App {
self.agents_overview
.dispatched_requests
.insert(thread_id, Vec::new());
self.submit_agents_overview_prompt(app_server, thread_id, prompt)
.await;
self.submit_agents_overview_prompt(
app_server,
thread_id,
prompt,
images.into_iter().map(Into::into).collect(),
)
.await;
}
Err(error) => {
self.restore_agents_overview_prompt(prompt);
@@ -750,18 +822,27 @@ impl App {
&mut self,
app_server: &AppServerSession,
thread_id: ThreadId,
prompt: String,
prompt: UserMessage,
mut input: Vec<UserInput>,
) {
if !prompt.text.is_empty() {
input.push(UserInput::Text {
text: prompt.text.clone(),
text_elements: prompt
.text_elements
.iter()
.cloned()
.map(Into::into)
.collect(),
});
}
let result = app_server
.request_handle()
.request_typed::<TurnStartResponse>(ClientRequest::TurnStart {
request_id: RequestId::String(Uuid::new_v4().to_string()),
params: TurnStartParams {
thread_id: thread_id.to_string(),
input: vec![UserInput::Text {
text: prompt.clone(),
text_elements: Vec::new(),
}],
input,
..Default::default()
},
})