@@ -53,9 +53,13 @@ export async function deliverLineAutoReply(params: {
5353 cfg : OpenClawConfig ;
5454 textLimit : number ;
5555 deps : LineAutoReplyDeps ;
56- } ) : Promise < { replyTokenUsed : boolean } > {
56+ } ) : Promise < { replyTokenUsed : boolean ; visiblePartialDeliveryError ?: Error } > {
5757 const { payload, lineData, replyToken, accountId, to, textLimit, deps } = params ;
5858 let replyTokenUsed = params . replyTokenUsed ;
59+ // Set when the text reached the user but a rich/media bubble did not. Returned
60+ // (not thrown) so the caller adopts the consumed reply-token state before it
61+ // surfaces the failure.
62+ let visiblePartialDeliveryError : Error | undefined ;
5963
6064 const pushLineMessages = async ( messages : messagingApi . Message [ ] ) : Promise < void > => {
6165 if ( messages . length === 0 ) {
@@ -141,11 +145,17 @@ export async function deliverLineAutoReply(params: {
141145
142146 if ( chunks . length > 0 ) {
143147 const hasRichOrMedia = richMessages . length > 0 || mediaMessages . length > 0 ;
144- if ( hasQuickReplies && hasRichOrMedia ) {
148+ // Quick replies attach to the trailing message, so when both are present the
149+ // rich/media bubbles must go out before the quick-reply text. Capture a
150+ // failure instead of swallowing it: the text still sends below, but a lost
151+ // rich/media bubble must surface as a partial delivery, not silent success.
152+ const sendRichBeforeText = hasQuickReplies && hasRichOrMedia ;
153+ let richMediaError : unknown ;
154+ if ( sendRichBeforeText ) {
145155 try {
146156 await sendLineMessages ( [ ...richMessages , ...mediaMessages ] , false ) ;
147157 } catch ( err ) {
148- deps . onReplyError ?. ( err ) ;
158+ richMediaError = err ;
149159 }
150160 }
151161 const { replyTokenUsed : nextReplyTokenUsed } = await deps . sendLineReplyChunks ( {
@@ -162,12 +172,27 @@ export async function deliverLineAutoReply(params: {
162172 createTextMessageWithQuickReplies : deps . createTextMessageWithQuickReplies ,
163173 } ) ;
164174 replyTokenUsed = nextReplyTokenUsed ;
165- if ( ! hasQuickReplies || ! hasRichOrMedia ) {
166- await sendLineMessages ( richMessages , false ) ;
167- if ( mediaMessages . length > 0 ) {
168- await sendLineMessages ( mediaMessages , false ) ;
175+ if ( ! sendRichBeforeText ) {
176+ try {
177+ await sendLineMessages ( richMessages , false ) ;
178+ if ( mediaMessages . length > 0 ) {
179+ await sendLineMessages ( mediaMessages , false ) ;
180+ }
181+ } catch ( err ) {
182+ richMediaError = err ;
169183 }
170184 }
185+ if ( richMediaError !== undefined ) {
186+ // Tag the failure as a visible partial delivery so the caller reports it
187+ // instead of silent success; visibleReplySent marks the text as visibly
188+ // delivered so the foreground fallback/freshness path does not re-send it
189+ // (see isVisiblePartialDeliveryError in src/auto-reply/dispatch.ts).
190+ const partialError =
191+ richMediaError instanceof Error
192+ ? richMediaError
193+ : new Error ( "LINE rich or media message send failed" , { cause : richMediaError } ) ;
194+ visiblePartialDeliveryError = Object . assign ( partialError , { visibleReplySent : true } ) ;
195+ }
171196 } else {
172197 const combined = [ ...richMessages , ...mediaMessages ] ;
173198 if ( hasQuickReplies && combined . length === 0 ) {
@@ -200,5 +225,8 @@ export async function deliverLineAutoReply(params: {
200225 }
201226 }
202227
203- return { replyTokenUsed } ;
228+ return {
229+ replyTokenUsed,
230+ ...( visiblePartialDeliveryError ? { visiblePartialDeliveryError } : { } ) ,
231+ } ;
204232}
0 commit comments