Skip to content

Fix gem lock refusal repeated per platform patch (#2436) - #2482

Open
Mikola Lysenko (mikolalysenko) wants to merge 4 commits into
mainfrom
agent/fix-gem-refusal-per-platform-patch
Open

Mikola Lysenko (mikolalysenko) wants to merge 4 commits into
mainfrom
agent/fix-gem-refusal-per-platform-patch

Conversation

@mikolalysenko

@mikolalysenko Mikola Lysenko (mikolalysenko) commented Dec 3, 2026 •

Copy link
Copy Markdown
Collaborator

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

Refs #2436

Summary

On a default Bundler 4 lock, a vendored scan of a project with nokogiri
printed the same platform_gem_unsupported refusal nine times (once for
the patch of the ruby gem and once for each platform gem's patch) and
closed with "9 patches failed" for one gem. It now prints the refusal once
and counts one failure. No file the tool writes changes: the gem was
refused before and is refused now.

Root cause

A vendored run selects one patch per build of a gem that Gemfile.lock
names. A refusal read from the lock is the same for every one of them, but
the download phase (fetch_selected_patches) and the dry-run preview
looked the refusal up per selected patch and reported and counted each.

The change

  • vendor::refusals::repeated_gem_refusals (core) names the patches of a
    gem that are refused with the same code and detail as another patch of
    the gem. The refusal is reported under the ruby gem's patch where that
    one is refused, else under the first in purl order, the same order of
    preference the vendor loop uses for the patch a gem is vendored through.
  • The download phase leaves those patches out: no [error] line, no
    failed event, no count, no view fetch (as before).
  • The dry-run preview drops their rows but keeps them refused for the
    --max-new-patches plan, so none of them takes a slot.
  • An expected skip (vendor_gem_version_not_locked) is not folded and
    stays one line and event per patch, as the contract describes it.
  • CLI_CONTRACT.md and docs/ecosystems.md state the rule.

Behavior change to note: under --json, a gem refused this way now has
one failed event (one skipped event in a dry run) instead of one per
selected patch, and summary.failed counts it once.

Evidence

  • scan_vendor_gem_lock_refusal_is_reported_once_per_gem
    (tests/in_process_vendor.rs, first commit) runs the built binary on a
    gem locked for the ruby platform beside two platform gems with a patch
    for each build. On main it fails with 3 failed events where 1 is
    expected; with the fix it passes and checks the JSON event and count,
    the single [error] line, "Nothing was vendored: 1 patch failed", the
    single [would-refuse] row, the dry-run JSON, and that nothing was
    written.
  • a_gems_refusal_is_reported_under_one_patch (core) covers which patch
    reports, and what is not folded: another gem, version, reason or
    ecosystem, an expected skip, and one purl listed twice.
  • preview_reports_a_gems_refusal_once (cli) covers the preview row, the
    headline count and the rollout plan's refused set.
  • Local runs, all passing: cargo clippy --locked --workspace --all-features -- -D warnings; socket-patch-core vendor::refusals
    tests; socket-patch-cli lib tests (1106); in_process_vendor (157),
    scan_vendor_e2e (43), in_process_gem_multi_platform (9).
    With real Ruby 3.x and Bundler 4.0.18 (--include-ignored):
    e2e_redirect_gem_build (57) and e2e_vendor_gem_build (23).
  • cargo clippy ... --all-targets already fails on main in test code
    under the pinned toolchain (88 errors in socket-patch-core, none in
    the files this PR touches); CI's clippy does not pass --all-targets.

Review

/code-review high found no correctness bug and five nits. Fixed: a purl
listed twice would have dropped its own report; the docs named one code
for a rule that covers every failing gem refusal; expected skips are now
left per patch; a stale doc comment. Not fixed:

  • The dry run does not narrow a gem's patches to the builds the lock names
    or the copy installed, as the wet run does before it reports, so the two
    can name different patches of the gem as the one that reports. That
    difference in narrowing is older than this PR and changing it changes
    which rows a dry run lists.
  • A hosted gem pinned at the selected patch has its takeover refusal left
    to the vendor loop for that one patch. It is not part of the download
    phase's refusals and is not folded here. Not run.

Left of #2436

The issue also reports the re-scan of a gem that is already vendored as
platform gems: one [skip] ... (already vendored) line per platform
patch. Those lines are not refusals (each patch's record is reused by the
vendor step) and are not changed here.

https://claude.ai/code/session_011f9aeQtMahebsTVDgcRvsp


Generated by Claude Code

Refs #2436.

Assisted-by: Claude Code:claude-fable-5-2
A gem that Gemfile.lock locks for the ruby platform beside platform
gems, with a patch for each build, must be refused once: one failed
event, one [error] line, one would-refuse row and a count of one.
Fails on main, which reports the refusal for every patch (#2436).

Assisted-by: Claude Code:claude-fable-5-2
A vendored scan selects a patch for each build of a gem the lock
names, and a refusal read from Gemfile.lock is the same for all of
them. The download phase and the dry-run preview reported it for
every patch and counted each as a failure: nine identical lines for
nokogiri on a default Bundler 4 lock.

The refusal is now reported under one patch of the gem, the ruby
gem's where it is refused, else the first. The other patches stay
refused (not downloaded, no rollout slot) with no line, event or
count of their own.

Refs #2436.

Assisted-by: Claude Code:claude-fable-5-2
Review follow-ups to the once-per-gem refusal: an expected skip
(a gem version the lock does not resolve) keeps its line and event
for each patch, a purl listed twice is not dropped with its own
repeat, and the contract states the rule for every failing gem
refusal, not for one code.

Refs #2436.

Assisted-by: Claude Code:claude-fable-5-2
@mikolalysenko

Copy link
Copy Markdown
Collaborator Author

bugbot run


Generated by Claude Code

@cursor

cursor Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

PR Summary

Low Risk
User-visible output and JSON event counts change for multi-platform gem refusals; logic is scoped to vendored gem failures and is covered by new unit and integration tests.

Overview
When vendored scan/get selects a patch for each platform build of a gem, a lock-derived refusal such as platform_gem_unsupported used to emit one [error], one failed event, and one failure count per patch. The run now reports one refusal for the whole gem.

repeated_gem_refusals (core) marks sibling patches that share the same refusal code and detail. Reporting stays on the ruby platform patch when it is refused, otherwise the first refused patch in purl order. Benign skips (e.g. vendor_gem_version_not_locked) are not folded.

The vendored download phase drops repeat patches from selection so they are not fetched or counted again. The vendor dry-run preview mirrors that (one row / one [would-refuse]) while still treating all refused platform patches in rollout planning. CLI_CONTRACT.md and docs/ecosystems.md document the behavior.

Reviewed by Cursor Bugbot for commit 086034e. Configure here.

@mikolalysenko

Copy link
Copy Markdown
Collaborator Author

[agent] PR shepherd: review brief

What it does
A vendored scan/get of a gem with a patch per platform build (nokogiri on a default Bundler 4 lock) printed the same lock refusal once per patch and counted each as a failure. Now a refusal that is the same code and detail for several patches of one gem version is reported once, under the ruby gem's patch (else the first in purl order), and counts as one failure. The dry-run preview does the same, and still keeps every one of those patches out of --max-new-patches slots.

Risk
Low. Nothing written to disk changes: the gem was refused before and still is. One change you can see: --json now has one failed event (one skipped in a dry run) per gem instead of one per patch, and summary.failed drops to match. Expected skips (refusal_is_benign) and non-gem ecosystems aren't folded.

Look here

  • refusals.rs:307: the folding rule, and which patch reports (L331)
  • [agent_download.rs:1415](https://github.com/SocketDev/socket-patch/blob/086034e1050a4cd88b1877a4e9b3ee8d5f064dcf/crates/socket-patch-cli/src/commands/agent_download.rs#L1415): repeats are dropped from the download selection
  • vendor_flow.rs:412 and [L149](https://github.com/SocketDev/socket-patch/blob/086034e1050a4cd88b1877a4e9b3ee8d5f064dcf/crates/socket-patch-cli/src/commands/scan/vendor_flow.rs#L149): preview rows, while dropped patches stay in the refused set
  • in_process_vendor.rs:3808: end-to-end test on the built binary (it fails on main, according to the description)

Verified

  • Read the whole diff. Refusal order is deterministic (VendorRefusals is a BTreeMap and selection is sorted by purl), so the "first in purl order" unit case can't flake.
  • Refused patches were never fetched before this change either, so dropping them changes no file the tool writes.
  • CHANGELOG.md is untouched. There's no debug code and no unrelated edits.
  • Ran locally: socket-patch-core vendor::refusals tests (18 pass) and preview_reports_a_gems_refusal_once (passes).
  • CI on 086034e: ci-ok and clippy are green, and so are the gem e2e jobs. Bugbot left no findings.

Changes I made
None.

Open questions
None blocking. The description lists two leftovers that are older than this PR: the dry run doesn't narrow to the locked builds the way the wet run does, and already-vendored platform patches still print one [skip] line each.


Generated by Claude Code

@mikolalysenko Mikola Lysenko (mikolalysenko) added the Ready for review Agent-verified: mergeable, CI green, Bugbot clean — awaiting human review label Dec 3, 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

Development

Successfully merging this pull request may close these issues.

2 participants