fix: recompute package snapshot when missing from cache #95

Merged
pat-s merged 1 commit from fix/recompute-missing-package-snapshot into main 2026-06-17 17:49:05 +00:00

View file

@ -15,6 +15,31 @@ library(bincraft, quietly = TRUE)
library(future) library(future)
plan("sequential") plan("sequential")
# The install-deps step precomputes the package snapshot into /mnt/cache, but
# that volume is per-agent: a job landing on a fresh agent (or racing
# install-deps) finds it empty. Recompute the snapshot here when any part is
# missing, so the first job on an agent repopulates the cache for the jobs that
# follow; concurrent jobs that also miss simply redo the work. Write via a
# temp file + atomic rename so a concurrent reader never sees a half-written rds.
package_cache_files <- c(
"/mnt/cache/packages/pkgs_to_build.rds",
"/mnt/cache/packages/r_minor_sensitive_pkgs.rds",
"/mnt/cache/packages/s3_cache.rds"
)
if (!all(file.exists(package_cache_files))) {
message("Package snapshot missing from cache; recomputing via packages-to-build.R")
dir.create("/mnt/cache/packages", showWarnings = FALSE, recursive = TRUE)
save_rds_atomic <- function(obj, path) {
tmp <- paste0(path, ".tmp.", Sys.getpid())
saveRDS(obj, tmp)
file.rename(tmp, path)
}
source(file.path("local", "packages-to-build.R"))
save_rds_atomic(pkgs, "/mnt/cache/packages/pkgs_to_build.rds")
save_rds_atomic(pkgs[r_minor_sensitive == TRUE], "/mnt/cache/packages/r_minor_sensitive_pkgs.rds")
message("Package snapshot recomputed.")
}
pkgs <- if (sensitive_only) { pkgs <- if (sensitive_only) {
readRDS("/mnt/cache/packages/r_minor_sensitive_pkgs.rds") readRDS("/mnt/cache/packages/r_minor_sensitive_pkgs.rds")
} else { } else {