@@ -395,19 +395,19 @@ export function startChatDispatch(params: StartChatDispatchParams): void {
395395 await measureDiagnosticsTimelineSpan (
396396 "gateway.chat_send.post_dispatch" ,
397397 async ( ) => {
398- const returnedAgentErrorPayloads = agentRunStarted
399- ? replyDispatch . deliveredReplies
400- . map ( ( entryInner ) => entryInner . payload )
401- . filter ( ( payload ) => payload . isError )
402- : [ ] ;
398+ const returnedAgentErrorPayloads = replyDispatch . deliveredReplies
399+ . map ( ( entryInner ) => entryInner . payload )
400+ . filter ( ( payload ) => payload . isError ) ;
401+ const hasReturnedAgentError =
402+ returnedAgentErrorPayloads . length > 0 &&
403+ ( agentRunStarted || ! isInternalTextSlashCommandTurn ) ;
403404 const returnedAgentErrorMessage =
404405 returnedAgentErrorPayloads
405406 . map ( ( payload ) => payload . text ?. trim ( ) )
406407 . filter ( ( text ) : text is string => Boolean ( text ) )
407408 . join ( " | " ) || undefined ;
408409 if (
409- agentRunStarted &&
410- returnedAgentErrorPayloads . length > 0 &&
410+ hasReturnedAgentError &&
411411 ! userTurnRecorder . hasPersisted ( ) &&
412412 ! userTurnRecorder . isBlocked ( )
413413 ) {
@@ -426,7 +426,7 @@ export function startChatDispatch(params: StartChatDispatchParams): void {
426426 // Agent runs persist model-visible turns through SessionManager; this dispatcher owns
427427 // live delivery. Mirroring agent finals would duplicate normal assistant turns. The
428428 // non-agent branch has no runtime-owned turn, so it appends one before broadcasting.
429- if ( ! agentRunStarted && ! queuedFollowup . isEnqueued ( ) ) {
429+ if ( ! agentRunStarted && ! queuedFollowup . isEnqueued ( ) && ! hasReturnedAgentError ) {
430430 await finalizeChatSendNonAgentReplies ( {
431431 accountId,
432432 context,
@@ -443,12 +443,11 @@ export function startChatDispatch(params: StartChatDispatchParams): void {
443443 context,
444444 deliveredReplies : replyDispatch . deliveredReplies ,
445445 emitFirstAssistantServerTiming,
446- hasReturnedAgentErrorPayloads : returnedAgentErrorPayloads . length > 0 ,
446+ hasReturnedAgentErrorPayloads : hasReturnedAgentError ,
447447 session,
448448 } ) ;
449449 }
450- const shouldBroadcastAgentError =
451- returnedAgentErrorPayloads . length > 0 && ! broadcastedSourceReplyFinal ;
450+ const shouldBroadcastAgentError = hasReturnedAgentError && ! broadcastedSourceReplyFinal ;
452451 if ( shouldBroadcastAgentError ) {
453452 broadcastChatError ( {
454453 context,
0 commit comments