So I got the following scenario and my attempt gives a wrong result.
Would appreciate a helping hand here:
Here's a file with the data for test, should you feel like jumping in...
There is a more straightforward approach. Delete everything (including the header) from Col B, then place the following in B1:
=ArrayFormula({"Task Nº"; IF(A2:A="",,COUNTIFS(A2:A,A2:A,ROW(A2:A),"<="&ROW(A2:A)))})