Repository navigation
Fix hosted scan leaving the upstream .gem beside an agent-patched gem (#2089) - #2103
Conversation
Hosted scan over a gem agent mode patched in place leaves the upstream .gem in the gem home's cache under a lock that pins the patched checksum. Claim commit; the fix follows. Assisted-by: Claude Code:claude-fable-5-2
A hosted scan over a gem agent mode patched in place leaves the upstream .gem in the gem home's cache under a lock that pins the patched checksum (#2089). The probe unit test and the two e2e tests fail until the next commit. Assisted-by: Claude Code:claude-fable-5-2
The hosted scan's stale-install probe judged an installed gem by an agent-mode manifest record when one existed and never looked at the archive RubyGems reinstalls from. An in-place patch keeps the upstream archive, so once the lock pinned the patched checksum, bundle pristine and bundle install --redownload removed the gem and failed on the checksum (exit 37), or reinstalled the unpatched gem on a lock without CHECKSUMS. Files a record proves patched beside a readable archive that is not a patched artifact's now count as stale. The existing refresh then replaces the dir and the archive with the verified patched gem, or the run warns where it may not (shared gem home, refresh off). The messages say the copy is patched in place and name the archive instead of calling the install unpatched. Fixes #2089 Assisted-by: Claude Code:claude-fable-5-2
Review of the first fix: swapping the whole gem dir would drop what agent mode keeps inside it (a native gem's build marker and its original-build backup), so a later rollback could not restore the prebuilt binaries. The files are already patched; only the archive RubyGems reinstalls from is wrong. The refresh now replaces <home>/cache/<leaf>.gem alone for such a copy and leaves the gem dir as it is. The manual remedy is that one archive, not the specifications entry. The sha256 comparison ignores case and the archive is hashed only when the verdict needs it. The shared-home bullet and the mixed headline no longer call a copy patched in place unpatched. Refs #2089 Assisted-by: Claude Code:claude-fable-5-2
|
[agent] bugbot run Generated by Claude Code |
PR SummaryMedium Risk Overview The stale-install probe now treats “files proved patched by an agent manifest, but the sidecar archive is not a patched artifact” as stale ( Reviewed by Cursor Bugbot for commit d41f8cb. Configure here. |
The contract listed the plain 'still unpatched' headline as the one for gems patched in place. It is the headline when none was; the in-place and mixed headlines follow. Assisted-by: Claude Code:claude-opus-5-5
|
[agent] PR shepherd: review brief What it does Risk: medium. On the agent→hosted path the scan now writes a file in the gem home that it used to leave alone. The write uses the existing staged, sha256-checked archive replacement, and the same policy as before applies: project-local by default, a shared home only with Look here
Verified
Changes I made: none. Open questions: none. Generated by Claude Code |
Main gained the in-tree build products fix (#2108) and the hosted scan's refresh of the archive beside an agent-patched gem (#2103). Both touch files this branch changes; three hunks conflicted, each resolved by keeping both sides. crates/socket-patch-core/src/patch/gem_ext.rs, `recover_interrupted_rebuild_sync`: this branch's `refuse_link(&ext, ..)` (a link, or an extension dir that cannot be probed, is refused) in place of main's unchanged `is_symlink` check, followed by main's new restore of the gem's tree from the snapshot of an interrupted in-place build. crates/socket-patch-cli/src/commands/gem_refresh.rs, `report`: main's two headlines for gems patched in place become arms of this branch's `known` headline, which the count of copies that could not be checked is then added to. The words "the switch to hosted patches" come from `switch`. crates/socket-patch-cli/src/commands/gem_refresh.rs, `stale_after_restore`: this branch's listing of a copy that cannot be judged whether or not its archive is cached, with main's new `in_place: false` field. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
LLM Description written by Claude Code:claude-fable-5-2
Fixes #2089
Summary
A hosted scan over a gem that agent mode had patched in place left the
upstream
.gemin the gem home'scache/, under a lock that now pins thepatched gem.
bundle pristineandbundle install --redownloadreinstallfrom that archive: with a
CHECKSUMSsection Bundler removes the gem andexits 37 (and every later
bundle installfails too), without one itsilently reinstalls the unpatched gem. The run printed no warning.
The scan now replaces that archive with the verified patched one. The gem
dir is not touched: its files are already the patched ones, and agent mode
keeps a native gem's original build inside it. Where the run may not write
(a shared gem home,
--no-gem-install-refresh, an archive it cannot fetchor verify) it warns and names the archive.
Root cause
gem_stale_install_warnings(commands/scan/hosted.rs) judged an installeddir by the agent-mode manifest record when one existed and skipped the
<home>/cache/<leaf>.gemcomparison in that case. The record proves thefiles, but says nothing about the archive RubyGems reinstalls from.
The change
scan/hosted.rs): files a record proves patched, beside areadable archive whose sha256 is not a patched artifact's, are reported as
stale with
StaleGem::in_place. With the patched archive, no readablearchive, or no patched sha256 to compare, the record's verdict stands as
before. The sha256 comparison ignores case, as the refresh's already did.
commands/gem_refresh.rs): anin_placegem's target is itshome archive (
Target::CacheArchive, the existing staged-and-renamedreplacement), under the same policy as an installed copy: project-local
by default, a shared home only with
--gem-refresh-shared. That archiveis not listed with the files to commit.
gems say "patched in place" and name the archive. They never call the
install unpatched, and the delete list is the archive alone.
CLI_CONTRACT.md("Gem stale-install guard") anddocs/ecosystems.md("Ruby gems: gems already installed") describe the new rule.
No core crate change, and nothing in the
npm/,pypi/orgem/wrappersdepends on this.
Evidence
Red first: commit
81b1165holds the tests only; the unit test and bothhermetic e2e tests failed there, and the two real-Bundler capstones failed
with the fix stashed.
scan::hosted::tests::gem_stale_probe_flags_an_upstream_archive_beside_an_in_place_patchgem_refresh::tests::in_place_patched_gems_are_never_called_unpatchede2e_redirect_gem_stale_install::refresh_replaces_the_upstream_archive_beside_an_agent_patched_installrollbackrestores upstream files and archivee2e_redirect_gem_stale_install::an_agent_patched_install_the_run_may_not_replace_is_warned_about--no-gem-install-refresh, shared home,--gem-refresh-sharede2e_redirect_gem_build::gem_hosted_scan_refreshes_an_agent_patched_warm_install(and_with_a_checksums_lock)install,--redownload,pristineand a frozen install all succeed and keep the patchRun locally (Ruby 3.3.6, Bundler 4.0.18):
cargo test -p socket-patch-cli --lib: 948 passed--test e2e_redirect_gem_stale_install: 33 passed--test e2e_redirect_gem_build -- --include-ignored: 46 passed--test e2e_vendor_gem_build,e2e_gem_native_ext_build(--include-ignored),in_process_rollback_hosted,cli: passedcargo clippy --locked --workspace --all-features -- -D warnings(the CI command): clean.--all-targetsreports 37 errors in test helpers onmainas well(
tests/prebuilt_common, duplicatecommonmodules); none is in a filethis PR touches.
CI on
d41f8cb:ci-okandclippygreen, Cursor Bugbot passed with no findings, no open review thread.Review (
/code-review high)The first version replaced the whole gem dir. The review showed that this
would drop agent mode's native-build marker and original-build backup, so
the fix was reworked to replace the archive only. Also fixed from it: the
case-sensitive sha256 comparison, hashing the archive only when the result
is used, the human bullet and mixed headline wording, stale comments, and
the duplicated test fixture (now
common::write_in_place_patch_record).Not changed:
stale_detailkeeps a separate branch for in-place gems. Its sentenceshave another subject and delete list than the two arms below it; folding
them would thread four more variables through those arms.
rollbackthatcannot fetch the upstream gem (
--offline, a gem from a private remote)restores the files from blobs but leaves that archive, and warns
upstream_gem_stale_install. This is what every hosted refresh alreadydoes for a warm install.
Follow-ups (not in this PR)
From the issue's last paragraph: the agent manifest record stays after the
switch, so
socket-patch listshows the gem twice. That is a separatequestion (should the hosted switch migrate the record out?).
https://claude.ai/code/session_011f9aePQWkJCgXswur7SmP6
Generated by Claude Code