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
Maintainers usually reply within 1 day
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 12/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Stale
- Domain
- build-system, cli
Research direction
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.
Written by the indexing model from the issue text.
Description
[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):rollbackandremovealways 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 printedsocket-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 invendor/bundle: the app keeps loading the patched code,socket-patch rollbackthen says "No patches in this project", andbundle pristinefails on the checksum (exit 37), removes the gems, and the app no longer loads. - Lock without
CHECKSUMS(Bundler 2.5):rollbackexits 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 installkeeps them andbundle pristinereinstalls them from the patched archive incache/. Noupstream_gem_stale_installwarning 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/removegive 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'scache/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 beforebundle 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(thesame_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) andcrates/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
- Dominant language
- Rust
- Stars
- 9
- Forks
- 2
- Avg merge
- 1d 8h
- Merged PRs (30d)
- 309
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from SocketDev/socket-patch
-
Windows unit tests fail on main: pnpm-registry-overrides fixtures are checked out as CRLF (mixes CRLF and LF line endings)Possibly taken @mikolalysenko claimed this today. Openagent:claimed agent:triaged ci-janitor priority:p1
Difficulty 1/5 1-3 hours Newbie friendliness 85/100
SocketDev/socket-patch#2238 · 1 comment ·
Maintainers usually reply within 1 day
-
agent:triaged arch-audit priority:p3 refactor
Difficulty 2/5 1-3 hours Newbie friendliness 83/100
SocketDev/socket-patch#1860 ·
Maintainers usually reply within 1 day
-
agent:triaged arch-audit priority:p3 refactor
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
SocketDev/socket-patch#1838 ·
Maintainers usually reply within 1 day
-
Nightly: pnpm11_registry_route_is_cleaned_up_when_a_patch_is_not_needed fails on Windows (pnpm records the RUNNER~1 short path as a second importer)Possibly taken A pull request linked to this issue is open or already merged. Openagent:triaged ci-janitor priority:p1
Difficulty 3/5 Half a day Newbie friendliness 42/100
SocketDev/socket-patch#2235 ·
Maintainers usually reply within 1 day
-
Agent mode reports a gem whose installed file was edited as "not installed on this host" / "not found on disk", `apply --check` says to run `apply`, and `rollback` exits 1 with "modified after patching" on every runPossibly taken @mikolalysenko claimed this today. Openagent:claimed agent:triaged bug bughunt pm:bundler priority:p1 ux
Difficulty 4/5 3-5 days Newbie friendliness 18/100
SocketDev/socket-patch#2231 · 1 comment ·
Maintainers usually reply within 1 day
All issues in SocketDev/socket-patch
Similar issues
-
[Bug] StreamLifecycleConfig clamps post-TTFT stream timeouts to remaining admission budgetPossibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
lbjlaq/Antigravity-Manager#4063 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
farion1231/cc-switch#9981 · 2 comments ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
bot:ai-assisted component:indexer status:untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
midnightntwrk/midnight-indexer#1834 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day