@@ -835,7 +835,8 @@ export function useComposerSend(input: ComposerSendInput) {
835835 composerFilesSnapshot . length > 0
836836 ? attachmentCapabilitiesBeforeUpload . supportsAttachmentUploads
837837 : ( readEnvironmentPresentation ( environmentId ) ?. serverConfig ?? null ) !== null ;
838- if ( turnUsesAttachmentUploads && composerAttachmentsSnapshot . length > 0 ) {
838+ // Uploads finish after the message shows as sending; the turn starts once they land.
839+ if ( turnUsesAttachmentUploads ) {
839840 for ( const attachment of composerAttachmentsSnapshot ) {
840841 const upload =
841842 readAttachmentUpload ( attachment . id ) ?. status === "failed"
@@ -847,18 +848,6 @@ export function useComposerSend(input: ComposerSendInput) {
847848 draftTarget : composerDraftTarget ,
848849 } ) ;
849850 }
850- await awaitAttachmentUploads ( composerAttachmentsSnapshot . map ( ( attachment ) => attachment . id ) ) ;
851- const attachmentCapabilitiesAfterUpload = readLiveAttachmentCapabilities ( ) ;
852- if ( attachmentCapabilitiesAfterUpload . fileBlockReason !== null ) {
853- sendInFlightRef . current = false ;
854- setThreadError ( threadIdForSend , attachmentCapabilitiesAfterUpload . fileBlockReason ) ;
855- return ;
856- }
857- if ( getUploadedAttachments ( { environmentId, images : composerAttachmentsSnapshot } ) === null ) {
858- sendInFlightRef . current = false ;
859- setThreadError ( threadIdForSend , "Retry or remove failed uploads before sending." ) ;
860- return ;
861- }
862851 }
863852
864853 if (
@@ -903,6 +892,27 @@ export function useComposerSend(input: ComposerSendInput) {
903892 ) ;
904893 return ;
905894 }
895+ // Declining is irreversible, so a redirect waits for its uploads instead of failing after.
896+ if (
897+ turnUsesAttachmentUploads &&
898+ composerAttachmentsSnapshot . length > 0 &&
899+ ( sendCtx ?. shownPendingApprovalIds . length ?? 0 ) > 0
900+ ) {
901+ await awaitAttachmentUploads ( composerAttachmentsSnapshot . map ( ( attachment ) => attachment . id ) ) ;
902+ const uploadBlockReason =
903+ readLiveAttachmentCapabilities ( ) . fileBlockReason ??
904+ ( getUploadedAttachments ( { environmentId, images : composerAttachmentsSnapshot } ) === null
905+ ? "Retry or remove failed uploads before sending."
906+ : null ) ;
907+ if ( uploadBlockReason !== null ) {
908+ sendInFlightRef . current = false ;
909+ setThreadError ( threadIdForSend , uploadBlockReason ) ;
910+ setDockedDraftHeroThreadKey ( ( currentThreadKey ) =>
911+ currentThreadKey === activeThreadKey ? null : currentThreadKey ,
912+ ) ;
913+ return ;
914+ }
915+ }
906916 // A message sent while approvals are pending redirects the agent. They are declined only
907917 // here, after everything above has accepted the send, so local commands and rejected
908918 // drafts leave them alone. After navigating away during an upload, the shown approvals
0 commit comments