Skip to content

Fix vendored scan skipping a gem locked only as platform gems (#2394) - #2447

Merged
Mikola Lysenko (mikolalysenko) merged 3 commits into
mainfrom
agent/fix-vendored-scan-platform-only-gems
Dec 2, 2026
Merged

Mikola Lysenko (mikolalysenko) merged 3 commits into
mainfrom
agent/fix-vendored-scan-platform-only-gems

Conversation

@mikolalysenko

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

Copy link
Copy Markdown
Collaborator

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

Fixes #2394

Summary

socket-patch scan --mode vendored on a checkout with nothing installed
never asked the patch service about a gem that Gemfile.lock holds only as
precompiled platform gems (nokogiri (1.19.7-x86_64-linux-gnu), no plain
nokogiri (1.19.7)). The gem was skipped without a message, the run ended
with Nothing left to patch. and exited 0. That lock is what Bundler 2.x
writes by default, and what the vendored refusal's own remedy
(bundle lock --remove-platform ruby) leaves behind.

Now the scan looks the gem up in every mode. A vendored run vendors it from
the lock alone (or names it when it cannot), and an agent run counts it
among the packages that are not installed.

Root cause

The scan's lockfile supplement (commands/scan/discovery.rs) adds the
packages the lock resolves that have no installed copy. The Bundler lock
inventory leaves platform-only gems out, and the supplement added them back
for a hosted run alone. That limit predates vendoring from prebuilt platform
gems: the vendored engine has not needed an installed copy since then, but
discovery still never named the gem.

The fix

The supplement names platform-only gems in every mode (one filter removed).
Nothing else in the engine changes. get --mode vendored reads the same
supplement, so it finds such a gem on a fresh checkout too.
CLI_CONTRACT.md ("Lockfile supplement" and the agent-mode paragraph on
gems that are not installed) says so.

No file is written that was not written before for an installed copy: the
vendored path is the one the same scan takes after bundle install.

Evidence

The issue's repro (Ruby 3.3.6, Bundler 4.0.18, nokogiri 1.19.7, 8 platforms,
nothing installed), which gems each scan asks the service about:

mode main this branch
hosted rack, nokogiri rack, nokogiri
vendored rack rack, nokogiri
agent rack rack, nokogiri

With the repository's stand-in patch service, on this branch: the fresh
checkout prints Vendored 1 package., vendor --check verifies it, a
frozen bundle install passes and Ruby loads the patched nokogiri. A second
scan says already vendored. An agent scan of the fresh checkout prints the
"not yet installed" note for both locked gems, skips the patches and exits 0.

Tests, each red on main and green here:

  • platform_only_gem_is_looked_up_on_a_fresh_checkout
    (e2e_redirect_gem_stale_install, no Bundler needed) covers
    Fixes #2394: a vendored and an agent scan of a fresh checkout ask about
    the gem. The vendored run names the gem it skips (one platform has no
    patch) and counts its advisory as left to patch. The agent run counts it
    as not installed.
  • platform_only_gem_is_vendored_from_the_lock_alone (same suite): with a
    patch for every locked platform, the vendored scan writes one tree per
    platform, moves the lock to the vendored path and records each platform's
    patch in the ledger.
  • tests/nokogiri/nokogiri_e2e.rb, vendored scenario (real Bundler, real
    nokogiri): it now first scans a checkout with nothing installed, installs
    it frozen and checks Ruby loads the patched gem from the vendored tree.
    The stand-in service now answers a lookup for nokogiri only when the run
    asks about it, as the real service does. Before that it always answered,
    which is why this scenario never caught the bug.

