Send local TUI images as portable attachments to remote app servers (#45499)

## Why

Remote app servers cannot read image paths on the TUI host. Image attachments need to carry their contents when submitting to a remote workspace.

## What changed

- Prepare local images as data URLs off the event loop for new turns and steers, preserving source pixels for model-specific resizing and enforcing a 32 MiB image transport budget.
- Show preparation progress, preserve queued message order, and recover drafts on preparation failures, cancellation, disconnects, or thread switches. Ignore stale preparation completions.
- Avoid duplicate user messages from server receipts and duplicate image labels in history.

## Testing

Add regression tests for portable image contents, receipt deduplication, draft restoration, responsive input during preparation, and cancellation across thread and connection changes.

GitOrigin-RevId: 6404615eae0b06c141af96b4229501c61f7fcfee
This commit is contained in:
Eric Traut authored and copyberry committed 2026-09-14 19:21:08 +00:00
1 parent afaad7cdc0
commit d38b5260a1
21 files changed
+731 -40

No files matched your search

+16
View File
@@ -343,6 +343,7 @@ use self::ide_context::IdeContextState;
mod input_queue;
mod reconnect;
use self::input_queue::InputQueueState;
mod image_submission;
mod input_flow;
mod input_restore;
mod input_submission;
@@ -596,6 +597,9 @@ pub(crate) struct ChatWidget {
pub(crate) initial_user_message: Option<UserMessage>,
status_account_display: Option<StatusAccountDisplay>,
pub(crate) remote_connection: Option<RemoteConnectionStatus>,
/// Remote app servers cannot read image paths on the TUI host.
pub(crate) snapshot_local_images: bool,
pending_image_submission: Option<image_submission::PendingImageSubmission>,
pub(crate) local_worktree_operations: bool,
pub(crate) windows_sandbox_host: crate::app::WindowsSandboxHost,
#[cfg(any(target_os = "windows", test))]
@@ -816,6 +820,7 @@ pub(crate) struct ChatWidget {
current_goal_status: Option<GoalStatusState>,
external_editor_state: ExternalEditorState,
last_rendered_user_message_display: Option<UserMessageDisplay>,
last_rendered_user_message_client_id: Option<String>,
last_non_retry_error: Option<(String, String)>,
}
@@ -1354,6 +1359,12 @@ impl ChatWidget {
return;
}
// Servers may omit media from receipts, so prefer the submission identity.
if client_id.is_some() && self.last_rendered_user_message_client_id.as_deref() == client_id
{
return;
}
if self
.input_queue
.pending_steers
@@ -1369,6 +1380,9 @@ impl ChatWidget {
let pending_display =
user_message_display_for_history(pending.user_message, &pending.history_record);
self.on_user_message_display(pending_display);
// Later receipts carry the wire media, which may differ from the local attachment.
self.last_rendered_user_message_display = Some(display);
self.last_rendered_user_message_client_id = Some(pending.client_id);
} else if self.last_rendered_user_message_display.as_ref() != Some(&display) {
tracing::warn!(
"pending steer matched receipt but queue was empty when rendering committed user message"
@@ -1385,6 +1399,7 @@ impl ChatWidget {
fn on_user_message_display(&mut self, display: UserMessageDisplay) {
self.transcript.last_status_copy_targets = None;
self.last_rendered_user_message_display = Some(display.clone());
self.last_rendered_user_message_client_id = None;
if !display.message.trim().is_empty()
|| !display.text_elements.is_empty()
|| !display.local_images.is_empty()
@@ -1799,6 +1814,7 @@ impl ChatWidget {
}
pub(crate) fn show_external_writer_thread(&mut self) {
self.cancel_image_submission();
self.blocks_direct_input = true;
self.external_writer_view = true;
self.pause_unavailable_thread();