@@ -803,6 +803,7 @@ describe('cancelWorkflowExecution', () => {
803803 mockMarkExecutionCancelled
804804 . mockResolvedValueOnce ( { durablyRecorded : false , reason : 'redis_unavailable' } )
805805 . mockResolvedValueOnce ( { durablyRecorded : true , reason : 'recorded' } )
806+ . mockResolvedValueOnce ( { durablyRecorded : true , reason : 'recorded' } )
806807 mockCompletePausedCancellation . mockResolvedValueOnce ( true )
807808
808809 const response = await POST ( makeRequest ( ) , makeParams ( ) )
@@ -822,7 +823,10 @@ describe('cancelWorkflowExecution', () => {
822823 expect ( mockMarkExecutionCancelled ) . toHaveBeenNthCalledWith ( 1 , 'resume-ex-1' , {
823824 executionDeadlineAt : null ,
824825 } )
825- expect ( mockMarkExecutionCancelled ) . toHaveBeenNthCalledWith ( 2 , 'resume-ex-2' , {
826+ expect ( mockMarkExecutionCancelled ) . toHaveBeenNthCalledWith ( 2 , 'resume-ex-1' , {
827+ executionDeadlineAt : null ,
828+ } )
829+ expect ( mockMarkExecutionCancelled ) . toHaveBeenNthCalledWith ( 3 , 'resume-ex-2' , {
826830 executionDeadlineAt : null ,
827831 } )
828832 expect ( mockCompletePausedCancellation ) . toHaveBeenCalledWith ( 'ex-1' , 'wf-1' )
@@ -842,6 +846,7 @@ describe('cancelWorkflowExecution', () => {
842846 . mockResolvedValueOnce ( { durablyRecorded : false , reason : 'redis_unavailable' } )
843847 . mockResolvedValueOnce ( { durablyRecorded : false , reason : 'redis_unavailable' } )
844848 . mockResolvedValueOnce ( { durablyRecorded : true , reason : 'recorded' } )
849+ . mockResolvedValueOnce ( { durablyRecorded : true , reason : 'recorded' } )
845850 mockCompletePausedCancellation . mockResolvedValueOnce ( true )
846851
847852 const response = await POST ( makeRequest ( ) , makeParams ( ) )
@@ -864,12 +869,53 @@ describe('cancelWorkflowExecution', () => {
864869 expect ( mockMarkExecutionCancelled ) . toHaveBeenNthCalledWith ( 2 , 'resume-ex-1' , {
865870 executionDeadlineAt : null ,
866871 } )
867- expect ( mockMarkExecutionCancelled ) . toHaveBeenNthCalledWith ( 3 , 'resume-ex-2' , {
872+ expect ( mockMarkExecutionCancelled ) . toHaveBeenNthCalledWith ( 3 , 'resume-ex-1' , {
873+ executionDeadlineAt : null ,
874+ } )
875+ expect ( mockMarkExecutionCancelled ) . toHaveBeenNthCalledWith ( 4 , 'resume-ex-2' , {
868876 executionDeadlineAt : null ,
869877 } )
870878 expect ( mockCompletePausedCancellation ) . toHaveBeenCalledWith ( 'ex-1' , 'wf-1' )
871879 } )
872880
881+ it ( 'does not treat replacement queue cancellation as confirmation of the original stop' , async ( ) => {
882+ mockStagePausedCancellation
883+ . mockResolvedValueOnce ( { kind : 'active_resume' , target : ACTIVE_RESUME_TARGET } )
884+ . mockResolvedValueOnce ( {
885+ kind : 'active_resume' ,
886+ target : REPLACEMENT_ACTIVE_RESUME_TARGET ,
887+ } )
888+ mockGetActiveResumeCancellationTarget
889+ . mockResolvedValueOnce ( REPLACEMENT_ACTIVE_RESUME_TARGET )
890+ . mockResolvedValueOnce ( REPLACEMENT_ACTIVE_RESUME_TARGET )
891+ mockRollbackActiveResumeCancellation . mockResolvedValueOnce ( false )
892+ mockCancelByExecution . mockResolvedValue ( 1 )
893+ mockMarkExecutionCancelled
894+ . mockResolvedValueOnce ( { durablyRecorded : false , reason : 'redis_unavailable' } )
895+ . mockResolvedValueOnce ( { durablyRecorded : false , reason : 'redis_unavailable' } )
896+ . mockResolvedValueOnce ( { durablyRecorded : true , reason : 'recorded' } )
897+
898+ const response = await POST ( makeRequest ( ) , makeParams ( ) )
899+
900+ expect ( response . status ) . toBe ( 200 )
901+ await expect ( response . json ( ) ) . resolves . toMatchObject ( {
902+ success : false ,
903+ pausedCancelled : false ,
904+ reason : 'active_resume_signal_failed' ,
905+ } )
906+ expect ( mockMarkExecutionCancelled ) . toHaveBeenNthCalledWith ( 1 , 'resume-ex-1' , {
907+ executionDeadlineAt : null ,
908+ } )
909+ expect ( mockMarkExecutionCancelled ) . toHaveBeenNthCalledWith ( 2 , 'resume-ex-1' , {
910+ executionDeadlineAt : null ,
911+ } )
912+ expect ( mockMarkExecutionCancelled ) . toHaveBeenNthCalledWith ( 3 , 'resume-ex-2' , {
913+ executionDeadlineAt : null ,
914+ } )
915+ expect ( mockWriteTerminalEvent ) . not . toHaveBeenCalled ( )
916+ expect ( mockCompletePausedCancellation ) . not . toHaveBeenCalled ( )
917+ } )
918+
873919 it ( 'returns success when a paused HITL execution is cancelled directly in the database' , async ( ) => {
874920 mockStagePausedCancellation . mockResolvedValue ( { kind : 'idle' } )
875921 mockCompletePausedCancellation . mockResolvedValue ( true )
0 commit comments