Skip to content

Fix vendoring a hosted gem whose patch was superseded (#2129) - #2143

Merged
Mikola Lysenko (mikolalysenko) merged 5 commits into
mainfrom
agent/fix-gem-takeover-superseded-hosted-patch
Nov 19, 2026
Merged

Mikola Lysenko (mikolalysenko) merged 5 commits into
mainfrom
agent/fix-gem-takeover-superseded-hosted-patch

Conversation

@mikolalysenko

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

Copy link
Copy Markdown
Collaborator

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

Fixes #2129

Summary

A gem on a hosted patch has that patch's bytes installed. Once a newer
patch is published for the same version, scan --mode vendored (and
get <uuid> --mode vendored) failed with package_not_installed /
"no installed package found on disk" and exit 1, though the gem is
installed and --dry-run previewed success. The gem is now vendored at
the newer patch, as it already was on a checkout with no gems installed.

Root cause

The vendor loop judges each candidate of a release-variant ecosystem with
a variant probe (CandidateGates::judge in
crates/socket-patch-cli/src/commands/vendor.rs): it hashes one patch
target in the installed dir against the record. The installed copy holds
the older hosted patch's bytes, which match neither the before nor the
after hash of the newer record, so the candidate was skipped and later
reported as not installed. PyPI got an exemption for a live hosted pin in
#1713. Gems were left out because the gem backend reads the installed
dir to refuse a platform gem.

Fix

A sole gem candidate that the lockfiles still pin hosted passes a failed
probe and keeps its installed dir as the source (hosted_gem_install).
That is safe because the gem backend takes no file from the installed
dir: the vendored copy is always the patch service's build, verified
against the record's after hashes. The backend still reads the dir's name
and its gemspec, so a platform gem or a gem with a native extension is
refused for what it is instead of "not installed". The PyPI path (a
stand-in source) is unchanged.

No file under docs/ or CLI_CONTRACT.md changes: docs/ecosystems.md
already says vendoring a hosted gem works and leaves installed copies
alone.

Evidence

Test Covers
e2e_redirect_gem_stale_install::vendored_takeover_of_a_hosted_gem_whose_patch_was_superseded #2129 for scan --mode vendored and get --mode vendored: dry run, real run (pair wired to the newer uuid, vendored copy is the newer patch, gem home untouched), and a no-op re-run
e2e_redirect_gem_stale_install::vendored_takeover_of_a_superseded_native_gem_names_the_extension the native-extension half of #2129: native_extensions_unsupported, hosted pin kept
vendor::plan_gate_tests::judge_sends_a_hosted_gem_on_from_its_installed_dir the gate: unpinned is skipped; pinned goes on from the installed dir, with or without an older ledger entry
vendor::plan_gate_tests::hosted_pin_keeps_a_gem_install_as_the_source the predicate: sole candidate, pinned, gem only

The two end-to-end tests were committed first and failed with
package_not_installed (commit 81d12e1); they pass after abff7a2.

Local runs (Ruby 3.3.6, Bundler 4.0.18):

  • cargo test -p socket-patch-cli --lib: 957 passed
  • cargo test -p socket-patch-cli --test e2e_redirect_gem_stale_install: 54 passed
  • cargo test -p socket-patch-cli --test e2e_redirect_gem_build --test e2e_vendor_gem_build -- --ignored: 48 and 11 passed
  • cargo clippy --locked -p socket-patch-cli --all-features -- -D warnings (CI's form): clean.
    With --all-targets clippy reports errors in files this PR does not
    touch (tests/prebuilt_common/mod.rs, tests/common/mod.rs,
    src/commands/vendored_backend/repair.rs test code); none is in the
    two changed files.

Review (/code-review high)

No correctness finding. Applied: the judge-level unit test, and the
suite's API mocks now take the patch uuid so the newer-patch fixture
reuses them. Not applied, with reasons:

  • A hosted gem with several variant records (for example
    ?platform=ruby beside a native platform record) is still skipped when
    its installed copy is superseded. The hosted pin names no variant, so
    picking one needs its own rule; the sole-candidate limit is the same
    one PyPI has and never vendors a wrong variant.
  • The dry run previews no native-extension refusal for a hosted gem
    (superseded or not): the scan preview checks only the manifest and
    Gemfile declaration refusals. The real run refuses and keeps the hosted
    pin. This predates the PR and is a follow-up.
  • Plain vendor (eject) vendors the uuid the lock pins and is unchanged.

https://claude.ai/code/session_011f9aeT7HWFSwgbuzoQv6kJ


Generated by Claude Code

Refs #2129. Empty commit that opens the draft PR; the failing test
and the fix follow.

Assisted-by: Claude Code:claude-fable-5-2
Two failing hermetic cases for #2129: a hosted-pinned gem whose
installed copy holds an older patch's bytes must be vendored at the
newer patch, and a native gem in that state must be refused for its
extension. Both report package_not_installed today.

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_011f9aeT7HWFSwgbuzoQv6kJ
A gem on a hosted patch has that patch's bytes installed. Once a newer
patch is published, those bytes match neither side of the new record,
so the vendored variant probe skipped the gem and the run reported it
as package_not_installed, though it is installed and the dry run
previewed success.

A sole gem candidate under a live hosted pin now passes the probe with
its installed dir as the source. The gem backend takes no file from
that dir (the copy is the service's build) and still reads its name and
gemspec, so a platform gem or a native extension is refused for what it
is. PyPI got the matching exemption earlier.

Fixes #2129

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_011f9aeT7HWFSwgbuzoQv6kJ
Review follow-ups: a unit test drives CandidateGates::judge for a
hosted-pinned gem (with and without an older ledger entry), and the
suite's API mocks take the patch uuid so the newer-patch fixture reuses
them instead of copying them.

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_011f9aeT7HWFSwgbuzoQv6kJ
@mikolalysenko
Mikola Lysenko (mikolalysenko) marked this pull request as ready for review November 19, 2026 01:46
@mikolalysenko

Copy link
Copy Markdown
Collaborator Author

[agent] bugbot run


Generated by Claude Code

@cursor

cursor Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

PR Summary

Medium Risk
Changes vendor candidate gating for hosted Rubygems pins—affects lock wiring and whether installs are skipped or sourced from disk—but stays scoped to sole-candidate hosted gems with existing backend safety checks.

Overview
Fixes #2129 so a hosted-pinned gem whose on-disk install still carries an older patch’s bytes can be vendored after the service publishes a newer patch, instead of being skipped by the variant probe and reported as package_not_installed.

The vendor judge now treats sole hosted gem candidates like PyPI: a new hosted_gem_install gate lets a failed probe continue using the installed directory as the source (the backend still inspects name/gemspec for platform/native refusals). superseded_install no longer covers that gem case.

Coverage adds unit tests for the predicate and judge path, plus e2e scenarios for scan/get --mode vendored takeover and native-extension refusal, with mock API helpers parameterized by patch uuid.

Reviewed by Cursor Bugbot for commit 2f618d2. Configure here.

@mikolalysenko

Copy link
Copy Markdown
Collaborator Author

[agent] PR shepherd: review brief for the approver

What it does
Fixes #2129. A gem on a hosted patch, whose installed copy holds that patch's bytes, could not be switched to vendored mode once a newer patch was published for the same version: the variant probe saw bytes that match neither side of the newer record and the run reported "no installed package found on disk" (exit 1) while --dry-run previewed success. Now a sole gem candidate the lockfiles still pin hosted passes that probe and keeps its installed dir as the source, so it vendors the newer patch.

Risk
Low. The exemption is narrow (gem, sole candidate, live hosted pin) and it can't vendor wrong bytes: the gem backend builds the vendored copy only from the patch service's artifact (materialise_patched_copy → gem_service_copy), checked against the record's after hashes. The installed dir is read only for its name and gemspec, so platform gems and native extensions are still refused, now with their real reason. PyPI's stand-in path is unchanged.

Look here

  • vendor.rs:2889: the hosted_gem_install predicate
  • vendor.rs:3025: the gate in CandidateGates::judge, asked before the PyPI superseded_install check
  • gem.rs:1138 (unchanged): the copy comes from the service only, which is what makes this safe
  • [e2e_redirect_gem_stale_install.rs:4261](https://github.com/SocketDev/socket-patch/blob/2f618d278e8917ce635fd1b80f01eb35c91d2ade/crates/socket-patch-cli/tests/e2e_redirect_gem_stale_install.rs#L4261) and [:4343](https://github.com/SocketDev/socket-patch/blob/2f618d278e8917ce635fd1b80f01eb35c91d2ade/crates/socket-patch-cli/tests/e2e_redirect_gem_stale_install.rs#L4343): the end-to-end tests for scan/get --mode vendored and the native-extension refusal

Verified

Changes I made
None.

Open questions
None blocking. The description names two follow-ups it leaves out on purpose: a hosted gem with several variant records is still skipped, and the dry run doesn't preview the native-extension refusal (that predates this PR).


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 19, 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 at 2f618d2. Letting a sole hosted-pinned candidate past a failed variant probe is safe: the installed dir feeds only the name and gemspec refusals in gem_prelude, and materialise_patched_copy builds the vendored copy from the service build checked against the after hashes. Multi-variant gems stay excluded and the refusal and symlink gates still run. Non-blocking: a dry run still previews no native-extension refusal for a hosted gem (unchanged by this PR).

Merged via the queue into main with commit 20150bd Nov 19, 2026
83 checks passed
@mikolalysenko
Mikola Lysenko (mikolalysenko) deleted the agent/fix-gem-takeover-superseded-hosted-patch branch November 19, 2026 14:54
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

3 participants