@@ -7911,12 +7911,13 @@ export default function ChatView(props: ChatViewProps) {
79117911 setThreadError ,
79127912 ] ,
79137913 ) ;
7914- const onCompactContext = async ( ) => {
7914+ // Resolves true once the /compact turn is accepted.
7915+ const onCompactContext = async ( ) : Promise < boolean > => {
79157916 if ( compactDisabled || ! activeThread || ! clientSettingsHydrated || sendInFlightRef . current ) {
7916- return ;
7917+ return false ;
79177918 }
79187919 const context = composerRef . current ?. getSendContext ( ) ;
7919- if ( ! context ?. providerAvailable ) return ;
7920+ if ( ! context ?. providerAvailable ) return false ;
79207921
79217922 // Compaction is a standalone command; the draft and its attachments stay local.
79227923 const threadId = activeThread . id ;
@@ -7974,9 +7975,10 @@ export default function ChatView(props: ChatViewProps) {
79747975 error instanceof Error ? error . message : "Failed to compact context." ,
79757976 ) ;
79767977 }
7977- } else {
7978- clearUsageLimitsFor ( routeThreadKey ) ;
7978+ return false ;
79797979 }
7980+ clearUsageLimitsFor ( routeThreadKey ) ;
7981+ return true ;
79807982 } finally {
79817983 sendInFlightRef . current = false ;
79827984 }
@@ -8586,7 +8588,16 @@ export default function ChatView(props: ChatViewProps) {
85868588 ) ;
85878589 const messageIdForSend = newMessageId ( ) ;
85888590 const messageCreatedAt = new Date ( ) . toISOString ( ) ;
8589- const shouldQueueBehindActiveRun = phase === "running" && dispatchMode === "queue" ;
8591+ // Sending past the resume banner compacts first so the turn does not resend the stale
8592+ // history. The message queues behind the /compact run; steering into it is rejected.
8593+ const compactBeforeSend =
8594+ resumeCompactionBannerItem !== null &&
8595+ ! compactDisabled &&
8596+ multipleModelSelections === null &&
8597+ messageTextForSend . toLowerCase ( ) !== "/compact" ;
8598+ const turnDispatchMode = compactBeforeSend ? "queue" : dispatchMode ;
8599+ const shouldQueueBehindActiveRun =
8600+ compactBeforeSend || ( phase === "running" && dispatchMode === "queue" ) ;
85908601 const outgoingMessageText = formatOutgoingPrompt ( {
85918602 provider : ctxSelectedProvider ,
85928603 model : ctxSelectedModel ,
@@ -8659,6 +8670,7 @@ export default function ChatView(props: ChatViewProps) {
86598670 } ) ;
86608671 }
86618672
8673+ if ( compactBeforeSend && ! ( await onCompactContext ( ) ) ) return ;
86628674 sendInFlightRef . current = true ;
86638675 const sendGeneration = ++ composerSendGenerationRef . current ;
86648676 const attachmentCapabilitiesBeforeUpload = readLiveAttachmentCapabilities ( ) ;
@@ -9227,7 +9239,7 @@ export default function ChatView(props: ChatViewProps) {
92279239 titleSeed : title ,
92289240 runtimeMode,
92299241 interactionMode : sendInteractionMode ,
9230- dispatchMode,
9242+ dispatchMode : turnDispatchMode ,
92319243 ...( bootstrap ? { bootstrap } : { } ) ,
92329244 createdAt : messageCreatedAt ,
92339245 } ,
0 commit comments