Waiting for all batches within a parent batch not working

I’m currently working on a schema as follows:

  • create a batchjob and start a single background job
  • this job reads a file and creates multiple additional batches, attaching to that original parent batch
  • these child batches run a succession of backgroundjobs

Now, the problem I’ve having is waiting for everything to finish to run a final cleanup process. I await the parent batch, but it runs the final job before the child batches finish.

 var importJobId = BatchJob.StartNew(action => action.Enqueue<IBeginImportJob>(x => x.Start(import.Id, bucketName, key, null, JobCancellationToken.Null, action.BatchId)), $"Import Id {import.Id} of {import.Name}");

Inside of there (simplified) I have 

BatchJob.Attach(parentBatchId, parentBatch =>
        {
              --read file in a while loop
                    parentBatch.StartNew(workBatchAction =>
        {
            var checkBrandId = workBatchAction.Enqueue<ICheckBrandJob>(e => e.Start(id, JobCancellationToken.Null, null));
            workBatchAction.ContinueWith<ICheckPartJob>(checkBrandId, job => job.Start(id, JobCancellationToken.Null, null));
        }, $"Import Id {import.Id} - batch {batchNumber}");  
}

  BatchJob.AwaitBatch(parentBatchId,
                fullBatchAction =>
                {
                    BatchJob.Attach(parentBatchId,
                        action => action.Enqueue<ICompleteImportJob>(job => job.StartTest()));
                },"Complete the import");

But what’s happening is that last awaitbatch doesn’t wait for everything in the child batches to finish. Or at least that’s what it seems.