Repository navigation
Description
[agent] Found by the scheduled Bundler (RubyGems) bug-hunt routine (ledger #316).
Summary
When a hosted gem project keeps its gems in a shared gem home (no BUNDLE_PATH), rollback and remove restore the Gemfile pair and warn that the shared gem home still holds the patched build. The warning names two remedies. The second one, "re-run with --gem-refresh-shared", can't work: the first run already removed the patch state, so the re-run exits 1 with "No patches in this project; nothing to roll back." (or "nothing to remove."). The patched install and the patched .gem archive stay in the shared gem home.
Impact
The user followed the tool's own instruction and got an error. Their project is now on the upstream lock, but:
bundle installprints "Bundle complete!" and the app still loads the patched code.- On Bundler 4.0.18 (lock with
CHECKSUMS),bundle pristineexits 37 on the patched archive and leaves the gem uninstalled.bundle execthen fails withcannot load such file -- rack, and every laterbundle installexits 37 too. - On Bundler 2.6.9 (no
CHECKSUMS),bundle pristinereinstalls the patched build from the archive.
Nothing in socket-patch can put the upstream copy back at this point, short of patching the project again with scan --gem-refresh-shared and then running rollback --gem-refresh-shared. The first remedy in the warning (bundle config set --local path vendor/bundle && bundle install) does work, and passing --gem-refresh-shared to the first rollback works as well.
Repro
Any hosted gem patch will do. I used a local mock of the patch API serving a repacked rack 2.2.8 ($MOCK stands for --api-url … --proxy-url … --patch-server-url …).
export GEM_HOME=/tmp/shared-gem-home # any gem home outside the project
mkdir proj && cd proj && git init -q .
printf 'source "https://rubygems.org"\n\ngem "rack", "2.2.8"\n' > Gemfile
printf 'require "bundler/setup"\nrequire "rack"\nputs "patched=#{($SOCKET_PATCHED||[]).inspect}"\n' > app.rb
bundle install
socket-patch scan --mode hosted --yes --gem-refresh-shared $MOCK
bundle exec ruby app.rb # patched=["rack"]
socket-patch rollback --yes $MOCK # exit 0, prints the warning below
socket-patch rollback --yes --gem-refresh-shared $MOCK # the remedy: exit 1
bundle install && bundle exec ruby app.rb # Bundle complete! patched=["rack"]
bundle pristine; echo $? # 37 on Bundler 4.0.18
bundle exec ruby app.rb # cannot load such file -- rackOutput of the two rollbacks:
Restored pkg:gem/rack@2.2.8 to its upstream registry entry
Note: 1 unwired package keeps its patched bytes in installed trees until the next package-manager install.
Warning: 1 gem still holds the patched build on disk after the switch back to the upstream registry. Shared gem home /tmp/shared-gem-home (left alone, other projects may load it): rack 2.2.8. `bundle install` reuses an installed gem instead of fetching the upstream one. To install it for this project only, run `bundle config set --local path vendor/bundle && bundle install`, or re-run with `--gem-refresh-shared` to replace the shared copy
Error: No patches in this project; nothing to roll back.
socket-patch remove rack --yes followed by socket-patch remove rack --yes --gem-refresh-shared behaves the same way ("nothing to remove.", exit 1).
The same happens when the shared copy became patched without the flag, for example a bundle install into an empty gem home after the hosted scan.
Expected
docs/ecosystems.md ("Ruby gems: gems already installed") says of the refresh: "rollback and remove do the same with the upstream gem", and of a shared home: "or re-run with --gem-refresh-shared … to replace the copies in the shared gem home". CLI_CONTRACT.md lists --gem-refresh-shared for "Hosted mode, rollback, remove: also refresh stale gems in gem homes outside the project." A remedy the tool prints should work when followed. Either the re-run with the flag replaces the shared copy with the upstream build even though the pair is already restored, or the unwind warning names a remedy that does work at that point.
The note "keeps its patched bytes in installed trees until the next package-manager install" is also wrong here: the next bundle install keeps them.
Actual
The re-run exits 1 and changes nothing. The shared gem home keeps the patched install and archive.
Versions
| Bundler | Ruby | Result |
|---|---|---|
| 4.0.18 | 3.3.6 | Reproduces (twice). bundle pristine exits 37 and leaves rack uninstalled |
| 2.6.9 | 3.1.6 | Reproduces. bundle pristine reinstalls the patched build |
| 4.0.18 | 3.3.6 | rollback --gem-refresh-shared as the first rollback: works, upstream copy restored, bundle pristine passes |
socket-patch main 63f791d (5.1.0). Linux only; nothing here looks platform-specific.
Suspect code
crates/socket-patch-cli/src/commands/gem_refresh.rs:380and:585build the "re-run with--gem-refresh-shared" text for both directions. For the unwind direction a re-run has no state to act on.crates/socket-patch-cli/src/ui/text.rs:557is the "nothing to roll back" refusal the re-run hits before any gem refresh is considered.
Generated by Claude Code
Activity
bundler: 2026-11-15 run, #2086 and #2087
mikolalysenko commentedon Nov 18, 2026
[agent] Not claimed this run, on purpose. Both fixes this issue allows (an unwind warning that names a remedy that works after the state is gone, or a re-run with
--gem-refresh-sharedthat judges the shared copy without a manifest record) change the unwind half ofcrates/socket-patch-cli/src/commands/gem_refresh.rs, which #2122 (open, awaiting review) rewrites and where #2092 is already queued behind it. A PR frommainwould conflict with #2122, so this should be built on top of it once it merges.Generated by Claude Code
mikolalysenko commentedon Nov 19, 2026
[agent] Claiming this issue. Branch: agent/fix-gem-unwind-shared-rerun-remedy.
Generated by Claude Code
Test the gem unwind warning for a shared home
Name a working remedy after a gem unwind
Quote rm paths and state the shared-copy cost