Behind a private gem mirror a hosted gem pin cannot be undone: `rollback` and `remove` refuse on a `CHECKSUMS` lock, and without `CHECKSUMS` `rollback` leaves the patched builds installed with no warning that names them

Abierto
#2,230 1 comentario 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

@mikolalysenko ya está trabajando en esto.

Desde el 25/11/2026.

  • #2233 de @mikolalysenko — abierto

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
12/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Estancado
Stack tecnológico
ruby, rust
Área
build-system, cli

Línea de trabajo

The refusal is raised in crates/socket-patch-core/src/patch/redirect/upstream/gem.rs (the same_remote check against RUBYGEMS_REMOTE, around line 1410), and the stale-install warning is in crates/socket-patch-cli/src/commands/gem_refresh.rs. Read CLI_CONTRACT.md's 'The unwind is exact' and 'Gem stale-install guard' sections first, and check open PR #2233 before starting, since it is already linked. Done means rollback and remove restore the pre-scan Gemfile and Gemfile.lock on a CHECKSUMS lock with a mirror source, or the scan declines to wire the gem, and the Bundler 2.5 case names the patched files to remove.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

agent:claimed agent:triaged bug bughunt pm:bundler priority:p1

[agent] Found by the scheduled Bundler (RubyGems) bug-hunt routine (ledger #316).

Summary

When a project's Gemfile names a private gem mirror as its source (source "https://gems.example.com": Artifactory, Nexus, Gemstash, a static gem generate_index server), scan --mode hosted wires the gems and replaces the installed copies with the patched builds as usual, but the pin can't be undone with socket-patch afterwards:

  • Lock with CHECKSUMS (Bundler 2.6 and later, 4.x): rollback and remove always refuse with "its upstream GEM remote … is not rubygems.org, so its CHECKSUMS sha256 cannot be re-derived" (exit 1). The scan that wired the gem printed socket-patch rollback pkg:gem/<gem>@<version> as the way to move it to a newer release, so its own remedy can't be followed. The refusal's remedy, git checkout -- Gemfile Gemfile.lock, restores the pair but leaves the patched builds in vendor/bundle: the app keeps loading the patched code, socket-patch rollback then says "No patches in this project", and bundle pristine fails on the checksum (exit 37), removes the gems, and the app no longer loads.
  • Lock without CHECKSUMS (Bundler 2.5): rollback exits 0 and restores the pair byte for byte, but leaves the patched builds installed and says only "2 unwired packages keep their patched bytes in installed trees until the next package-manager install". That is not true for Bundler: bundle install keeps them and bundle pristine reinstalls them from the patched archive in cache/. No upstream_gem_stale_install warning names the files to remove.

The mirror serves the very same .gem files as rubygems.org here (same sha256), so the checksum to restore is the one the lock held before the scan and the one the rubygems.org index lists.

A mirror set with bundle config mirror.https://rubygems.org is not affected (the lock still says remote: https://rubygems.org/). This is about a source line that names the mirror, which is how many companies reach gems.

Impact

A project that installed cleanly can't get back to its pre-scan state with the tool. On Bundler 2.6+ the documented way out ends in a failing bundle pristine and a broken gem home. On Bundler 2.5 rollback reports success while the app still runs the patched gems. rollback pkg:gem/<gem>@<version> of one gem out of several (to upgrade it, as the scan suggests) is impossible: git checkout of the pair drops every pin.

Repro

Uses the repo's stand-in patch service (tests/nokogiri/patch_service.rb) for rack 2.2.8 and rake 13.2.1 on a loopback port; every socket-patch call below also takes --api-url <mock> --patch-server-url <mock> --api-token fake --org nokogiri-e2e. Ruby 3.3.6.

# a private mirror holding the unmodified upstream gems
mkdir -p mirror/gems && cd mirror
(cd gems && gem fetch rack -v 2.2.8 && gem fetch rake -v 13.2.1)
gem generate_index -d . && python3 -m http.server 18091 --bind 127.0.0.1 &
cd ..

mkdir app && cd app
printf 'source "http://127.0.0.1:18091"\n\ngem "rack", "2.2.8"\ngem "rake", "13.2.1"\n' > Gemfile
bundle config set --local path vendor/bundle && bundle install   # Bundler 4.0.18
cp Gemfile Gemfile.orig && cp Gemfile.lock Gemfile.lock.orig

socket-patch scan --mode hosted
#   Replaced the installed copy of 2 gems with the patched build: rack 2.2.8, rake 13.2.1.
#   ... To move one to a newer release, run `socket-patch rollback pkg:gem/<gem>@<version>`, ...

socket-patch rollback pkg:gem/[email protected]      # exit 1
#   Error: Cannot restore pkg:gem/[email protected] to its upstream registry entry: its upstream GEM remote
#   http://127.0.0.1:18091/ is not rubygems.org, so its CHECKSUMS sha256 cannot be re-derived; restore it
#   from version control instead (`git checkout -- Gemfile Gemfile.lock`)
socket-patch remove pkg:gem/[email protected]        # same error, exit 1
SOCKET_RUBYGEMS_URL=http://127.0.0.1:18091 socket-patch rollback   # same error

# the remedy the refusal names
cp Gemfile.orig Gemfile && cp Gemfile.lock.orig Gemfile.lock
bundle install            # "Bundle complete!"; the app still loads the patched rack and rake
socket-patch rollback     # Error: No patches in this project; nothing to roll back.
bundle pristine           # exit 37: "Bundler found mismatched checksums", gems removed
bundle exec ruby -e 'require "rack"'   # LoadError

With Bundler 2.5.22 (no CHECKSUMS section) on the same project:

socket-patch scan --mode hosted
socket-patch rollback     # exit 0, Gemfile and Gemfile.lock byte-identical to the originals
#   Note: 2 unwired packages keep their patched bytes in installed trees until the next package-manager install.
bundle install && bundle pristine
bundle exec ruby app.rb   # still the patched rack and rake

rollback --json there has status: success and one warning, reinstall_required; no upstream_gem_stale_install.

Expected

  • CLI_CONTRACT.md ("The unwind is exact"): rollback / remove give back the pre-scan pair byte for byte. The task of this routine states the same bar. If hosted mode can't undo a pin for a lock it is about to edit, the scan should either not wire the gem (warn and name --mode agent), or be able to restore it: the pre-scan sha256 is in the lock the scan rewrites, the upstream archive is in the gem home's cache/ before the scan replaces it, and the mirror serves a compact index (info/<name>) with the checksum.
  • The hold note should not offer socket-patch rollback pkg:gem/<gem>@<version> where it will refuse.
  • CLI_CONTRACT.md ("Gem stale-install guard", the unwind direction): "a gem from another remote is refreshed only from an archive already on disk" and "what is still the patched build is warned about once (upstream_gem_stale_install)", naming the files to remove before bundle install. On the Bundler 2.5 lock no such warning is printed, only the generic note, whose "next package-manager install" does not replace anything under Bundler.

Actual

See the summary. On a CHECKSUMS lock the pin is one-way; without CHECKSUMS the pair is restored and the patched installs stay, unreported.

Versions

Result
main e685fb1 (5.1.0 + 33 commits), Bundler 4.0.18, Ruby 3.3.6, mirror as the only top-level source reproduces: rollback and remove refuse; git checkout remedy leaves patched installs, bundle pristine exits 37
main e685fb1, Bundler 2.5.22, Ruby 3.3.6, same project reproduces the second form: pair restored, patched builds stay, no upstream_gem_stale_install
main e685fb1, Bundler 4.0.18, source "https://rubygems.org" does not reproduce: "Replaced the installed copy of 1 gem with the upstream build", pair byte-exact

Linux only. Nothing here looks platform-specific. First bad release not searched; the refusal text predates 5.1.0.

Suspect code

  • crates/socket-patch-core/src/patch/redirect/upstream/gem.rs:1410 (the same_remote(&remote, RUBYGEMS_REMOTE) refusal; nothing on the scan side checks it before wiring).
  • crates/socket-patch-cli/src/commands/rollback.rs:2803 (the generic note) and crates/socket-patch-cli/src/commands/gem_refresh.rs:58 (upstream_gem_stale_install, not raised for a gem from another remote with no upstream archive on disk).

Generated by Claude Code

Lenguaje dominante
Rust
Estrellas
9
Forks
2
Merge medio
1 d 8 h
PR fusionados (30 d)
309

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de SocketDev/socket-patch

Todos los issues de SocketDev/socket-patch

Issues similares

Más issues de Rust

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.