Repository navigation
Fix hosted gem unwind skipping a copy with no cached archive (#2092) - #2130
Mikola Lysenko (mikolalysenko) merged 6 commits into
Conversation
Refs #2092. Opens the draft PR that claims the issue. Assisted-by: Claude Code:claude-fable-5-2
Four end-to-end tests for #2092, in a gem home whose cache/ dir is gone: rollback and remove put the upstream gem back, a human run reports it, a copy no patch record can judge is named, and an upstream copy is left alone. The first three fail: the unwind judges an installed copy by its cached archive alone. Assisted-by: Claude Code:claude-fable-5-2
A capstone for #2092 in the real-Bundler suite: after a hosted install whose gem home lost its cache/ dir, rollback and remove must leave the upstream gem installed and bundle install must keep it. It fails: the patched copy stays. The mock-registry test of a copy no record can judge drops its offline arm, which no hosted unwind reaches (see the fix). Assisted-by: Claude Code:claude-fable-5-2
A hosted unwind (rollback, remove, a withdrawn-patch restore) judged an installed gem only by <home>/cache/<leaf>.gem. In a gem home with no cache dir (Bundler 4.1 prune, a slim image, gem cleanup) the copy the hosted scan had replaced with the patched build was passed over: no refresh and no warning, and no later bundle install replaced it. The unwind now fetches the record of the patch such a gem was pinned to, as the scan direction does, and judges the copy by its afterHash map through the records mechanism the vendored unwind uses. A copy holding the patch is replaced with the upstream gem. When the record cannot be fetched the copy is left alone and reported as one that could not be checked, with the files to remove. An unwind with no such copy fetches nothing. Fixes #2092 Assisted-by: Claude Code:claude-fable-5-2
Review of the #2092 fix found that the record judgment was keyed by purl and bolted on beside the archive check: - a gem two pins named was judged by the first pin's record only; - the fetched record then judged every copy of the gem, so whether a copy with its archive was replaced depended on a sibling gem home; - an unreachable API cost one timeout per gem; - a copy was still passed over when nothing proved the upstream sha256 (a lock without CHECKSUMS, offline or a registry error); - a gem with one refreshed and one unchecked copy was reported as needing no reinstall, and one with a stale and an unchecked copy lost its place in the warning's headline count; - the leg built an API client of its own. PinJudge now judges each installed copy that has no readable archive by the record of any patch its gem was pinned to, stops asking after the first fetch the API does not answer, and uses the run's API client, which run_hosted_leg now takes. Without an upstream sha256 a copy proven patched is reported as left on the patched build. Refs #2092 Assisted-by: Claude Code:claude-fable-5-2
A second review of the #2092 fix: - any API error stopped every later record fetch. Only a request the API did not answer (a network error) does now; - a copy missing a file its record lists was taken as free of the patch. A record judges only files it could read, so such a copy is reported as not checked; - a gem restored to a remote other than rubygems.org was not judged when nothing proved its upstream sha256. The restore that ran is what says the gem is back on its upstream entry; - the reason told a user to expect a fetch failure when the API had answered that it has no record of the patch; - the judge and the archive check now use one test for a readable archive, and after_restore takes the pins alone. Refs #2092 Assisted-by: Claude Code:claude-fable-5-2
|
bugbot run Generated by Claude Code |
PR SummaryMedium Risk Overview The unwind path adds Reporting treats a gem with one known-stale copy and one uncheckable copy in another home as stale in the human headline. Contract docs and ecosystem notes describe the pruned-cache behavior. E2E and unit tests cover refresh, warnings, offline/API failure, and upstream-only installs left alone. Reviewed by Cursor Bugbot for commit 10a4c86. 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 10a4c86. Configure here.
|
[agent] PR shepherd: review brief for What it does: After a hosted scan replaces an installed gem with the patched build, Risk: Low.
Look here
Verified
Changes I made: none. Open questions: none. The description lists four limits left on purpose, including a new "could not be checked" warning when scan restores a withdrawn patch in a pruned home. I agree with leaving them. Generated by Claude Code |
LLM Description written by Claude Code:claude-fable-5-2
Fixes #2092
Summary
After a hosted scan replaces an installed gem with the patched build,
rollback/removeare meant to put the upstream gem back. In a gemhome with no
cache/dir (Bundler 4.1'sprunesetting, therm -rf "${BUNDLE_PATH}"/ruby/*/cacheof the Dockerfile Railsgenerates,
gem cleanup) they restored theGemfilepair, left thepatched gem installed, and said nothing about it. No later
bundle installreplaces that copy, so the app kept loading patchedcode under the upstream lock.
Now the unwind judges such a copy by the record of the patch its gem was
pinned to, which is how the scan direction already judges a copy in a
pruned home, and:
upstream_gem_install_refreshed)CHECKSUMS, registry error)upstream_gem_stale_installwith the files to remove--offline, API error, a patch the API no longer has)upstream_gem_stale_installas "could not be checked", with the reason and the files to removeNothing changes for a copy whose gem home still has its archive, or for
any other ecosystem. An unwind with no archive-less copy fetches no
patch record.
Root cause
stale_after_restoreincrates/socket-patch-cli/src/commands/gem_refresh.rsjudged aninstalled copy only by
<home>/cache/<leaf>.gem. With no archive toread there was no evidence, so the copy was skipped. The hosted unwind
keeps no patch record of its own (v5 hosted mode has no ledger), so the
record mechanism #2122 added for the vendored unwind had nothing to
work from here.
How it works
PinJudge(new,gem_refresh.rs) looks at each installed copy of arestored gem that has no readable archive, fetches the record of each
patch that gem was pinned to (
/patches/view/<uuid>, once per uuid),and calls the copy stale when every file a record lists hashes to its
afterHash. Stale copies join the existing refresh, which alreadyreinstalls from the upstream archive and creates no
cache/dir.(
hosted_unwind.rs).run_hosted_legnow takes the run'sRunApiClient, sorollbackandremovebuild no second client andnone at all when no record is needed. Its four callers pass theirs.
view_recordis the one rule for "a view response that can judge",shared with the scan's
ViewFallback.report's headline counts a gem with one stale and one uncheckedcopy as stale (it could not occur before).
Evidence
Red first:
f392882and383e7e9add the end-to-end tests; on thosecommits 3 of 4 mock-registry tests and the real-Bundler test fail with
the installed file still
PATCHED. They pass from131f1bcon.At
10a4c86(Ruby 3.3.6, Bundler 4.0.18):cargo test -p socket-patch-cli --lib: 953 passed.cargo test -p socket-patch-cli --test e2e_redirect_gem_stale_install --test e2e_redirect_gem_build --test e2e_vendor_gem_build --test e2e_gem_native_ext_build -- --include-ignored:52, 49, 18 and 34 passed.
cargo clippy --locked -p socket-patch-cli --all-features -- -D warnings(CI's command): clean.
--all-targetsstill reports the lintsmainhas intests/commonandtests/prebuilt_common; none is ina file this PR touches.
cargo fmt --checkon the touched files: clean.Tests that cover
Fixes #2092:gem_hosted_unwind_restores_an_install_whose_home_cache_was_pruned(
e2e_redirect_gem_build.rs, real Bundler):rollbackandremoveleave the upstream gem installed, and
bundle installkeeps it.e2e_redirect_gem_stale_install.rs(mock registry):hosted_unwind_restores_an_install_whose_home_cache_was_pruned(both commands, one record fetched, no
cache/created),hosted_unwind_reports_the_pruned_home_refresh_in_a_human_run(dry run, progress line, no "keeps its patched bytes" note),
hosted_unwind_names_a_pruned_home_install_no_record_can_judge(API error: nothing changed, warning with reason and files),
hosted_unwind_names_a_pruned_home_install_with_no_upstream_sha256(
--offlinefetches nothing; registry error),hosted_unwind_leaves_an_upstream_install_in_a_pruned_home_alone.gem_refresh.rs:pin_judge_judges_an_archiveless_copy_by_any_of_its_pins(two pins,a missing record, unreadable record files, a copy with its archive),
a_gem_with_a_stale_copy_and_an_unchecked_one_counts_as_stale.Docs: the "Gem stale-install guard" section and the
upstream_gem_stale_installrow ofCLI_CONTRACT.md, and "Ruby gems:gems already installed" in
docs/ecosystems.md.Review (
/code-review high, two passes)Fixed (
1de2023,10a4c86): a gem two pins named was judged by onerecord; a fetched record judged every copy of the gem, not only the
archive-less one; any API error stopped later fetches, and an
unreachable API cost a timeout per gem; a copy missing a record's file
was taken as unpatched; no judgment when nothing proved the upstream
sha256, or for a gem on another remote; a refreshed-plus-unchecked gem
was reported as needing no reinstall; a second API client; a reason
that said "could not be fetched" when the API had answered.
Not fixed, on purpose:
judge, but the API may no longer serve that patch's record. The copy
is then reported as not checked, with the files to remove, where it
was passed over before. Replacing it would mean judging against the
upstream archive's own files in place of a patch record: a larger
change to the refresh, better as its own PR.
(
rollback --offlineon a lock withoutCHECKSUMS). It is stillnot judged, as on
main. The record judge could cover it, but thatchanges what every offline rollback on Bundler 2.5 and older prints,
and it is not this issue.
ViewFallbackandPinJudgestay two types. They shareview_record; the scan's holds a built client and retries after anerror, the unwind's builds the client lazily and stops after a
network error. Merging them would change the scan path.
an archive-less copy was refreshed). The archive check and the judge
each walk the homes; folding them into one walk is a refactor of
stale_after_restore.CI and Bugbot
All 88 checks pass on
10a4c86,ci-okandclippyamong them. Thethree
ruby / bazeljobs were cancelled by a duplicate run theready-for-review event started, and passed on one re-run. Bugbot found
no issues.
Follow-ups
their patched bytes ... until the next package-manager install" note
is still printed for a gem that was not refreshed, beside the specific
gem warning. It is not true for Bundler. Left for a change of its own,
since it is shared with every ecosystem.
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 shared-home warning names a re-run that cannot work)touches the same file and was waiting on Fix vendored unwind leaving an agent-patched gem (#2093) #2122 too. Not in this PR:
it is a different cause.
https://claude.ai/code/session_011f9aeQv3najd5px4XRiFzQ
Generated by Claude Code