Skip to content

Fix left-to-patch count of a platform-only gem (#2181) - #2187

Merged
Mikola Lysenko (mikolalysenko) merged 3 commits into
mainfrom
agent/fix-gem-platform-lock-left-to-patch
Nov 20, 2026
Merged

Mikola Lysenko (mikolalysenko) merged 3 commits into
mainfrom
agent/fix-gem-platform-lock-left-to-patch

Conversation

@mikolalysenko

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

Copy link
Copy Markdown
Collaborator

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

Fixes #2181

Summary

A hosted or vendored scan that refuses a gem which Gemfile.lock
holds only as precompiled platform builds (the default nokogiri lock)
now counts that gem's advisories as left to patch. Before, a run that
patched another gem ended with Nothing left to patch., and a run that
patched nothing printed no totals, while the refused gem was still
vulnerable.

Before, for a project with nokogiri (refused) and rack (patched):

Patched 1 package, fixing 1 vulnerability (1 high).
Nothing left to patch.

After, the last line reads
1 vulnerability left to patch: 1 is in packages this run did not patch.

Only the closing totals change. No file is written differently, and exit
codes and --json are unchanged.

Root cause

The totals skip a package that the project's lockfile does not name: it
is a copy installed on the machine that the project does not use. The
set of locked packages came from the lockfile inventory, and that
inventory leaves out a gem the Bundler lock holds only as platform
builds (nokogiri (1.18.10-x86_64-linux-gnu), with no plain
nokogiri (1.18.10) entry). Such a gem was taken for a copy outside the
project and never counted.

The fix

  • scan/discovery.rs: the lockfile supplement now carries the
    platform-only gems of the lock in every mode (platform_gems). As
    before, only a hosted run adds them to the lockfile-only packages it
    looks up.
  • scan/mod.rs: the set of locked packages behind the totals is the
    inventory plus those gems.

CLI_CONTRACT.md already describes this behavior ("'Left to patch'
counts the advisories of every package a patch was offered for that this
run did not fix"), so it needs no change. The npm/, pypi/ and
gem/ wrappers are not affected.

Evidence

Check Result
New test refused_platform_gem_is_counted_as_left_to_patch (suite e2e_redirect_gem_stale_install), before the fix fails in both arms: hosted prints no totals, vendored prints Vendored 0 packages; 1 skipped. and no totals
The same test, after the fix passes: both arms end with 1 vulnerability left to patch: 1 is in packages this run did not patch.
cargo test -p socket-patch-cli --test e2e_redirect_gem_stale_install --test scan 59 and 267 passed
cargo test -p socket-patch-cli --lib 1024 passed
cargo clippy --locked -p socket-patch-cli --all-features -- -D warnings (CI's command) clean
Bundler suites e2e_redirect_gem_build, e2e_vendor_gem_build with --include-ignored (Ruby 3.3.6, Bundler 4.0.18) 55 and 20 passed

The test covers #2181 in hosted mode (the gem is read from the lock
alone) and in vendored mode (the installed platform copy is read). It
uses a lock with a plain gem beside the platform-only one, as a real
nokogiri lock has racc.

cargo clippy --all-targets fails on main too, in test code this PR
does not touch (type_complexity and a module loaded twice in the
shared test helpers). CI's clippy job does not pass --all-targets.

The e2e_gem suite needs the live patch API, which this sandbox
cannot reach, so it was not run locally; CI runs it.

Review

/code-review high found no defect in the change. I fixed its one test
finding (the vendored arm passed without the installed copy). It also
named two gaps that exist on main and are left out of this PR:

  • apply and the prune GC of a global scan decide what the project's
    lock resolves from the same inventory, so they also miss a gem locked
    only as platform builds. I did not reproduce a user-visible failure.
  • A vendored scan of a fresh checkout (nothing installed) does not look
    up a gem locked only as platform builds, so it reports nothing for it.
    Whether vendored mode should read such a gem from the lock alone is a
    behavior question for a maintainer.

https://claude.ai/code/session_011f9aeSWDdLUDci7zLLrvTj


Generated by Claude Code

Empty commit that opens the draft pull request for #2181.

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_011f9aeSWDdLUDci7zLLrvTj
The closing totals of a hosted or vendored scan leave out a package
the lockfile does not name. The set of locked packages came from the
lockfile inventory, which omits a gem the Bundler lock holds only as
precompiled platform builds. A refused gem of that kind was taken for
a copy the project does not use, and a run that patched another gem
ended with "Nothing left to patch."

The lockfile supplement now carries those gems in every mode, and
the totals count them as locked.

Fixes #2181

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_011f9aeSWDdLUDci7zLLrvTj
The lookup mock now answers only a run that asks about the gem, so
the vendored arm fails without the installed platform copy, and each
arm asserts its own refusal message. The supplement's comment no
longer says what vendored mode can patch.

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_011f9aeSWDdLUDci7zLLrvTj
@mikolalysenko
Mikola Lysenko (mikolalysenko) marked this pull request as ready for review November 20, 2026 17:47
@mikolalysenko

Copy link
Copy Markdown
Collaborator Author

bugbot run


Generated by Claude Code

@cursor

cursor Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

PR Summary

Low Risk
Narrows scan reporting logic for Bundler platform-only gems; behavior change is limited to closing totals with no changes to patching, exit codes, or JSON output per the PR.

Overview
Fixes incorrect "left to patch" closing totals when a hosted or vendored scan refuses a gem that Gemfile.lock lists only as precompiled platform builds (e.g. nokogiri-style locks).

LockfileSupplement now keeps those gems in a new platform_gems field (always populated; still only folded into lockfile-only discovery in hosted mode). The scan path that decides which packages count as lock-resolved for totals unions entries with platform_gems, so refused platform-only gems are no longer treated as extraneous installs and their advisories show up in the final line.

Adds e2e coverage in refused_platform_gem_is_counted_as_left_to_patch for both hosted and vendored modes.

Reviewed by Cursor Bugbot for commit 1e26e16. Configure here.

Merged via the queue into main with commit 02add9b Nov 20, 2026
83 checks passed
@mikolalysenko
Mikola Lysenko (mikolalysenko) deleted the agent/fix-gem-platform-lock-left-to-patch branch November 20, 2026 20:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Scan totals say "Nothing left to patch." when a refused gem is locked as precompiled platform builds (nokogiri)

3 participants