Skip to content

Fix vendored re-scan of a gem patched in another mode (#2269) - #2274

Open
Mikola Lysenko (mikolalysenko) wants to merge 4 commits into
mainfrom
agent/fix-vendored-scan-gem-patched-in-other-mode
Open

Mikola Lysenko (mikolalysenko) wants to merge 4 commits into
mainfrom
agent/fix-vendored-scan-gem-patched-in-other-mode

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 #2269

Summary

Vendored mode refuses a gem that builds a native extension (native_extensions_unsupported) and tells the user to patch it with --mode hosted or --mode agent. After the user did that, every later scan --mode vendored raised the same refusal, counted the gem as failed and as "left to patch", and exited 1. A stock Rails Gemfile has such gems (json, puma, bootsnap, racc), so every vendored Ruby project ended up there.

Such a gem is now a skip, vendor_gem_patched_in_other_mode:

Skipping pkg:gem/json@2.9.1: json builds a native extension, which vendored mode cannot vendor; it stays patched in hosted mode (patch <uuid>)

The run exits 0 when nothing else failed, the closing totals count the gem as patched, and nothing is written: the hosted pin, the manifest record and the installed copies stay as they were.

Root cause

The vendor loop had two outcomes for a backend refusal: one of a fixed list of benign codes (a skip), or a failure. It had none for "the remedy this refusal names is already in place".

The change

  • crates/socket-patch-cli/src/commands/vendor.rs: a backend refusal with native_extensions_unsupported goes through settle_gem_refusal. It becomes the skip when the gem holds the patch the run selected:
    • hosted: the lock still pins that patch uuid. live_pin is cleared when this run's restore of the upstream entry stands, so a gem the takeover left un-hosted is never called hosted.
    • agent: the manifest records that patch uuid for the gem.
    • in both cases every installed copy the crawl finds must hold the patch: a hosted copy by its files, a copy patched in place by the verdict vex and apply --check use (rebuilt extension included).
  • crates/socket-patch-core: the two code constants, the skip in refusal_is_benign, and gem_copies_patched_in_place over the existing every-copy gem verdict.
  • The closing lines of scan count the skip as a patch in place, like already_vendored.
  • CLI_CONTRACT.md (code table) and docs/ecosystems.md ("Ruby gems: gems vendored mode refuses") describe the skip and when the refusal still stands.

What still fails, on purpose (do no harm: never report a gem as patched that isn't):

  • a native gem patched in no mode;
  • one that holds a different patch from the one the scan selects (the existing vendored_takeover_of_a_superseded_native_gem_names_the_extension test keeps this);
  • a manifest record whose patch is not in the installed copy, or one unpatched copy beside a patched one;
  • a hosted pin whose installed copy is still the upstream gem.

In each of these the refusal's own remedy, followed, puts the patch in place, and the next vendored scan skips the gem.

Evidence

Tests, all in crates/socket-patch-cli/tests/e2e_redirect_gem_stale_install.rs. The first commit adds them failing; the fix turns them green.

Test Covers
vendored_scan_skips_a_native_gem_that_holds_the_patch_in_hosted_mode #2269, hosted remedy: scan --mode vendored twice (JSON), a human run ("Nothing left to patch", no error), and get <uuid> --mode vendored; the pair and the gem home are byte-identical
vendored_scan_skips_a_native_gem_that_holds_the_patch_in_agent_mode #2269, agent remedy: the same, and the manifest record stays
vendored_scan_still_refuses_a_native_gem_that_is_not_patched the four cases above that still fail with native_extensions_unsupported
a_gem_patched_in_another_mode_is_a_skip_and_its_refusal_is_not (core, vendor/refusals.rs) the skip is benign, the refusal is not

Run locally (Ruby 3.3.6, Bundler 4.0.18):

  • cargo clippy --locked --workspace --all-features -- -D warnings (CI's command): clean.
  • cargo test -p socket-patch-core --lib: 8642 passed. cargo test -p socket-patch-cli --lib: 1076 passed.
  • e2e_redirect_gem_stale_install: 70 passed. in_process_vendor: 156 passed. e2e_gem_native_ext_build: 43 passed. in_process_gem_apply, e2e_gem: passed.
  • e2e_vendor_gem_build -- --ignored (real Bundler): 13 passed.
  • cargo clippy ... --all-targets reports lints in test files this PR does not touch (crawler_ruby_e2e.rs, prebuilt_common/mod.rs and others); they are there without this change too, and CI's clippy does not lint test targets.

Review

/code-review high ran on the diff. Fixed: the agent verdict read one installed copy only; a hosted pin counted as patched over a stale install; one place still used the code as a literal; the doc named --mode hosted as the remedy for every case.

Not fixed here, because each is a different refusal path that fails the same way before this PR and needs its own decision:

  • A hosted gem declared inside a group block fails every vendored scan with gemfile_declaration_not_editable (raised before the takeover and in the download phase). The same holds for platform_gem_unsupported. The docs group these with the native-extension refusal, so they probably want the same skip.
  • On a checkout with no gems installed, a hosted native gem fails with vendor_prebuilt_required (the service serves no stub for a native gem), not native_extensions_unsupported.
  • With a CHECKSUMS lock and the gem registry unreachable, the takeover's restore fails with redirect_revert_failed before the backend is asked.
  • The dry run of scan / get --mode vendored previews a native gem as "would vendor"; it previews neither the refusal nor this skip (existing behavior, and the contract row says so).

For the reviewer to decide

  • The skip applies to every vendored entry point (scan, get, vendor), as refusal_is_benign documents for the other skips. get <gem> --mode vendored on such a gem therefore exits 0 with the "Skipping" line instead of 1. If an explicit get should keep failing, the conversion can be limited to scan.

Bugbot

One finding (the dry run of a hosted native gem would fail where the real run skips). Answered in its thread and resolved: no command reaches that branch for a hosted gem. vendor --dry-run takes the eject plan, and scan / get --dry-run are answered by the scan preview, which exits 0.

CI

hosted-e2e (and with it ci-ok) fails on every PR until #2270 lands: production published a new activestorage 6.0.3 patch that is not in the test's pinned set. That is not from this change.

https://claude.ai/code/session_011f9aeNf7JPkrSosgqVrSyG


Generated by Claude Code

Refs #2269. A vendored scan fails on every run for a gem it refuses
to vendor even after the gem holds its patch in the mode the refusal
names.

Assisted-by: Claude Code:claude-fable-5-2
A gem with a native extension that holds the selected patch in hosted
or agent mode should be a skip of scan --mode vendored, not a failure
on every run (#2269). Both tests fail today; the third pins that a
native gem patched in no mode is still refused.

Assisted-by: Claude Code:claude-fable-5-2
Vendored mode refuses a gem that builds a native extension and names
hosted or agent mode as the way to patch it. The vendor loop had no
outcome for a gem that already holds the selected patch there, so
every later scan --mode vendored raised the refusal again, counted
the gem as failed and as left to patch, and exited 1.

A gem refused with native_extensions_unsupported is now the skip
vendor_gem_patched_in_other_mode when the lock still pins the same
patch hosted, or the manifest records it and the installed copy holds
it as agent mode leaves it. The closing totals count it as patched.
A native gem that holds another patch, or none, is refused as before.

Fixes #2269

Assisted-by: Claude Code:claude-fable-5-2
Review of the skip found two cases it should not cover. The agent
verdict read one installed copy, where vex and apply --check judge
every copy, so an unpatched copy in the tree of another Ruby was
skipped as patched. And a hosted pin counted on its uuid alone, so a
pin over an install that is still the upstream gem closed the scan
with "Nothing left to patch".

The skip now needs every installed copy of the gem to hold the patch:
a hosted copy by its files, a copy patched in place by its rebuilt
extension as well. Otherwise the refusal stands as before. The second
place that raises native_extensions_unsupported uses the constant.

Refs #2269

Assisted-by: Claude Code:claude-fable-5-2
@mikolalysenko
Mikola Lysenko (mikolalysenko) marked this pull request as ready for review November 26, 2026 06:05
@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
Touches gem vendor refusal handling and patch verification across installed copies; behavior change is narrow (native gems only) but affects exit codes and scan totals for real Ruby projects.

Overview
Vendored mode no longer treats native-extension gems as failures on every re-scan after they’re already patched in hosted or agent mode. When the backend would refuse with native_extensions_unsupported, settle_gem_refusal checks whether the selected patch is already in place (lock pin or manifest, and every crawled install copy verified like vex/apply --check), and downgrades that case to the benign skip vendor_gem_patched_in_other_mode (exit 0, counted as patched in closing totals).

Adds gem_copies_patched_in_place, wires live_pin so a takeover that drops the hosted pin isn’t misclassified, documents the new reason in CLI_CONTRACT and ecosystems.md, and adds e2e coverage for hosted/agent skips vs. cases that still fail.

Reviewed by Cursor Bugbot for commit 53a6a67. Configure here.

@mikolalysenko

Copy link
Copy Markdown
Collaborator Author

[agent] hosted-e2e failed on 53a6a67, and it is not from this change: it is #2270.

The only failing test is gem_bundler_hosted_install_proof in e2e_hosted_production.rs (15 passed, 1 failed, on all three in-job attempts): production wired patch 146ef6aa-f43e-42aa-9891-0983435220e2 for pkg:gem/activestorage@6.0.3, which is not in the pinned GEM_UUIDS set. This PR does not touch that test or hosted mode's pin selection, and the same failure is on #2261 and #2266.

ci-ok will stay red here until #2270 lands. After that, hosted-e2e needs a re-run on this PR.


Generated by Claude Code

@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 53a6a67. Configure here.

@mikolalysenko

Copy link
Copy Markdown
Collaborator Author

[agent] PR shepherd: review brief for the approver

What it does
A gem with a native extension that vendored mode refuses, and that the user already patched in hosted or agent mode as the refusal told them to, no longer fails every later scan --mode vendored. It becomes the benign skip vendor_gem_patched_in_other_mode (exit 0, counted as patched), but only when the lock pins (hosted) or the manifest records (agent) the selected patch uuid and every installed copy verifies as patched. Fixes #2269.

Risk: medium. A refusal that used to exit 1 now exits 0, so a wrong match would report an unpatched gem as patched. That is guarded by checking every crawled copy (verify_patch_record for hosted, the vex/apply --check gem verdict for agent); a different uuid, no patch, or any unpatched copy still refuses. Nothing is written on the skip path.

Look here

  • vendor.rs:221 gem_patch_held_in: the hosted/agent decision and the every-copy check
  • vendor.rs:4019 live_pin, cleared where the takeover's restore of the upstream entry is settled, so a gem the run left un-hosted is never called hosted
  • vendor.rs:4397 where a backend refusal is turned into the skip
  • verify.rs:565 gem_copies_patched_in_place
  • [e2e_redirect_gem_stale_install.rs:5997](https://github.com/SocketDev/socket-patch/blob/53a6a67ce02ee968bef398d41fd95ec4a400b8ae/crates/socket-patch-cli/tests/e2e_redirect_gem_stale_install.rs#L5997) the cases that must still be refused

Verified

Changes I made: none.

Open questions: none.


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 26, 2026
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