Repository navigation
Fix vendored gem unwind leaving a hosted-patched install (#2083) - #2113
Mikola Lysenko (mikolalysenko) merged 5 commits into
Conversation
Refs #2083 Assisted-by: Claude Code:claude-fable-5-2 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011f9aeQ4raW21EPjpN9cP36
Three of the four tests fail: rollback, remove and vendor --revert of a gem that went hosted, then vendored, leave the installed copy and its gem-home archive on the patched build and say nothing. Refs #2083 Assisted-by: Claude Code:claude-fable-5-2 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011f9aeQ4raW21EPjpN9cP36
A hosted scan replaces the project's installed copy of a gem with the patched build. A hosted to vendored takeover leaves that copy, because Bundler loads the vendored one instead. Once rollback, remove or vendor --revert unwinds the vendored gem, Bundler loads the installed copy again, and it was still the patched build: the app kept running the patch under the upstream lock, and bundle pristine failed on the upstream checksum (exit 37). The shared vendored revert now runs the hosted unwind's upstream refresh for the installed copies of the gems it unwired, under the same limits (project-local gem homes, --no-gem-install-refresh, --offline), and warns upstream_gem_stale_install for a copy it leaves. A gem that was only ever vendored has the upstream archive in its gem home, so nothing is downloaded or changed for it. An unwind's stale-install warning no longer suggests a re-run without --no-gem-install-refresh: a second unwind has nothing left to unwind. Fixes #2083 Assisted-by: Claude Code:claude-fable-5-2 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011f9aeQ4raW21EPjpN9cP36
Review follow-ups for the vendored unwind's gem refresh. An entry vendored over hosted wiring before v5 reverts to its hosted pin, whose CHECKSUMS sha256 is the patched gem's. Judging the installed copy against it would call a correct upstream install stale. The refresh now covers only a gem the lock resolves from rubygems.org; the hosted unwind that follows restores such a pin and refreshes then. remove prints the refresh's progress line before it aborts on a failed ledger save, since the gem home was already changed. Refs #2083 Assisted-by: Claude Code:claude-fable-5-2 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011f9aeQ4raW21EPjpN9cP36
|
bugbot run Generated by Claude Code |
PR SummaryMedium Risk Overview Vendored unwinds now run the same upstream gem stale-install refresh as hosted unwinds, but only for project-local installed copies ( Unwind warnings with Contract and docs ( Reviewed by Cursor Bugbot for commit 1fb6e83. Configure here. |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 1fb6e83. Configure here.
|
[agent] PR shepherd: review brief for What it does: Fixes #2083. Sometimes a hosted scan patches a gem's installed copy before that gem is vendored. When Risk: low. It reuses the existing, tested hosted-unwind refresh. It writes nothing on a dry run, and never fails the unwind: a failed lookup or download only skips the gem or adds a warning, and the exit code stays 0. Look here
Verified
Changes I made: none. Open questions (minor, a possible follow-up)
Generated by Claude Code |
Conflicts: gem_refresh.rs (StaleGem gained in_place on main; the installed copies of an unwound gem are never patched in place) and the stale-install suite (both sides appended tests; kept both). Assisted-by: Claude Code:claude-fable-5-2 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011f9aeQ4raW21EPjpN9cP36
Main gained the vendored unwind's refresh of an install a hosted scan patched (#2113). It reworks the unwind refresh this branch changed, and two files conflicted. Each hunk keeps both sides. crates/socket-patch-cli/src/commands/gem_refresh.rs: - `stale_after_restore` takes main's `installed_with_archives` walk and its `Scope`, and keeps this branch's `Option<sha256>` map: a copy with no upstream sha256 to judge it by is listed whether or not its archive is cached, one with a sha256 is judged by the archive as before. - `after_restore` and main's new `after_vendored_unwind` both run `refresh_restored`, which keeps this branch's handling of `UpstreamArchive` (a refused registry is reported, not dropped) and its one `SecureRegistryClient` per run, with main's rule that a vendored unwind judges only a gem the lock resolves from rubygems.org. A refused lookup only comes back for such a gem, so that rule holds for the unchecked copies too. crates/socket-patch-cli/CLI_CONTRACT.md: - The unwind direction paragraph keeps this branch's account of a copy that could not be checked and ends with main's sentence on a copy left by `--no-gem-install-refresh`. - The `upstream_gem_stale_install` row takes main's vendored unwind columns and keeps this branch's "could not be checked" meaning. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…used registry The vendored unwind (#2113) now runs the same refresh as the hosted one, so it reports an installed copy it could not judge when the lock pins no sha256 and `SOCKET_RUBYGEMS_URL` is refused. An e2e holds that for `rollback`, `remove` and `vendor --revert`: the gem home is unchanged, no registry is asked, and the copy is named with the reason. The contract's paragraph on a vendored unwind says so. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
LLM Description written by Claude Code:claude-fable-5-2
Fixes #2083
Summary
A gem that was patched in hosted mode and later vendored keeps the patched installed copy in the project's
vendor/bundle(the hosted scan put it there, and the takeover leaves it because Bundler loads the vendored copy instead). When the vendored gem was unwound withrollback,removeorvendor --revert, theGemfilepair went back to upstream but the installed copy stayed patched. The app kept running the patch, and on a lock withCHECKSUMSbundle pristineandbundle install --redownloadfailed with exit 37.The vendored unwind now does what the hosted unwind already does for installed copies: it replaces a project-local installed copy whose gem-home archive is not the upstream gem with the sha256-verified upstream gem, and warns
upstream_gem_stale_install(with the files to remove) for a copy it may not or cannot replace.Root cause
VendoredBackend::revert(the one revert primitive behindrollback,remove,vendor --revertandvendor's reconcile) put a gem back on its upstream entry and only checked Bundler's cache dir (upstream_gem_stale_cache). The installed-copy refresh ingem_refresh::after_restoreran only from the hosted unwind.CLI_CONTRACT.mddocumented both halves ("the takeover leaves unused leftovers", "a vendored unwind only names the archive"), and together they left the gap: after the unwind the leftover is in use again.What changed
gem_refresh.rs:after_vendored_unwindruns the existing upstream refresh for installed copies only (Scope::Installed). It looks up the upstream sha256 only for a gem that has an installed copy with its archive, so unwinding a gem that is not installed still needs no network. The archive in Bundler's cache dir (vendor/cache) is not replaced, as before: the vendored unwind still names it.vendored_backend/mod.rs:revertcalls it once per run for the gems a wet revert unwired.--jsongets a note or warning per copy on the gem's entry. A human run gets one progress line and one consolidated warning.rollback.rs,remove.rs,vendor.rs: print the progress line after the gem's own line. Rollback's "keeps its patched bytes" note no longer counts a gem whose installed copy was refreshed.retry_hint: an unwind'supstream_gem_stale_installwarning no longer says "Re-run without--no-gem-install-refresh". A second unwind finds nothing to unwind (the same trap Hosted gemrollback/removetell the user to re-run with--gem-refresh-shared, but the re-run exits 1 with "nothing to roll back" and the patched gem stays in the shared gem home #2086 reports for--gem-refresh-shared), so the warning now gives only therm -f … && bundle installremedy. This also changes the hosted unwind's wording for that one case.CLI_CONTRACT.md("Gem stale-install guard", flag and warning tables) anddocs/ecosystems.mddescribe the new behavior.Limits kept from the hosted unwind: only gem homes inside the project are written unless
--gem-refresh-shared;--no-gem-install-refreshturns it off;--offlineuses only an archive already on disk; a failed download or verification changes nothing and warns. A gem that was only ever vendored has the upstream archive in its gem home, so nothing is downloaded or changed for it.Evidence
Each test below failed before the fix commit and passes after it.
e2e_redirect_gem_stale_install::vendored_unwind_restores_an_install_a_hosted_scan_patchedrollback,remove,vendor --revert: installed copy and gem-home archive are upstream again,upstream_gem_install_refreshedin the envelope…::vendored_unwind_reports_the_refresh_in_a_human_run…::vendored_unwind_names_an_install_it_leaves_on_the_patched_build--no-gem-install-refreshand a failed upstream download: gem home byte-identical,upstream_gem_stale_installnames the dir, gemspec and archive…::vendored_unwind_warns_once_in_a_human_runrm -f … && bundle installremedy and no "Re-run"…::vendored_unwind_leaves_an_upstream_install_alonee2e_redirect_gem_build::gem_vendored_unwind_restores_an_install_the_hosted_scan_patched(real Bundler,--ignored)bundle install,bundle install --redownloadandbundle pristineall succeed andbundle execloads the upstream codeLocal runs (Ruby 3.3.6, Bundler 4.0.18):
With the
src/changes stashed, the real-Bundler capstone and the four new hermetic tests fail on the installed copy still holding the patched build.Review (
/code-review high)Fixed:
CHECKSUMSsha256 is the patched gem's, so a correct upstream install would have been judged stale. The refresh now covers only a gem the lock resolves from rubygems.org. I have no test for this legacy state: staging a pre-v5 ledger entry by hand was more fixture than the rule deserves, so a reviewer may want to look at this hunk inrefresh_restored.removenow prints the refresh's progress line before it aborts on a failed ledger save.Not fixed, with reasons:
--offlineor a failed compact-index lookup on a lock withoutCHECKSUMS). The hosted unwind behaves the same way. Warning without evidence would fire on every offline unwind of a never-hosted gem.scan --pruneand--dry-rundo not refresh or preview. Stated in the contract. The prune leg that could hit this is the pre-v5 manifest reconcile.--gem-refresh-sharedon a re-run. That is Hosted gemrollback/removetell the user to re-run with--gem-refresh-shared, but the re-run exits 1 with "nothing to roll back" and the patched gem stays in the shared gem home #2086, unchanged here.rollback --jsonstill carriesreinstall_requirednext toupstream_gem_install_refreshed. The hosted unwind does the same; changing it for one leg would make the two disagree.Reportwould change the hosted path's types too.Not in this PR
scan --prunedoes not refresh, and--dry-rundoes not preview the refresh (the lock on disk is still the vendored one, so there is nothing to judge the archive by). Both are stated in the contract.rollback/removetell the user to re-run with--gem-refresh-shared, but the re-run exits 1 with "nothing to roll back" and the patched gem stays in the shared gem home #2086 (the--gem-refresh-sharedre-run hint for a shared gem home) is unchanged; the vendored unwind now prints that same warning for a shared gem home.rollback/remove/vendor --revertthe app still loads patched code and no command can undo it #2093 (agent-patched, then vendored) has a different cause: the gem-home archive there is the upstream one, so this refresh does not see it.https://claude.ai/code/session_011f9aeQ4raW21EPjpN9cP36
Generated by Claude Code