Local runs: cargo test -p socket-patch-cli --lib (1102 passed);
e2e_redirect_gem_stale_install (84), in_process_gem_multi_platform (9),
hosted_memory_parity (48), e2e_vex_redirect (39); with real Bundler
4.0.18 and --include-ignored: e2e_vendor_gem_build (21),
e2e_redirect_gem_build (57), e2e_gem_native_ext_build (54); the nokogiri
script's vendored (36 checks) and hosted (38 checks) scenarios on
nokogiri 1.18.10. cargo clippy --locked -p socket-patch-core -p socket-patch-cli --all-features -- -D warnings (CI's form) is clean. With
--all-targets clippy reports errors on this toolchain in test code this PR
does not touch; none is on a changed line.

Review findings not fixed here

/code-review high ran on the diff. Fixed: the missing success-path test,
the contract paragraph that still said an agent scan never names these gems,
and three comments that still called them hosted-only. Left out, with
reasons:

  • An agent scan of a project that hosted mode already pinned reports "a
    newer patch available" for a platform-locked gem that is on the current
    fix.
    Agent and report-only runs compare each platform's patch with the
    one uuid the hosted pin records. This already happens on main when the
    gem is installed; it is now also reachable on a fresh checkout. It is a
    separate comparison bug and worth its own issue.
  • apply exits 1 (package_not_installed) for a recorded patch of a
    platform-only gem that is not installed, while the agent scan now skips it
    calmly.
    apply is unchanged and an existing unit test pins it. Agent
    mode only records a patch for an installed copy, so this needs a manifest
    committed from another machine. Loosening apply is a behavior decision
    of its own.
  • The agent scan's skip line counts patches, not gems ("9 packages with
    patches are not installed" for one gem locked on 8 platforms). The wording
    is not new and is the same count Vendored scan prints the platform_gem_unsupported refusal once per platform patch of a gem: 9 identical lines for nokogiri on a default Bundler 4 lock, 31 for three gems, and "9 patches failed" for one gem #2436 reports for vendored mode.

https://claude.ai/code/session_011f9aeQTW6Y2zvHzpaEquUN


Generated by Claude Code

Refs #2394

Assisted-by: Claude Code:claude-fable-5-2
The scan's lockfile supplement named a gem that Gemfile.lock holds
only as precompiled platform gems for a hosted run alone. That limit
predates vendoring from prebuilt platform gems, so a vendored scan
of a checkout with nothing installed never asked the patch service
about such a gem: it was skipped without a message and the run
ended with "Nothing left to patch."

The supplement now names these gems in every mode. A vendored run
vendors the gem from the lock alone, and an agent run counts it
among the packages that are not installed.

The stand-in patch service of the nokogiri end-to-end test now
answers a lookup for the gem only when the run asks about it, as
the service does, and the vendored scenario scans a checkout with
nothing installed first.

Fixes #2394

Assisted-by: Claude Code:claude-fable-5-2
Add a hermetic test of the success path: a vendored scan of a
checkout with nothing installed vendors a gem the lock holds only
as platform gems, one tree per locked platform, when the service
has a patch for each. The service of the test answers a lookup
for the gem only when the run asks about it.

Bring the contract's agent-mode paragraph and the comments that
still called these gems hosted-only in line with the code.

Refs #2394

Assisted-by: Claude Code:claude-fable-5-2
@mikolalysenko
Mikola Lysenko (mikolalysenko) marked this pull request as ready for review December 2, 2026 10:16
@mikolalysenko

Copy link
Copy Markdown
Collaborator Author

bugbot run


Generated by Claude Code

@cursor

cursor Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

PR Summary

Low Risk
Scoped to lockfile discovery for platform-only Ruby gems; vendored/hosted/agent paths already handle these gems once named—no auth or persistence changes.

Overview
Fixes #2394: scan (and get in non-agent modes) now includes gems that Gemfile.lock lists only as precompiled platform builds in the lockfile supplement for every mode, not just hosted.

Previously those PURLs were added to discovery only when hosted == true, so scan --mode vendored on a fresh checkout never batch-queried them and could exit 0 with “Nothing left to patch.” The change is a one-line behavior shift in lockfile_supplement: platform_gems are always merged into lockfile-only packages (vendored can vendor from per-platform prebuilds; agent treats them as lockfile-only / not installed).

Docs & tests: CLI_CONTRACT.md and inline comments are aligned with the new rule. New Rust e2e tests cover lookup on a fresh checkout and full vendoring from the lock alone; the nokogiri Ruby e2e and mock patch service batch handler now assert the service is only asked when the gem is in the batch.

Reviewed by Cursor Bugbot for commit 94099f5. 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 94099f5. Configure here.

@mikolalysenko

Copy link
Copy Markdown
Collaborator Author

[agent] PR shepherd: review brief for the approver

What it does
scan --mode vendored (and agent mode) on a checkout with nothing installed never asked the patch service about a gem that Gemfile.lock holds only as precompiled platform builds (Bundler 2.x's default lock), so it ended with "Nothing left to patch." and exit 0. The lockfile supplement now names those gems in every mode, not only hosted. A vendored run vendors them from the lock; an agent run lists them as not installed. Fixes #2394.

Risk
Low to medium. The code change is one removed filter. But a vendored scan of a fresh checkout can now write files (vendored trees, a lock rewrite) where it used to do nothing. That is the fix, and it is the same path the scan already takes after bundle install. Exit codes do not change: both new tests assert exit 0 for vendored and agent mode.

Look here

  • discovery.rs:122: the change itself, platform_gems without the hosted filter
  • get.rs:1094: get --mode vendored now sees these purls too (only the comment changed)
  • CLI_CONTRACT.md:504 and :1792: the contract text
  • [e2e_redirect_gem_stale_install.rs:4234](https://github.com/SocketDev/socket-patch/blob/94099f5c5ffa252d113038c02919f753651f88a5/crates/socket-patch-cli/tests/e2e_redirect_gem_stale_install.rs#L4234) and [:4371](https://github.com/SocketDev/socket-patch/blob/94099f5c5ffa252d113038c02919f753651f88a5/crates/socket-patch-cli/tests/e2e_redirect_gem_stale_install.rs#L4371): the new tests
  • patch_service.rb:290: the stand-in service now answers only when the run asks for nokogiri. Before, it always answered, which is why the nokogiri e2e never caught this.

Verified

  • Read the whole diff. CHANGELOG.md is untouched, there is no debug code, and every edit belongs to the fix.
  • Ran the two new tests locally on 94099f5: both pass. Put the hosted filter back and both fail (assertions at lines 4323 and 4501), so they pin the fix.
  • CI on 94099f5: ci-ok and clippy are green and no check is red. There are no open review threads. Bugbot rated it low risk and found nothing.

Changes I made
None.

Open questions
None that block it. The description lists three follow-ups left out on purpose: agent mode's "newer patch available" against a hosted pin, apply exiting 1 for a recorded patch of an uninstalled platform-only gem, and the skip line counting patches rather than gems. Each is better as its own issue.


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 2, 2026
@mikolalysenko
Mikola Lysenko (mikolalysenko) added this pull request to the merge queue Dec 2, 2026
Merged via the queue into main with commit 266306d Dec 2, 2026
127 checks passed
@mikolalysenko
Mikola Lysenko (mikolalysenko) deleted the agent/fix-vendored-scan-platform-only-gems branch December 2, 2026 15:01
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

4 participants