From 26ac9887179df9cce34828300972582068721e8e Mon Sep 17 00:00:00 2001 From: pat-s Date: Wed, 17 Jun 2026 19:47:28 +0200 Subject: [PATCH] fix: recompute package snapshot when missing from cache The install-deps step precomputes pkgs_to_build.rds, r_minor_sensitive_pkgs.rds and s3_cache.rds into /mnt/cache, but that cache volume is per-agent. A build job scheduled on a fresh agent (or racing install-deps) finds the snapshot absent and fails at readRDS. Guard the reads in build-all.R: when any snapshot file is missing, source packages-to-build.R and save the derived files (atomic temp+rename so a concurrent job never reads a half-written rds). The first job on an agent repopulates the shared cache for subsequent jobs; jobs that also miss redo the work. --- local/build-all.R | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/local/build-all.R b/local/build-all.R index 8ce1cd5..f8e8efd 100644 --- a/local/build-all.R +++ b/local/build-all.R @@ -15,6 +15,31 @@ library(bincraft, quietly = TRUE) library(future) 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) { readRDS("/mnt/cache/packages/r_minor_sensitive_pkgs.rds") } else { -- 2.54.0