@@ -805,6 +805,19 @@ export async function dispatchPreparedSlackMessage(prepared: PreparedSlackMessag
805805 }
806806 } ;
807807 const deliveryTracker = createSlackEventDeliveryTracker ( ) ;
808+ const markPreviewPayloadDelivered = ( params : {
809+ kind : ReplyDispatchKind ;
810+ payload : ReplyPayload ;
811+ threadTs : string | undefined ;
812+ } ) => {
813+ deliveryTracker . markDelivered ( params ) ;
814+ // Single-use reply modes move later same-turn payloads off the preview
815+ // thread, so protect both delivery keys from duplicates.
816+ const nextThreadTs = replyPlan . peekThreadTs ( ) ;
817+ if ( nextThreadTs !== params . threadTs ) {
818+ deliveryTracker . markDelivered ( { ...params , threadTs : nextThreadTs } ) ;
819+ }
820+ } ;
808821 const resolveDeliveryThreadTs = ( params : {
809822 kind : ReplyDispatchKind ;
810823 forcedThreadTs ?: string ;
@@ -908,7 +921,7 @@ export async function dispatchPreparedSlackMessage(prepared: PreparedSlackMessag
908921 payload : ReplyPayload ;
909922 kind : ReplyDispatchKind ;
910923 forcedThreadTs ?: string ;
911- } ) : Promise < void > => {
924+ } ) : Promise < string | undefined > => {
912925 if ( params . payload . isReasoning === true ) {
913926 return ;
914927 }
@@ -925,7 +938,7 @@ export async function dispatchPreparedSlackMessage(prepared: PreparedSlackMessag
925938 } )
926939 ) {
927940 logVerbose ( "slack: suppressed duplicate normal delivery within the same turn" ) ;
928- return ;
941+ return deliveryReplyThreadTs ;
929942 }
930943 await deliverReplies ( {
931944 cfg : ctx . cfg ,
@@ -958,6 +971,7 @@ export async function dispatchPreparedSlackMessage(prepared: PreparedSlackMessag
958971 payload : params . payload ,
959972 threadTs : deliveryReplyThreadTs ,
960973 } ) ;
974+ return deliveryReplyThreadTs ;
961975 } ;
962976
963977 const deliverBufferedStreamFallback = async ( params : {
@@ -1311,7 +1325,7 @@ export async function dispatchPreparedSlackMessage(prepared: PreparedSlackMessag
13111325 kind : info . kind ,
13121326 forcedThreadTs : finalThreadTs ,
13131327 } ) ;
1314- deliveryTracker . markDelivered ( { kind : info . kind , payload, threadTs : finalThreadTs } ) ;
1328+ markPreviewPayloadDelivered ( { kind : info . kind , payload, threadTs : finalThreadTs } ) ;
13151329 return ;
13161330 }
13171331 }
@@ -1363,14 +1377,16 @@ export async function dispatchPreparedSlackMessage(prepared: PreparedSlackMessag
13631377 ...( edit . blocks ?. length ? { blocks : edit . blocks } : { } ) ,
13641378 threadTs : edit . threadTs ,
13651379 } ) ;
1366- emitSlackMessageSentHooks ( {
1367- ...messageSentHookContext ,
1368- to : messageSentHookTarget ,
1369- accountId : account . accountId ,
1370- content : trimmedFinalText ,
1371- success : true ,
1372- messageId : preview . messageId ,
1373- } ) ;
1380+ if ( ! ttsSupplement ) {
1381+ emitSlackMessageSentHooks ( {
1382+ ...messageSentHookContext ,
1383+ to : messageSentHookTarget ,
1384+ accountId : account . accountId ,
1385+ content : trimmedFinalText ,
1386+ success : true ,
1387+ messageId : preview . messageId ,
1388+ } ) ;
1389+ }
13741390 draftPreviewCommitted = true ;
13751391 observedFinalReplyDelivery = true ;
13761392 } ,
@@ -1382,14 +1398,25 @@ export async function dispatchPreparedSlackMessage(prepared: PreparedSlackMessag
13821398 const finalThreadTs = usedReplyThreadTs ?? statusThreadTs ;
13831399 observedReplyDelivery = true ;
13841400 replyPlan . markSent ( ) ;
1385- deliveryTracker . markDelivered ( { kind : info . kind , payload, threadTs : finalThreadTs } ) ;
1401+ // Supplemental TTS media is the terminal delivery for the logical
1402+ // payload. Marking the preview first would suppress that media send.
1403+ if ( ! ttsSupplement ) {
1404+ markPreviewPayloadDelivered ( { kind : info . kind , payload, threadTs : finalThreadTs } ) ;
1405+ }
13861406 } ,
13871407 buildSupplementalPayload : ( ) =>
13881408 ttsSupplement ? buildTtsSupplementMediaPayload ( payload ) : undefined ,
13891409 deliverSupplemental : async ( supplementalPayload ) => {
1390- await deliverNormally ( {
1410+ const previewThreadTs = usedReplyThreadTs ?? statusThreadTs ;
1411+ const supplementalThreadTs = await deliverNormally ( {
13911412 payload : supplementalPayload ,
13921413 kind : info . kind ,
1414+ forcedThreadTs : previewThreadTs ,
1415+ } ) ;
1416+ markPreviewPayloadDelivered ( {
1417+ kind : info . kind ,
1418+ payload,
1419+ threadTs : supplementalThreadTs ,
13931420 } ) ;
13941421 } ,
13951422 logPreviewEditFailure : ( err ) => {
0 commit comments