@@ -139,7 +139,7 @@ export function createDiscordMessageDispatcher(
139139 }
140140 const abortSignal = last . abortSignal ;
141141 if ( abortSignal ?. aborted ) {
142- await admissionLifecycle . onAbandoned ( ) ;
142+ await ingress . lifecycle ?. onCancelled ?. ( ) ;
143143 return ;
144144 }
145145 try {
@@ -157,7 +157,7 @@ export function createDiscordMessageDispatcher(
157157 turnAdoptionLifecycle : admissionLifecycle ,
158158 } ) ;
159159 if ( abortSignal ?. aborted ) {
160- await ingress . abandon ( abortSignal . reason ) ;
160+ await ingress . lifecycle ?. onCancelled ?. ( ) ;
161161 return ;
162162 }
163163 if ( ! ctx ) {
@@ -211,7 +211,7 @@ export function createDiscordMessageDispatcher(
211211 turnAdoptionLifecycle : admissionLifecycle ,
212212 } ) ;
213213 if ( abortSignal ?. aborted ) {
214- await ingress . abandon ( abortSignal . reason ) ;
214+ await ingress . lifecycle ?. onCancelled ?. ( ) ;
215215 return ;
216216 }
217217 if ( ! ctx ) {
@@ -232,7 +232,10 @@ export function createDiscordMessageDispatcher(
232232 }
233233 messageRunQueue . enqueue ( buildDiscordInboundJob ( ctx , { ingressSettlement : ingress } ) ) ;
234234 } catch ( error ) {
235- await admissionLifecycle . onAbandoned ( ) ;
235+ if ( abortSignal ?. aborted ) {
236+ await ingress . lifecycle ?. onCancelled ?.( ) ;
237+ return ;
238+ }
236239 throw error ;
237240 }
238241 } ,
@@ -244,7 +247,7 @@ export function createDiscordMessageDispatcher(
244247 onCancel : ( entries ) => {
245248 for ( const entry of entries ) {
246249 pendingDebounceEntries . delete ( entry ) ;
247- const settlement = Promise . resolve ( entry . turnAdoptionLifecycle ?. onAbandoned ( ) )
250+ const settlement = Promise . resolve ( entry . turnAdoptionLifecycle ?. onCancelled ?. ( ) )
248251 . catch ( ( error : unknown ) => {
249252 params . runtime . error (
250253 danger ( `discord ingress cancellation settlement failed: ${ String ( error ) } ` ) ,
@@ -271,6 +274,10 @@ export function createDiscordMessageDispatcher(
271274 const reason = dispatcherShutdown . signal . aborted
272275 ? ( dispatcherShutdown . signal . reason ?? new Error ( "discord dispatcher shut down" ) )
273276 : ( options ?. abortSignal ?. reason ?? new Error ( "discord dispatch aborted" ) ) ;
277+ if ( options ?. turnAdoptionLifecycle ?. onCancelled ) {
278+ await options . turnAdoptionLifecycle . onCancelled ( ) ;
279+ return { kind : "deferred" } ;
280+ }
274281 return { kind : "failed-retryable" , error : reason } ;
275282 }
276283 // Filter bot-own messages before they enter the debounce queue.
0 commit comments