@@ -796,7 +796,7 @@ export const layer = Layer.effect(
796796 if ( trigger !== "scheduled" ) {
797797 return yield * taskError ( "Schedule task is already running." , { taskId : task . id } ) ;
798798 }
799- return { task, threadId : null } ;
799+ return { task, threadId : null , dispatchFailed : false } ;
800800 }
801801
802802 return yield * Effect . gen ( function * ( ) {
@@ -811,15 +811,19 @@ export const layer = Layer.effect(
811811 if ( trigger !== "scheduled" ) {
812812 return yield * taskError ( "Schedule task not found." , { taskId : task . id } ) ;
813813 }
814- return { task, threadId : null } ;
814+ return { task, threadId : null , dispatchFailed : false } ;
815815 }
816816 if (
817817 webhook !== undefined &&
818818 ( yield * sql `SELECT 1 FROM scheduled_task_webhook_pending WHERE delivery_id = ${ webhook . deliveryId } AND state = 'completed'` . pipe (
819819 NodeSqliteClient . readOnly ,
820820 ) ) . length > 0
821821 )
822- return { task : { ...active , lastRunStatus : "succeeded" as const } , threadId : null } ;
822+ return {
823+ task : { ...active , lastRunStatus : "succeeded" as const } ,
824+ threadId : null ,
825+ dispatchFailed : false ,
826+ } ;
823827 const parsedNextRunAt =
824828 active . nextRunAt === null ? Option . none ( ) : DateTime . make ( active . nextRunAt ) ;
825829 if (
@@ -828,7 +832,7 @@ export const layer = Layer.effect(
828832 Option . isNone ( parsedNextRunAt ) ||
829833 DateTime . toEpochMillis ( parsedNextRunAt . value ) > DateTime . toEpochMillis ( startedAt ) )
830834 ) {
831- return { task : active , threadId : null } ;
835+ return { task : active , threadId : null , dispatchFailed : false } ;
832836 }
833837 // Reject queued deliveries after pause, same-id recreation or trigger changes.
834838 if ( webhook !== undefined ) {
@@ -1008,7 +1012,8 @@ export const layer = Layer.effect(
10081012 ) ,
10091013 ) ;
10101014 if ( written ) yield * notifyChanged ;
1011- return { task : recorded , threadId } ;
1015+ // The stored row can belong to a replacement, so report this dispatch separately.
1016+ return { task : recorded , threadId, dispatchFailed : ! runSucceeded } ;
10121017 } ) . pipe (
10131018 Effect . onError ( ( cause ) =>
10141019 releaseStuckRun ( task , startedAtIso , errorMessage ( cause ) , webhook ?. deliveryId ) ,
@@ -1751,8 +1756,8 @@ export const layer = Layer.effect(
17511756 ] ) ;
17521757 const dispatched = yield * Ref . make ( false ) ;
17531758 return yield * runTask ( task , "webhook" , { deliveryId, prompt, dispatched } ) . pipe (
1754- Effect . flatMap ( ( { task : completed } ) =>
1755- completed . lastRunStatus === "failed"
1759+ Effect . flatMap ( ( { dispatchFailed } ) =>
1760+ dispatchFailed
17561761 ? runOutcome ( "failed" ) . pipe (
17571762 Effect . andThen ( markDeliveryFailed ( deliveryId , "The run failed to start." ) ) ,
17581763 Effect . andThen ( releaseFailedDelivery ( deliveryId ) ) ,
0 commit comments