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

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

    let env = context.env.merging(job.extraEnvironment, uniquingKeysWith: { $1 })

    let value: DriverBuildValue
    var pendingFinish = false
    var pid = 0
    do {
      let arguments: [String] = try resolver.resolveArgumentList(for: job,
