Skip to content

Fix rollback reinstall note for vendored gems (#2214) - #2215

Merged
Mikola Lysenko (mikolalysenko) merged 5 commits into
mainfrom
agent/fix-rollback-note-vendored-gem
Nov 24, 2026
Merged

Mikola Lysenko (mikolalysenko) merged 5 commits into
mainfrom
agent/fix-rollback-note-vendored-gem

Conversation

@mikolalysenko

@mikolalysenko Mikola Lysenko (mikolalysenko) commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

LLM Description written by Claude Code:claude-fable-5-2

Fixes #2214

Summary

socket-patch rollback of a gem that was only ever vendored ended with "Note: 1 unwired package keeps its patched bytes in installed trees until the next package-manager install", and --json carried reinstall_required. Neither was true: vendored mode never writes to a gem home, so Bundler's own install was the upstream build all along.

After this change rollback leaves a vendored gem out of that count when it can prove the installed copies are the upstream build, and the --json warning is derived from the same count as the human note.

Root cause

Two things in commands/rollback.rs:

  • The note counted every reverted vendored gem except those the unwind refreshed or an in-place rollback restored. A gem whose installed copy was checked and found to be upstream already was in neither set.
  • reinstall_required was pushed whenever anything was unwired, with no filter, so it disagreed with the human note even in cases the note already handled (a refreshed gem, a package restored in place).

The fix

  • gem_refresh::after_vendored_unwind now also reports upstream_installs: the unwound gems that have an installed copy and whose every copy is proven upstream. The proof is two-fold: the archive RubyGems installed the copy from (<home>/cache/<leaf>.gem) has the verified upstream sha256, and every file of the gem's ledger record is in its pre-patch state (verify_file_patch says Ready).
  • Anything short of that keeps the gem in the count, as before: no copy found, a gem from another remote, a pruned cache/, no verified sha256, a ledger entry with no record, a file that is patched, edited or unreadable. The fix only ever removes a warning on positive proof.
  • rollback computes the count once and uses it for both the human note and the --json warning.
  • CLI_CONTRACT.md and docs/ecosystems.md describe the rule.

No change was needed in the npm/, pypi/ or gem/ wrappers.

Behavior change to review

rollback --json no longer emits reinstall_required in the cases where the human run already printed no note: every unwired package was also restored in place (or found original there), or was a gem the unwind refreshed. This affects every ecosystem, not only gems. No existing test expected the warning in those cases.

Evidence

Test Covers On main On this branch
e2e_redirect_gem_stale_install::rollback_of_an_only_vendored_gem_names_no_reinstall #2214, human and --json fails passes
e2e_vendor_gem_build::gem_get_uuid_vendored_fresh_checkout_bundle_install (new rollback step, real Bundler 4.0.18 / Ruby 3.3.6) #2214 end to end fails passes
vendored_unwind_restores_an_install_a_hosted_scan_patched (new assertion) no reinstall_required after a refresh fails passes
rollback_still_names_a_reinstall_for_an_install_it_could_not_judge a gem from another remote keeps the warning passes passes
rollback_never_calls_an_agent_patched_install_upstream a copy patched in place beside the upstream archive keeps the warning passes passes

Local runs:

  • cargo test -p socket-patch-cli --no-fail-fast: 5,671 passed, 5 failed. The five are write-failure tests (in_process_redirect x3, repair x2) that cannot fail a write when run as root, which this sandbox does; none touches rollback or gems. That run predates the last two commits; after them I re-ran the lib tests and the rollback, in_process_rollback_*, mode_migration_vlt, mode_migration_pypi and gem suites, all green.
  • e2e_vendor_gem_build, e2e_redirect_gem_build, e2e_redirect_gem_stale_install with --include-ignored (real Bundler): 20, 55 and 62 passed.
  • cargo clippy --locked --workspace --all-features -- -D warnings (CI's command): clean. --all-targets reports errors on main too, all in files this PR does not touch.
  • e2e_gem needs the live Socket API and could not run here.

Review

/code-review high ran on the first cut and found three cases where the proof was too generous (a copy agent mode patched in place beside the upstream archive, a gem with no copy found, a partly patched copy). All three are fixed in the second commit by requiring the record-file proof and an installed copy. Two findings are not fixed:

  • An only-vendored gem from a remote other than rubygems.org, or one whose gem home has a pruned cache/, still gets the note: nothing proves its copy upstream. This is the old behavior; the docs say when the note is dropped.
  • rollback --dry-run still counts every vendored gem: the gem unwind does not judge installed copies on a dry run. CLI_CONTRACT.md says so.

Bugbot

One finding, fixed in the last commit: a file the patch adds that is present with other content counted as unpatched. is_unpatched now requires such a file to be absent; gem_refresh::tests::is_unpatched_needs_every_record_file_in_its_pre_patch_state covers it.

Follow-ups

  • Found while testing, not changed here: after apply (agent mode) and then standalone vendor of the same gem, rollback removes the manifest record and the vendoring but leaves the installed copy patched. The only trace is this reinstall_required warning, whose advice ("the next package-manager install") does not help with Bundler, which keeps an installed gem. rollback_never_calls_an_agent_patched_install_upstream pins that the warning stays; the leftover copy deserves its own issue.

https://claude.ai/code/session_011f9aeQWcPFYLN6RCQyh8RM


Generated by Claude Code

Refs #2214.

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_011f9aeQWcPFYLN6RCQyh8RM
A gem that was only ever vendored has no patched byte in a gem
home: Bundler loaded it from .socket/vendor. Rollback counted it
as keeping its patched bytes anyway, because only a refreshed or
in-place-restored copy was left out, and --json pushed
reinstall_required whenever anything was unwired.

The vendored gem unwind now reports the gems whose installed
copies are proven to be the upstream build (the archive in the
gem home has the verified upstream sha256 and no recorded patch
is in the files) or that are not installed. Rollback leaves them
out, and derives the --json warning from the same count as the
human note.

Fixes #2214.

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_011f9aeQWcPFYLN6RCQyh8RM
Review found the first cut too generous: a copy agent mode patched
in place sits beside the upstream archive, a gem with no copy found
may live in a gem home this run cannot see, and a partly patched
copy does not hold the whole patch.

A vendored gem is now left out of rollback's reinstall count only
when it has an installed copy and every copy is proven upstream:
its archive has the verified upstream sha256 and every file of the
gem's ledger record is in its pre-patch state.

Refs #2214.

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_011f9aeQWcPFYLN6RCQyh8RM
The get-vendored capstone installs rack with a real Bundler and
vendors it through a detached ledger entry. Roll it back at the
end: the pair is restored byte for byte, Bundler's own install was
upstream all along, and no reinstall_required warning is raised.

Refs #2214.

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_011f9aeQWcPFYLN6RCQyh8RM
@mikolalysenko
Mikola Lysenko (mikolalysenko) marked this pull request as ready for review November 24, 2026 06:07
@mikolalysenko

Copy link
Copy Markdown
Collaborator Author

[agent] bugbot run


Generated by Claude Code

@cursor

cursor Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

PR Summary

Medium Risk
Changes rollback advisory logic across ecosystems (not only gems) and tightens proof requirements before suppressing reinstall warnings—incorrect detection could hide real stale installs.

Overview
Fixes false reinstall_required / "keeps patched bytes" messaging on rollback when a gem was only ever vendored and Bundler’s install was already the upstream build.

Gem unwind now tracks upstream_installs: gems whose every installed copy has a verified upstream archive sha256 and ledger patch files in pre-patch state (verify_file_patch → Ready). Vendored revert passes the full ledger record map (not only detached entries) into after_vendored_unwind for that proof.

Rollback uses one still_patched count for both human notes and JSON: it excludes packages restored in place, hosted-refreshed gems, and vendored gems in upstream_installs (renamed from refreshed_installs / gem_install_upstream). reinstall_required is emitted only when that count is > 0.

Contract and ecosystem docs describe the rule; e2e tests cover only-vendored rollback, unjudged installs, and agent-patched-in-place cases.

Reviewed by Cursor Bugbot for commit a0c0ff2. Configure here.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit a0c0ff2. Configure here.

verify_file_patch says Ready for a file the patch adds when it is
there with other content, since apply overwrites it. For the proof
that an installed gem never got its patch, only the file's absence
counts.

Refs #2214.

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_011f9aeQWcPFYLN6RCQyh8RM
@mikolalysenko

Copy link
Copy Markdown
Collaborator Author

[agent] PR shepherd: review brief for the approver

What it does
After rollback of a gem that was only ever vendored, the CLI no longer prints the "keeps its patched bytes" note or emits reinstall_required when it can prove the installed copy is the upstream build: the cached .gem archive has the verified upstream sha256 and every file in the ledger record is still at its beforeHash (an added file must be absent). The --json warning now comes from the same count as the human note.

Risk
Low to medium. It can only remove a warning, and only when both proofs hold. Anything it can't prove (no copy found, another remote, a pruned cache/, no sha256, no record) keeps the old warning. The one change outside gems: --json no longer emits reinstall_required in cases where the human run already printed no note, such as a package restored in place. That is intended and documented in CLI_CONTRACT.md.

Look here

  • gem_refresh.rs:1297: upstream_installs, the two-part proof. Every copy must pass.
  • gem_refresh.rs:1326: is_unpatched, including the Bugbot fix for added files (L1337).
  • gem_refresh.rs:1515: upstream sha256s are kept only for builds the lock resolves from rubygems.org.
  • rollback.rs:2767: the count moved out of the human-only branch so --json and human output agree.
  • [vendored_backend/mod.rs:238](https://github.com/SocketDev/socket-patch/blob/c1e1834b83a1b067aa586756e8f37c6860d52889/crates/socket-patch-cli/src/commands/vendored_backend/mod.rs#L238): ledger records are now collected for non-detached entries too.

Verified

  • Read the whole diff and the parts of refresh_restored it relies on. Early returns and --no-gem-install-refresh leave upstream_sha256 empty, so those paths fall back to warning. A copy left stale after the refresh fails is_unpatched (or the archive sha check, for a hosted-patched build), so it stays counted.
  • Ran cargo test -p socket-patch-cli --lib -- gem_refresh rollback locally on c1e1834: 81 passed.
  • CI on c1e1834: ci-ok and clippy green, 89 checks, none failing.
  • No conflict with main, no open review threads (the one Bugbot finding is fixed and answered), and CHANGELOG.md is untouched.

Changes I made
None.

Open questions
None blocking. The description's follow-up (agent apply then standalone vendor then rollback leaves a patched installed copy) is worth its own issue.


Generated by Claude Code

@mikolalysenko Mikola Lysenko (mikolalysenko) added the Ready for review Agent-verified: mergeable, CI green, Bugbot clean — awaiting human review label Nov 24, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[agent] Reviewed the installed-gem verification and both rollback outputs. The upstream archive and pre-patch file checks gate suppression of the same reinstall warning in human and JSON output.

Merged via the queue into main with commit 85a011b Nov 24, 2026
89 checks passed
@mikolalysenko
Mikola Lysenko (mikolalysenko) deleted the agent/fix-rollback-note-vendored-gem branch November 24, 2026 15:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Ready for review Agent-verified: mergeable, CI green, Bugbot clean — awaiting human review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

rollback of a gem that was only ever vendored says it "keeps its patched bytes in installed trees", though the gem home never held the patch

3 participants