Fixed the bug in validating duplicated task ID and added a test.

Review: https://reviews.apache.org/r/27903