Repository navigation
Fix vendored unwind leaving an agent-patched gem (#2093) - #2122
Mikola Lysenko (mikolalysenko) wants to merge 5 commits into
Conversation
Refs #2093 Assisted-by: Claude Code:claude-fable-5-2
Four tests fail: rollback, remove and vendor --revert of a gem that agent mode patched in place and a vendored scan then took over leave the installed copy on the patched files and say nothing, with or without the upstream archive in the gem home. Refs #2093 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_011f9aeQy1d8enbEzCjPrQua
Fails on rollback, remove and vendor --revert: the installed copy keeps agent mode's patched files after the vendored gem is unwound. Refs #2093 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_011f9aeQy1d8enbEzCjPrQua
A vendored takeover of a gem that agent mode patched in place moves the manifest record into the vendor ledger and keeps the patched files, because Bundler loads the vendored copy from then on. The vendored unwind judged an installed copy only by the archive in its gem home, which for such a copy is the upstream one. So rollback, remove and vendor --revert left the patched files in the copy Bundler loads again, with no record left to undo them. The unwind's gem refresh now also judges each installed copy against the patch record the unwind ends: a copy whose files hash to the record's afterHash values is reinstalled from the upstream gem. That is the archive RubyGems kept beside it, so nothing is downloaded unless the gem home's cache was pruned. A copy the run may not or cannot replace is named by upstream_gem_stale_install. The record is the detached ledger entry's. For a gem standalone vendor took from an agent manifest it is the manifest record, and only in rollback and remove, which drop it without restoring a file. vendor --revert keeps that record, so the copy stays patched. Fixes #2093 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_011f9aeQy1d8enbEzCjPrQua
Review follow-ups for the vendored unwind's record judgment. A gem the manifest still has a record for is not judged: its in-place patch is agent mode's and on record there (standalone vendor keeps the record), so vendor --revert leaves the installed copy as it is. Only a detached ledger entry's record is used, and the manifest is matched by PurlKey as the takeover does. With no sha256 for the upstream gem (an offline run or a registry error under a lock without CHECKSUMS), a copy is judged by its record only when the lock resolves the gem from rubygems.org. A gem from another remote stays unjudged, as in every unwind refresh. Refs #2093 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_011f9aeQy1d8enbEzCjPrQua
|
[agent] bugbot run Generated by Claude Code |
PR SummaryMedium Risk Overview The vendored unwind refresh now also compares installed files to the detached vendor ledger patch record (
Reviewed by Cursor Bugbot for commit 9389ca9. Configure here. |
LLM Description written by Claude Code:claude-fable-5-2
Fixes #2093
Summary
A gem that agent mode patched in place and
scan --mode vendored(orget --mode vendored) then took over stayed patched afterrollback,removeorvendor --revert: the pair was back on rubygems.org, Bundlerloaded the installed copy again, that copy still held the patched files,
and no record was left that any command could act on.
The vendored unwind now puts the upstream gem back in that copy, the same
way it already does for a copy a hosted scan had replaced (#2083). A copy
it may not or cannot replace is named by
upstream_gem_stale_installwith the files to remove.
Root cause
The takeover moves the manifest record into the vendor ledger and keeps
the patched files (by design: Bundler loads the vendored copy from then
on, and
vexcompares the installed copy with the vendored artifact).The unwind's gem refresh judged an installed copy only by the archive in
its gem home's
cache/. For an agent-patched copy that archive is theupstream one, so the copy passed as the upstream build.
The change
gem_refresh.rs: the vendored unwind's refresh also judges eachinstalled copy against the patch record of the ledger entry being
removed. A copy whose files all hash to the record's
afterHashvaluesis stale whatever archive its gem home holds, and is reinstalled from
the upstream gem. That is the archive RubyGems kept beside it, so
nothing is downloaded unless
cache/was pruned.vendored_backend/mod.rs:reverthands the refresh the record of eachunwound gem, under two limits. Only a detached entry's record is used
(
scan/get --mode vendored, where the ledger is the only owner).A gem
.socket/manifest.jsonstill has a record for is not judged: itsin-place patch is agent mode's and on record there.
--offlineor a registry errorunder a lock without
CHECKSUMS), a copy the record proves patched isreported, not refreshed, and only when the lock resolves the gem from
rubygems.org (
gem_resolves_from_rubygemsin core). A gem from anotherremote stays unjudged, as in every unwind refresh.
CLI_CONTRACT.md("Gem stale-install guard") anddocs/ecosystems.mddescribe the new judgment. No new flag, code or output field.
The existing limits of the refresh apply unchanged: a project-local gem
home only unless
--gem-refresh-shared,--no-gem-install-refresh,--offline, ruby-platform gems only. The hosted unwind is not touched(it passes no records).
Evidence
Each new test failed before the fix commit (
46d8a30,3dc990fare thered commits) and passes after it.
e2e_redirect_gem_stale_install(mock API, no Ruby needed), each overrollback,removeandvendor --revert:vendored_unwind_restores_an_install_agent_mode_patchedupstream_gem_install_refreshedvendored_unwind_restores_an_agent_patched_install_without_its_archivecache/pruned: one download of the upstream gemvendored_unwind_names_an_agent_patched_install_it_leaves--no-gem-install-refresh, and--offlinewithcache/pruned: gem home untouched, warning names the filesvendored_unwind_reports_the_agent_patched_refresh_in_a_human_runvendored_unwind_leaves_an_install_the_manifest_still_recordsvendor --revertleaves a copy whose record is in the manifestvendored_unwind_does_not_judge_an_agent_patched_gem_from_another_remotee2e_redirect_gem_build(real Bundler):gem_vendored_unwind_restores_an_install_agent_mode_patchedruns thethree unwinds, then
bundle install,--redownloadandpristine, andchecks
bundle execloads the upstream code after each.Local runs (Ruby 3.3.6, Bundler 4.0.18, Linux):
cargo clippy --all-targetsreports errors in test code this PR doesnot touch (
tests/common,tests/prebuilt_common, older lines of thetwo gem suites); they are on
maintoo, and CI's clippy job does notbuild test targets.
Review findings not fixed here
/code-review highran twice. Fixed: the judgment for a gem from anotherremote, PurlKey matching, and an earlier attempt to cover manifest
records that could reinstall a copy whose record then stayed. Left, with
the reason:
rollback/removeafter standalonevendorfrom an agentmanifest. They drop the manifest record of a vendored gem without
restoring its files, so the copy stays patched (unchanged from
main).The right fix is in the in-place leg, which still has the record's
blobs and can restore exactly, offline and in a shared gem home. It is a
different path from this one and deserves its own issue.
place. The takeover drops the older manifest record, and the ledger
record's hashes do not match the installed files, so the copy is not
detected. The fix belongs in the takeover (
migrate_legacy_manifest_records).warning still offers a re-run with
--gem-refresh-shared, which isHosted gem
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.manifest records the patch.
vendor's reconcile afterremove --skip-rollback) are not judged: the user chose to keep thepatched files.
be checked"; the remedy it prints is the same.
gem, on a path that already crawled twice.
gem_resolves_from_rubygemsre-reads the lock instead of a newUpstreamArchivevariant: that keeps the return contract the hostedunwind matches on.
https://claude.ai/code/session_011f9aeQy1d8enbEzCjPrQua
Generated by Claude Code