Repository navigation
Description
[agent] Found by the scheduled Bundler (RubyGems) bug-hunt routine (ledger #316).
Summary
After bundle remove <gem> drops a gem that vendored mode patched, no socket-patch command can clean up what is left of it. scan --mode vendored --prune, remove, rollback and vendor --revert all call the entry "drifted" and keep its .socket/vendor/gem/<uuid>/ directory and its ledger record, and vendor --check exits 1 from then on. Each message names a remedy that cannot work, because the gem is no longer in the project. The same happens when the user moves the gem to a newer release by editing its Gemfile line (gem "rake", "13.3.0") and running bundle install.
This is the Bundler form of #1132 (bun remove) and #1287 (uv remove), which #1147 fixed for those backends.
Impact
vendor --checkis red for good, so a CI job that gates on it fails on every run after an ordinarybundle remove.- The dead vendored copy and its ledger record stay in the repository. The only way out is to delete the directory and edit
.socket/vendor/state.jsonby hand. removeandrollbackof that gem exit 1, also on every later run.- Bundler itself is not affected: the
GemfileandGemfile.lockare left alone andbundle installpasses.vexcorrectly leaves the gem out (vendor_unwired).
Repro
A patch service that serves a patch for rake 13.2.1 (the repo's stand-in, tests/nokogiri/patch_service.rb, was used here; $M is the --api-url … --patch-server-url … --api-token … --org … flags that point at it).
mkdir repro && cd repro
printf 'source "https://rubygems.org"\n\ngem "rack", "2.2.8"\ngem "rake", "13.2.1"\n' > Gemfile
bundle config set --local path vendor/bundle
bundle install
socket-patch scan --mode vendored $M # exit 0, rack and rake vendored
BUNDLE_FROZEN=true bundle install # passes
bundle remove rake # the project no longer uses rake
socket-patch vendor --check $M # exit 1
socket-patch scan --mode vendored --prune $M # exit 0, entry kept
socket-patch remove pkg:gem/rake@13.2.1 $M # exit 1
socket-patch rollback pkg:gem/rake@13.2.1 $M # exit 1
socket-patch vendor --revert $M # exit 0, rack reverted, rake kept
socket-patch vendor --check $M # exit 1
ls .socket/vendor/gem # rake's uuid directory is still thereActual
$ socket-patch vendor --check
pkg:gem/rake@13.2.1?platform=ruby: wiring missing: no lockfile or config references .socket/vendor/gem/00000002-… any more, so a fresh install gets the unpatched package; re-run `socket-patch vendor` to rewire it
$ socket-patch scan --mode vendored --prune
[skip] pkg:gem/rake@13.2.1?platform=ruby (vendor_gem_version_not_locked): Gemfile.lock does not resolve rake 13.2.1: this project doesn't lock that version, so there is nothing to vendor
GC: kept 1 drifted vendored entry: lock entries were re-resolved since vendoring, so their artifacts and manifest/ledger entries were retained; undo the drift and re-run `vendor --revert` to finish.
$ socket-patch remove pkg:gem/rake@13.2.1
Warning: Gemfile.lock no longer carries what vendor wrote for rake; left alone, and neither Gemfile nor Gemfile.lock was changed
Warning: kept .socket/vendor/gem/00000002-…: some recorded lock entries were left alone (…) undo the drift (restore the vendored lock entries or re-vendor) and re-run `vendor --revert` to finish cleaning up
Warning: Kept vendored state for pkg:gem/rake@13.2.1?platform=ruby: lockfile wiring drifted
Error: 1 matching entry was drift-kept (vendored state and ledger record retained); re-run `scan --mode vendored` to normalize, then remove again
$ socket-patch vendor --revert
Reverted 1 vendored package.
Kept 1 drifted package: lock entries were re-resolved since vendoring, so their artifacts and ledger entries were retained — undo the drift and re-run `vendor --revert` to finish.
None of the named remedies works:
- "re-run
socket-patch vendorto rewire it": printsNo manifest to vendor from; … entries are tracked in the ledgerand changes nothing. - "re-run
scan --mode vendoredto normalize, then remove again": the scan skips the gem (vendor_gem_version_not_locked), andremovefails the same way again. - "undo the drift and re-run
vendor --revert": the only way to undo it is to add the gem back to the project.
Expected
crates/socket-patch-cli/CLI_CONTRACT.md (vendored revert, drift rules) says that for the npm family "a recorded lock entry that no longer exists at all — the user removed the dependency — is not drift: it warns vendor_lock_entry_removed and the artifact and entry are kept unless every wired file that exists was read and none mentions the uuid in any spelling …, so rollback / remove / scan --prune clean up after npm uninstall / yarn remove / pnpm remove / bun remove", and that the same holds for an entry re-resolved away from the artifact by an upgrade. #1147 gave bun.lockb, uv and Pipenv the same rule. The gem backend should follow it: when neither Gemfile nor Gemfile.lock names the entry's .socket/vendor/gem/<uuid> directory any more, there is nothing to restore, so the artifact and the ledger record should go and vendor --check should pass again. Neither docs/ecosystems.md nor the contract documents a gem exception.
Versions
| socket-patch | Bundler | Ruby | Result |
|---|---|---|---|
main cfc870f |
4.1.1 | 3.3.6 | reproduces (both the bundle remove and the upgrade variant) |
main cfc870f |
4.0.18 | 3.3.6 | reproduces |
main cfc870f |
2.6.9 | 3.3.6 | reproduces |
main cfc870f |
2.5.22 | 3.3.6 | reproduces |
| 5.1.0 (npm) | 4.1.1 | 3.3.6 | reproduces (scan --prune exits 1 there) |
Not a regression since v5.1.0. Linux only was tested; nothing here depends on the platform.
Suspect code
crates/socket-patch-core/src/vendor/gem.rs:2174: every RecordRevert::Drifted record sets drifted = true and warns vendor_lock_entry_drifted. There is no arm for a record whose entry is gone while no wired file still names the uuid directory (the vendor_lock_entry_removed case of the other backends).
Generated by Claude Code
Activity
mikolalysenko commentedon Nov 28, 2026
[agent] Two more observations from the same run (main
cfc870f, Bundler 4.1.1), in case they help the fix:rollback --dry-runin the stuck state previews the revert as if it would work: it printsWould revert vendoring for pkg:gem/rake@13.2.1?platform=rubybeside thevendor_lock_entry_driftedwarning, exits 0, and under--jsonreportsstatus: successwith averifiedevent for the gem. The realrollbackthen exits 1 and keeps the entry.Gemfile.lockwith merge-conflict markers (a branch that added a gem, merged into the branch that vendored) goes down the same "drifted" path for every vendored gem:rollback,removeandvendor --checkprint the texts above, and ascan --mode vendoredsaysGemfile.lock does not resolve nokogiri 1.18.10: this project doesn't lock that version. Nothing is written, and after the conflict is resolved withbundle installeverything works again (re-scan changes nothing, frozen install,vex, rollback). Hosted mode names the conflict marker's line in the same situation; vendored mode does not.Generated by Claude Code
mikolalysenko commentedon Dec 1, 2026
[agent] Claiming this issue. Branch: agent/fix-gem-revert-removed-dependency.
Generated by Claude Code
Add failing tests for a dropped vendored gem
Clean up a vendored gem the project dropped
Hold the dropped-gem audit to what each undo leaves
Keep a gem entry wired under another patch uuid