fix(abi): prune flat-slot binaries of ABI-risky packages (#200)
Some checks failed
ci/crow/manual/prune-stale-flat-binaries/17 Pipeline was successful
ci/crow/cron/process-updates/6 Pipeline was successful
ci/crow/manual/rebuild-abi-gap/15 Pipeline was successful
ci/crow/manual/rebuild-abi-gap/13 Pipeline was successful
ci/crow/manual/rebuild-abi-gap/7 Pipeline was successful
ci/crow/cron/process-updates/5 Pipeline was successful
ci/crow/manual/rebuild-abi-gap/9 Pipeline was successful
ci/crow/manual/rebuild-abi-gap/17 Pipeline was successful
ci/crow/manual/rebuild-abi-gap/18 Pipeline was successful
ci/crow/manual/rebuild-abi-gap/11 Pipeline was successful
ci/crow/manual/rebuild-abi-gap/16 Pipeline was successful
ci/crow/cron/process-updates/1 Pipeline was successful
ci/crow/manual/rebuild-abi-gap/3 Pipeline was successful
ci/crow/manual/rebuild-abi-gap/14 Pipeline was successful
ci/crow/manual/rebuild-abi-gap/5 Pipeline was successful
ci/crow/cron/process-updates/7 Pipeline was successful
ci/crow/manual/rebuild-abi-gap/8 Pipeline was successful
ci/crow/cron/process-updates/9 Pipeline was successful
ci/crow/manual/rebuild-abi-gap/10 Pipeline was successful
ci/crow/cron/process-updates/3 Pipeline was successful
ci/crow/manual/rebuild-abi-gap/12 Pipeline was successful
ci/crow/manual/reindex/7 Pipeline was successful
ci/crow/manual/reindex/17 Pipeline was successful
ci/crow/cron/process-updates/13 Pipeline was successful
ci/crow/manual/reindex/1 Pipeline was successful
ci/crow/manual/reindex/3 Pipeline was successful
ci/crow/manual/reindex/9 Pipeline was successful
ci/crow/manual/reindex/5 Pipeline was successful
ci/crow/manual/reindex/13 Pipeline was successful
ci/crow/manual/reindex/15 Pipeline was successful
ci/crow/manual/reindex/11 Pipeline was successful
ci/crow/manual/rebuild-abi-gap/4 Pipeline was successful
ci/crow/cron/process-updates/15 Pipeline was successful
ci/crow/cron/process-updates/2 Pipeline was successful
ci/crow/cron/process-updates/11 Pipeline was successful
ci/crow/cron/process-updates/8 Pipeline was successful
ci/crow/manual/rebuild-abi-gap/6 Pipeline was successful
ci/crow/cron/process-updates/17 Pipeline was successful
ci/crow/manual/reindex/2 Pipeline was successful
ci/crow/manual/reindex/4 Pipeline was successful
ci/crow/manual/reindex/8 Pipeline failed
ci/crow/manual/reindex/6 Pipeline was successful
ci/crow/manual/reindex/10 Pipeline was successful
ci/crow/manual/reindex/12 Pipeline was successful
ci/crow/manual/reindex/14 Pipeline was successful
ci/crow/manual/reindex/16 Pipeline was successful
ci/crow/manual/reindex/18 Pipeline was successful
ci/crow/cron/process-updates/10 Pipeline was successful
ci/crow/cron/process-updates/4 Pipeline was successful
ci/crow/cron/process-updates/16 Pipeline was successful
ci/crow/cron/process-updates/14 Pipeline was successful
ci/crow/cron/process-updates/12 Pipeline was successful
ci/crow/cron/process-updates/18 Pipeline was successful
Some checks failed
ci/crow/manual/prune-stale-flat-binaries/17 Pipeline was successful
ci/crow/cron/process-updates/6 Pipeline was successful
ci/crow/manual/rebuild-abi-gap/15 Pipeline was successful
ci/crow/manual/rebuild-abi-gap/13 Pipeline was successful
ci/crow/manual/rebuild-abi-gap/7 Pipeline was successful
ci/crow/cron/process-updates/5 Pipeline was successful
ci/crow/manual/rebuild-abi-gap/9 Pipeline was successful
ci/crow/manual/rebuild-abi-gap/17 Pipeline was successful
ci/crow/manual/rebuild-abi-gap/18 Pipeline was successful
ci/crow/manual/rebuild-abi-gap/11 Pipeline was successful
ci/crow/manual/rebuild-abi-gap/16 Pipeline was successful
ci/crow/cron/process-updates/1 Pipeline was successful
ci/crow/manual/rebuild-abi-gap/3 Pipeline was successful
ci/crow/manual/rebuild-abi-gap/14 Pipeline was successful
ci/crow/manual/rebuild-abi-gap/5 Pipeline was successful
ci/crow/cron/process-updates/7 Pipeline was successful
ci/crow/manual/rebuild-abi-gap/8 Pipeline was successful
ci/crow/cron/process-updates/9 Pipeline was successful
ci/crow/manual/rebuild-abi-gap/10 Pipeline was successful
ci/crow/cron/process-updates/3 Pipeline was successful
ci/crow/manual/rebuild-abi-gap/12 Pipeline was successful
ci/crow/manual/reindex/7 Pipeline was successful
ci/crow/manual/reindex/17 Pipeline was successful
ci/crow/cron/process-updates/13 Pipeline was successful
ci/crow/manual/reindex/1 Pipeline was successful
ci/crow/manual/reindex/3 Pipeline was successful
ci/crow/manual/reindex/9 Pipeline was successful
ci/crow/manual/reindex/5 Pipeline was successful
ci/crow/manual/reindex/13 Pipeline was successful
ci/crow/manual/reindex/15 Pipeline was successful
ci/crow/manual/reindex/11 Pipeline was successful
ci/crow/manual/rebuild-abi-gap/4 Pipeline was successful
ci/crow/cron/process-updates/15 Pipeline was successful
ci/crow/cron/process-updates/2 Pipeline was successful
ci/crow/cron/process-updates/11 Pipeline was successful
ci/crow/cron/process-updates/8 Pipeline was successful
ci/crow/manual/rebuild-abi-gap/6 Pipeline was successful
ci/crow/cron/process-updates/17 Pipeline was successful
ci/crow/manual/reindex/2 Pipeline was successful
ci/crow/manual/reindex/4 Pipeline was successful
ci/crow/manual/reindex/8 Pipeline failed
ci/crow/manual/reindex/6 Pipeline was successful
ci/crow/manual/reindex/10 Pipeline was successful
ci/crow/manual/reindex/12 Pipeline was successful
ci/crow/manual/reindex/14 Pipeline was successful
ci/crow/manual/reindex/16 Pipeline was successful
ci/crow/manual/reindex/18 Pipeline was successful
ci/crow/cron/process-updates/10 Pipeline was successful
ci/crow/cron/process-updates/4 Pipeline was successful
ci/crow/cron/process-updates/16 Pipeline was successful
ci/crow/cron/process-updates/14 Pipeline was successful
ci/crow/cron/process-updates/12 Pipeline was successful
ci/crow/cron/process-updates/18 Pipeline was successful
## Why
`base64enc` still fails to install under R 4.6 even after it was built into the 4.6 slot:
```
base64enc.so: undefined symbol: SETLENGTH
```
The per-minor binary is correct and serves correctly to any client the router can identify. But the **flat slot still holds a binary built under R 4.4.3**, and that is what every client receives when it cannot be routed by R minor.
That object should not exist. `upload_single_binary()` writes an ABI-risky package only to the per-minor path:
```r
if (is_r_minor_sensitive) {
remote_tarball_path <- file.path(remote_bin_path, minor_version, tarball_name)
} else {
remote_tarball_path <- file.path(remote_bin_path, tarball_name)
}
```
`base64enc`'s flat binary is a legacy artifact from before it was classified risky. Removing it makes the outcome correct regardless of routing, user agent, downloader or renv configuration, which is the part I could not otherwise guarantee.
## What it does
`local/prune-stale-flat-binaries.R` lists a slot's flat objects, intersects them with the risky set, and deletes them. Deleting is safe here: the source fallback republishes the CRAN source under the same key, so the package stays installable everywhere and compiles against the client's own R, while routed clients keep getting the per-minor binary.
Safety posture, given this deletes production objects:
- **dry run by default**; nothing is removed without `--apply`
- takes an **explicit package list**, so the first runs need not trust the classifier cache at all
- **refuses to proceed on an empty risky set**, which is indistinguishable from an unreachable cache and would otherwise report success having pruned nothing
- **keeps objects whose package CRAN no longer ships**, since there would be no source to fall back to and the package would vanish
- **re-indexes and purges in the same run**. This is not optional: a published index naming deleted files serves 404s, which is worse than the binary it replaced.
## Use
```sh
# dry run first
crow pipeline create devxy/build-cran-binaries \
--var prune_flat=ubuntu-2604-amd64 --var PRUNE_PACKAGES="base64enc lobstr"
# then apply
crow pipeline create devxy/build-cran-binaries \
--var prune_flat=ubuntu-2604-amd64 --var PRUNE_PACKAGES="base64enc lobstr" \
--var PRUNE_APPLY=yes
```
`crow lint` passes.
## Sequencing
Run with an explicit list first, on one slot, and confirm the flat URL then serves source while the per-minor URLs still serve binaries. Only widen to the cache-derived set once the backfill has finished and its output looks sane: the first 250 classifications came back 232 r-minor-sensitive, and a rate that high suggests the source-grep classifier is broader than the set that actually breaks, which is worth checking before pruning thousands of flat binaries.
Reviewed-on: #200
This commit is contained in:
parent
853b924765
commit
f9ebb3dba4
1 changed files with 381 additions and 0 deletions
136
local/prune-stale-flat-binaries.R
Normal file
136
local/prune-stale-flat-binaries.R
Normal file
|
|
@ -0,0 +1,136 @@
|
|||
### Remove flat-slot binaries of packages that are ABI-risky.
|
||||
#
|
||||
# Usage:
|
||||
# Rscript local/prune-stale-flat-binaries.R <arch> <codename> [--apply] [pkg ...]
|
||||
#
|
||||
# `upload_single_binary()` writes an ABI-risky package only to the per-minor
|
||||
# slot, never to the flat one, so a risky package should have no flat binary at
|
||||
# all. Packages built before they were classified risky still do, and the flat
|
||||
# slot is what every client that cannot be routed by R minor receives. That
|
||||
# binary was built under whichever R was primary at the time, so it fails at
|
||||
# load under any minor that dropped a symbol it uses:
|
||||
#
|
||||
# base64enc.so: undefined symbol: SETLENGTH
|
||||
#
|
||||
# Deleting the flat object does not create a hole: bincraft's source fallback
|
||||
# publishes the CRAN source under the same key, so the package stays installable
|
||||
# everywhere and compiles against the client's own R. Clients that are routed
|
||||
# keep getting the per-minor binary.
|
||||
#
|
||||
# Dry run by default. Nothing is deleted without --apply.
|
||||
|
||||
options(error = function() {
|
||||
cat("ERROR:", geterrmessage(), "\n", file = stdout())
|
||||
traceback(2)
|
||||
q(status = 1)
|
||||
})
|
||||
|
||||
library(bincraft, quietly = TRUE)
|
||||
|
||||
args <- commandArgs(trailingOnly = TRUE)
|
||||
apply_changes <- "--apply" %in% args
|
||||
args <- args[args != "--apply"]
|
||||
if (length(args) < 2L) {
|
||||
stop(
|
||||
"usage: prune-stale-flat-binaries.R <arch> <codename> [--apply] [pkg ...]",
|
||||
call. = FALSE
|
||||
)
|
||||
}
|
||||
arch <- args[[1L]]
|
||||
codename <- args[[2L]]
|
||||
explicit <- args[-c(1L, 2L)]
|
||||
|
||||
bucket <- "devxy-rpkgs-binaries"
|
||||
s3fs::s3_file_system(
|
||||
aws_access_key_id = Sys.getenv("B2_S3_ACCESS_KEY"),
|
||||
aws_secret_access_key = Sys.getenv("B2_S3_SECRET_KEY"),
|
||||
endpoint = "https://s3.eu-central-003.backblazeb2.com",
|
||||
region_name = "eu-central-003",
|
||||
refresh = TRUE
|
||||
)
|
||||
|
||||
contrib <- sprintf("%s/%s/%s/latest/src/contrib", bucket, arch, codename)
|
||||
objects <- s3fs::s3_dir_ls(contrib, recurse = TRUE)
|
||||
relative <- sub(sprintf("^(s3://)?%s/", contrib), "", objects)
|
||||
|
||||
is_tarball <- grepl("\\.tar\\.gz$", relative)
|
||||
# Flat objects only: no `<minor>/` prefix and not under Archive/.
|
||||
is_flat <- is_tarball & !grepl("/", relative, fixed = TRUE)
|
||||
flat_files <- relative[is_flat]
|
||||
flat_pkg <- sub("_.*$", "", flat_files)
|
||||
|
||||
if (length(explicit) > 0L) {
|
||||
risky <- explicit
|
||||
cat(sprintf("Restricted to %d named package(s)\n", length(risky)))
|
||||
} else {
|
||||
risky <- bincraft:::abi_cache_risky_packages()
|
||||
cat(sprintf("Classifier cache reports %d risky package(s)\n", length(risky)))
|
||||
if (length(risky) == 0L) {
|
||||
stop(
|
||||
"The classifier cache returned nothing. Refusing to proceed: an empty risky set here is indistinguishable from an unreachable cache, and would silently prune nothing while reporting success.", # nolint
|
||||
call. = FALSE
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
doomed <- flat_files[flat_pkg %in% risky]
|
||||
cat(sprintf(
|
||||
"%s/%s: %d flat binaries, %d belong to ABI-risky packages\n",
|
||||
arch,
|
||||
codename,
|
||||
length(flat_files),
|
||||
length(doomed)
|
||||
))
|
||||
|
||||
# Never remove the last artifact of a package. The source fallback republishes
|
||||
# the CRAN source under this key, but only for packages CRAN still ships, so
|
||||
# confirm the source exists before deleting the binary.
|
||||
cran <- tryCatch(
|
||||
{
|
||||
con <- gzcon(url(
|
||||
"https://cloud.r-project.org/src/contrib/PACKAGES.gz",
|
||||
open = "rb"
|
||||
))
|
||||
on.exit(close(con), add = TRUE)
|
||||
read.dcf(con, fields = "Package")[, "Package"]
|
||||
},
|
||||
error = function(e) character(0)
|
||||
)
|
||||
if (length(cran) == 0L) {
|
||||
stop("Could not read CRAN's index; refusing to prune blind.", call. = FALSE)
|
||||
}
|
||||
|
||||
orphaned <- doomed[!(sub("_.*$", "", doomed) %in% cran)]
|
||||
if (length(orphaned) > 0L) {
|
||||
cat(sprintf(
|
||||
"Keeping %d object(s) whose package is no longer on CRAN, so there is no source to fall back to: %s\n",
|
||||
length(orphaned),
|
||||
paste(utils::head(orphaned, 5L), collapse = ", ")
|
||||
))
|
||||
doomed <- setdiff(doomed, orphaned)
|
||||
}
|
||||
|
||||
if (length(doomed) == 0L) {
|
||||
cat("Nothing to prune.\n")
|
||||
quit(status = 0)
|
||||
}
|
||||
|
||||
for (f in doomed) {
|
||||
cat(sprintf(" %s %s\n", if (apply_changes) "DELETE" else "would delete", f))
|
||||
}
|
||||
|
||||
if (!apply_changes) {
|
||||
cat(sprintf(
|
||||
"\nDry run: %d object(s) left in place. Re-run with --apply to delete.\n",
|
||||
length(doomed)
|
||||
))
|
||||
quit(status = 0)
|
||||
}
|
||||
|
||||
for (f in doomed) {
|
||||
s3fs::s3_file_delete(file.path(contrib, f))
|
||||
}
|
||||
cat(sprintf(
|
||||
"Deleted %d flat binary object(s). Re-index the slot so the source fallback republishes them.\n",
|
||||
length(doomed)
|
||||
))
|
||||
Loading…
Reference in a new issue