       }
       // Only inform finished job if the job has been started, otherwise the build
       // system may complain about malformed output
-      if (knownPId.contains(pid)) {
+      if (pendingFinish) {
         context.delegateQueue.sync {
           let result = ProcessResult(
             arguments: [],

      context.delegateQueue.sync {
        context.executorDelegate.jobFinished(job: job, result: result, pid: pid)
      }
      context.cancelBuildIfNeeded(result)
      if !context.isBuildCancelled {
        try context.addRuleBeyondMandatoryCompiles(finishedJob: job, result: result)

      // Inform the delegate.
      context.delegateQueue.sync {
        context.executorDelegate.jobStarted(job: job, arguments: arguments, pid: pid)
      }
      pendingFinish = true

      let result = try process.waitUntilExit()
      let success = result.exitStatus == .terminated(code: EXIT_SUCCESS)
