Skip to content

Fix revert of a vendored gem after a platform is removed (#2283) - #2291

Open
Mikola Lysenko (mikolalysenko) wants to merge 4 commits into
mainfrom
agent/fix-gem-revert-removed-platform
Open

Mikola Lysenko (mikolalysenko) wants to merge 4 commits into
mainfrom
agent/fix-gem-revert-removed-platform

Conversation

@mikolalysenko

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

Copy link
Copy Markdown
Collaborator

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

Fixes #2283

Summary

A gem vendored from prebuilt platform gems (sqlite3, nokogiri, thruster) could not be rolled back or removed once a platform was taken out of the lock with bundle lock --remove-platform. That command is the remedy socket-patch itself prints for a platform gem it cannot vendor, so a default Rails 8 app runs into it. rollback, remove and vendor --revert all refused the gem as drifted, and the remedy they named (re-run scan --mode vendored) changed nothing.

With this change the revert treats a platform that Bundler removed as having nothing to restore. It puts back the entries of the platforms that are still locked. The result is byte for byte the lock Bundler writes for the same removal on the unvendored lock.

Root cause

The ledger records one spec block and one CHECKSUMS line per platform the lock held when the gem was vendored. bundle lock --remove-platform drops a platform's spec entry and its CHECKSUMS line together. The revert in crates/socket-patch-core/src/vendor/gem.rs assumed the lock still held every recorded platform:

  • revert_lock_checksum_record found neither the bare line vendor wrote nor the registry line it replaced, and reported drift. This is the refusal in the issue.
  • revert_lock_text put every recorded spec block back, including the removed platform's. On a lock without CHECKSUMS the revert went through and re-added builds for platforms the lock no longer names.
  • lock_record_converged wanted every recorded block back before it called a hand-restored pair converged.

The fix

One function, removed_platforms, decides which recorded platform builds Bundler has removed, and all three places use it. A build counts as removed only when all of this holds:

  • the record is of platform builds (never a plain name (version) entry);
  • the lock holds neither a spec entry nor a CHECKSUMS line for the build;
  • every spec entry and CHECKSUMS line of the gem that is in the lock is one the record names;
  • the lock still holds at least one spec entry of the record.

Any other lock is judged exactly as before, so a hand edit, a respelled platform or an unparseable line is still drift and nothing is written.

Evidence

Real Bundler 4.0.18 and sqlite3 2.10.2 (ten platform builds) against the repository's stand-in patch service (tests/nokogiri/patch_service.rb): vendor, bundle lock --remove-platform x86-linux-gnu x86-linux-musl, frozen install, then the command.

Command main this branch
rollback "Kept vendored state … lockfile wiring drifted" exit 0, lock identical to Bundler's own lock for that removal, frozen install passes
remove pkg:gem/sqlite3@2.10.2 exit 1, "drift-kept" exit 0, same lock, frozen install passes
vendor --revert "Kept 1 drifted package" exit 0, same lock
rollback on a lock without CHECKSUMS exit 0, the two removed builds come back exit 0, lock identical to Bundler's

Hosted mode already handled the same removal and is unchanged.

Tests, each failing before the fix commit:

  • a_platform_removed_from_the_lock_reverts_without_it (unit, with and without CHECKSUMS): the case in Vendored platform gem cannot be rolled back or removed after bundle lock --remove-platform on a lock with CHECKSUMS, and the named re-scan remedy changes nothing #2283.
  • a_restored_lock_without_a_removed_platform_has_converged (unit): a pair already back on the registry without the platform.
  • gem_vendor_platform_gems_fresh_checkout_bundle_install_and_revert (e2e_vendor_gem_build): a new step drops a platform with the real Bundler, installs frozen, and compares rollback with that Bundler's lock for the same removal. Run locally on Bundler 2.3.27, 2.4.22, 2.5.23, 2.6.9, 2.7.2 and 4.0.18. Bundler older than 2.5 keeps a removed platform's spec entries, and the step compares against whatever that Bundler writes.
  • a_half_removed_platform_is_restored_or_drift (unit): pins what must not change. It holds the three locks from the review below.

Local checks: cargo clippy --locked -p socket-patch-core -p socket-patch-cli --all-features -- -D warnings clean, 8,644 core lib tests pass, e2e_vendor_gem_build 20 of 20 with --include-ignored, rustfmt --check on the touched files.

Review

/code-review high on the first version of the fix found three locks it wrongly read as a removed platform: another build of the gem in the removed one's place, a lock with no build of the gem left, and lines of the gem that do not parse. All three are fixed in the last commit and pinned as drift.

Behavior change to know about

On a lock without a CHECKSUMS section, main already reverted after a platform removal, and re-added the removed platform's spec entries. The revert now leaves them out, which is what Bundler 2.5 and later write.

CLI_CONTRACT.md (the gem CHECKSUMS wiring row) and docs/ecosystems.md (the vendored platform-gem row) say so.

Not in this PR

https://claude.ai/code/session_011f9aeRdzAqnWS27Kgayqvw


Generated by Claude Code

Refs #2283.

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_011f9aeRdzAqnWS27Kgayqvw
Three tests for a gem vendored as platform gems whose lock lost a
platform to `bundle lock --remove-platform`. Two fail today: the
revert of the wired pair, and the revert of a pair that is already
back on the registry. The third pins what stays as it is.

Refs #2283.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011f9aeRdzAqnWS27Kgayqvw
Assisted-by: Claude Code:claude-fable-5-2
A gem vendored as platform gems records one spec block and one
CHECKSUMS line per platform the lock held. `bundle lock
--remove-platform` drops a platform's spec and its CHECKSUMS line
together, and the revert read the missing line as drift: rollback,
remove and `vendor --revert` kept the gem wired, and the remedy they
name (a re-scan) changed nothing.

A platform the lock holds nothing of any more now has nothing to
restore. The lock record puts back the blocks of the platforms still
locked, the checksum record skips the removed platform's line, and a
pair that is already back on the registry without the platform has
converged. The reverted lock is the one bundler writes for the same
removal on the registry lock. A lock that keeps the platform's spec
or a CHECKSUMS line for it is judged as before.

The platform-gem capstone drops a platform from a copy of the
vendored project with the real bundler and compares the rollback
with bundler's own lock for that removal.

Fixes #2283.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011f9aeRdzAqnWS27Kgayqvw
Assisted-by: Claude Code:claude-fable-5-2
Review of the previous commit found three locks it read as a removed
platform that are not one: another build of the gem in the removed
one's place (a respelled platform), a lock with no build of the gem
left, and lines of the gem the entry grammar does not read. Each
made the revert drop a spec or leave a CHECKSUMS line behind and
report success.

One decision now serves the lock record and the checksum record. A
platform counts as removed only when every spec entry and CHECKSUMS
line of the gem in the lock is one the record names, and the lock
still holds a spec entry of the record. Anything else is judged as
before this fix. The three locks are pinned as drift.

Refs #2283.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011f9aeRdzAqnWS27Kgayqvw
Assisted-by: Claude Code:claude-fable-5-2
@mikolalysenko
Mikola Lysenko (mikolalysenko) marked this pull request as ready for review November 26, 2026 22:16
@mikolalysenko

Copy link
Copy Markdown
Collaborator Author

bugbot run


Generated by Claude Code

@cursor

cursor Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

PR Summary

Medium Risk
Changes gem lockfile revert/rollback semantics for multi-platform vendored gems; incorrect detection could still mis-classify drift vs. intentional platform removal.

Overview
Fixes #2283: gem rollback, remove, and vendor --revert no longer treat a platform dropped via bundle lock --remove-platform as lockfile drift for vendored platform gems.

Core (gem.rs): Adds removed_platforms (and locked_spec_block) to detect platforms Bundler removed after vendoring (spec + CHECKSUMS gone together, with guards so hand-edits, respelled platforms, or missing gem entries still count as drift). Revert paths—revert_lock_text, revert_lock_checksum_record, and lock_record_converged—only restore platforms still present in the lock, matching the registry lock Bundler would write for the same removal (no re-adding removed spec/CHECKSUMS lines).

Tests: New unit cases for removal, convergence, and half-removed drift; platform-gem e2e runs bundle lock --remove-platform, frozen install, then rollback against Bundler’s reference lock.

Docs: CLI_CONTRACT.md, docs/ecosystems.md state removal-after-vendoring is allowed without revert-first.

Reviewed by Cursor Bugbot for commit 2343c18. 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.

✅ 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 2343c18. Configure here.

@mikolalysenko

Copy link
Copy Markdown
Collaborator Author

[agent] ci-ok is red on 2343c18 only because of hosted-e2e, and that failure is not from this change.

gem_bundler_hosted_install_proof fails on all 3 attempts with "the redirect wired patch 146ef6aa-f43e-42aa-9891-0983435220e2, which is not in the pinned any-of set". That is #2270: production published a new patch for activestorage 6.0.3 that GEM_UUIDS does not list yet. It fails the same way on main and on every open PR. This diff touches the vendored gem revert and none of the hosted code.

Every other check passed, clippy included, and Bugbot found nothing. Once #2270 is fixed on main, a re-run of hosted-e2e is all this PR should need.


Generated by Claude Code

@mikolalysenko

Copy link
Copy Markdown
Collaborator Author

[agent] PR shepherd: review brief for the approver

What it does. After bundle lock --remove-platform, a gem that was vendored as platform gems (sqlite3, nokogiri) could not be rolled back or removed, because the revert read the missing platform as drift. Now a platform that Bundler removed counts as having nothing to restore. The revert puts back only the platforms that are still locked, and the result matches the lock Bundler itself writes for that removal.

Risk: low. The change only affects the gem vendored-revert path. The new removed_platforms check is narrow: the record must be all platform builds, every line of the gem in the lock must be one the record names, and at least one recorded spec must remain. Any other lock is judged exactly as before, so a hand edit, a respelled platform or an unparseable line is still drift. One behavior change: on a lock without CHECKSUMS, the revert no longer re-adds the removed platform's spec entries. That matches Bundler ≥ 2.5.

Look here

Verified

Changes I made: none.

Open questions: none. Once #2280 lands, hosted-e2e needs a re-run (or a merge from main) before the queue will take this PR.


Generated by Claude Code

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

2 participants