If hydra-eval-jobs creates a new root, and hydra-update-gc-roots runs before hydra-evaluator has had a chance to add the corresponding build to the database, then hydra-update-gc-roots will remove the root. If subsequently the Nix garbage collector kicks in, it may remove the build's .drv file before the build is performed. Since evaluation of the Nixpkgs and NixOS jobsets nowadays takes a lot of time (e.g. an hour), the probability of this happening is fairly high.
The quick fix is not to delete roots that are less than a day old. So long as evaluation doesn't take longer than a day, this should be fine ;-)
Fixes #166.
3D3F5I744YILPYZYZQHGADFNYIM7RESDLSCDULH5WVIIPTYD5GYQC
print STDERR "removing root $path\n";
$rootsDeleted++;
unlink "$gcRootsDir/$link" or warn "cannot remove $gcRootsDir/$link";
# Don't delete roots that are less than a day old, to prevent
# a race where hydra-eval-jobs has added a root but
# hydra-evaluator hasn't added them to the database yet.
if (lstat($path)->ctime < $now - 24 * 60 * 60) {
print STDERR "removing root $path\n";
$rootsDeleted++;
unlink "$gcRootsDir/$link" or warn "cannot remove $gcRootsDir/$link";
} else {
print STDERR "NOT removing recent root $path\n";
$rootsKept++;
}