Skip to content

Fix vendored re-scan failing over a gem patched in hosted mode (#2395) - #2397

Open
Mikola Lysenko (mikolalysenko) wants to merge 6 commits into
mainfrom
agent/fix-vendored-gem-indented-hosted-skip
Open

Mikola Lysenko (mikolalysenko) wants to merge 6 commits into
mainfrom
agent/fix-vendored-gem-indented-hosted-skip

Conversation

@mikolalysenko

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

Copy link
Copy Markdown
Collaborator

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

Fixes #2395

Summary

scan --mode vendored refuses a gem whose gem line sits inside a block
(group :development do), and the refusal says to leave the gem to hosted
mode. After the user did that, every later scan --mode vendored raised the
same refusal, counted the gem as left to patch and exited 1.

Such a gem is now the benign skip vendor_gem_patched_in_other_mode, as a
native gem already was (#2269): exit 0, counted as patched, nothing written.

Skipping pkg:gem/rake@13.4.2?platform=ruby: vendored mode cannot edit the Gemfile
declaration of rake; it stays patched in hosted mode (patch <uuid>)
Nothing left to patch.

The conditions are those of the native skip: Gemfile.lock pins the
selected patch hosted (or the manifest records it for agent mode), and
every installed copy the crawl finds holds it. Anything else is refused
as before.

Root cause

Two things kept the declaration refusal away from the existing skip:

  1. settle_gem_refusal returned early for every code but
    native_extensions_unsupported.
  2. For a gem with a hosted pin, the declaration refusal is raised by the
    takeover preflight, in the download phase, before the patch view is
    fetched. Without the view nothing can check the installed copies.

The change

  • Core: refusal_names_another_mode covers both codes, and the skip's
    detail says which reason applies.
  • Vendor loop: the takeover preflight's refusal goes through the same
    settlement as the backend's.
  • Download phase (scan, get <purl>): a gem refused for its declaration
    is left to the vendor loop only when its pin is the selected patch and
    a copy of it is installed. Every other gem is refused before any fetch, as
    before.
  • get <uuid> holds the view already, so it settles the gem before its
    engine and keeps its one shape for a refusal (status: "error").
  • CLI_CONTRACT.md (the skip's row, the takeover preflight paragraph) and
    docs/ecosystems.md.

The npm/, pypi/ and gem/ wrappers call the binary and need no change.

What stays refused (each a case of the guard test)

  • No pin and no record.
  • A hosted pin whose installed copy is still the upstream gem.
  • A hosted pin with an unpatched copy in the tree of another Ruby.
  • A hosted pin of an earlier patch than the one the scan selects.
  • A hosted pin on a checkout with no copy of the gem installed. This one is
    refused without fetching the view, which an existing real-Bundler test
    pins (gem_hosted_group_block_pin_survives_a_refused_vendored_takeover).

Evidence

The issue's script (real Bundler 4.0.18, Ruby 3.3.6, rake 13.4.2 in
group :development), step 3, scan --mode vendored after the hosted get:

output exit
main 1b3f422 [error] … (gemfile_declaration_not_editable), 1 vulnerability left to patch 1
this branch Skipping …; it stays patched in hosted mode, Nothing left to patch. 0

The Gemfile and the lock are unchanged by the scan, and vex still writes
its statement.

Tests, in crates/socket-patch-cli/tests/e2e_redirect_gem_stale_install.rs
(real binary, mock patch service). The first commit adds them against
main, where the two skip tests fail with
failed/gemfile_declaration_not_editable and the guard passes:

Local runs:

cargo clippy --locked --workspace --all-features -- -D warnings
cargo test -p socket-patch-core --lib vendor::
cargo test -p socket-patch-cli --lib --test get --test scan --test vendor
cargo test -p socket-patch-cli --test e2e_redirect_gem_stale_install
cargo test -p socket-patch-cli --test command_module_layering
cargo test -p socket-patch-cli --test e2e_redirect_gem_build \
  --test e2e_vendor_gem_build --test e2e_gem_native_ext_build -- --include-ignored

cargo clippy --all-targets reports 78 errors in test code that main has
too (CI's clippy job does not pass --all-targets); none is in a line this
PR touches.

Review findings not fixed

  • A fresh checkout stays refused. With the pin in the lock and no copy
    of the gem installed (a CI job that scans before bundle install), the
    scan still exits 1. The native skip has the same limit, and the existing
    test named above expects the refusal there. Whether a lock pin alone
    should count as "patched in hosted mode" is a behavior question for a
    maintainer; the guide now states the limit.
  • The dry run does not preview the skip. It reads no installed copy, so
    it still lists a hosted gem in a block as would-refuse (exit 0 either
    way). The contract and the guide say so.

https://claude.ai/code/session_011f9aeNrnmLGQjptH8jHcD9


Generated by Claude Code

Refs #2395

Assisted-by: Claude Code:claude-fable-5-2
A gem declared in a group block and patched in hosted mode, as the
vendored refusal advises, must be a skip of the next vendored scan.
The two skip tests fail on main with
failed/gemfile_declaration_not_editable; the guard test passes.

Refs #2395

Assisted-by: Claude Code:claude-fable-5-2
A vendored scan refuses a gem whose gem line sits inside a block and
names hosted mode. Once the gem held the selected patch there, every
later vendored scan raised the refusal again and exited 1: the skip
vendor_gem_patched_in_other_mode covered only the native-extension
refusal, and the declaration refusal of a hosted gem was raised
before the patch view was fetched, so nothing could check the
installed copies.

The declaration refusal now reaches the same settlement. When the
lock pins the selected patch, the download phase leaves the gem to
the vendor loop, which has the record: every installed copy holding
the patch makes it the skip, anything else the refusal as before.
Nothing is written either way.

Fixes #2395

Assisted-by: Claude Code:claude-fable-5-2
The vendored download phase left every hosted gem refused for its
declaration, and pinned at the selected patch, to the vendor loop,
which fetched its patch view. A checkout with no copy of the gem
installed has nothing the view could judge: refuse it before any
fetch, as before.

Refs #2395

Assisted-by: Claude Code:claude-fable-5-2
get <uuid> --mode vendored raises a vendored refusal before its
engine, in the pre-record error shape. The gem left to the patch
view skipped that step and reached the vendor loop, so the same
refusal had two shapes depending on whether the gem was installed.
The uuid path holds the view already: it now settles the gem there,
as the skip or as the refusal in its one shape.

Also scope the dry-run and takeover sentences of the contract and
the guide to what the preview does.

Refs #2395

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

Copy link
Copy Markdown
Collaborator Author

bugbot run


Generated by Claude Code

@cursor

cursor Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

PR Summary

Low Risk
Targeted gem vendored-flow behavior change with fail-closed checks unchanged for uninstalled or mismatched patches; covered by new e2e tests and doc contract updates.

Overview
Vendored scan/get no longer fail on gems that vendored mode cannot wire (gemfile_declaration_not_editable, e.g. gem inside a group block) once the same selected patch is already active in hosted or agent mode. Those refusals are treated like native-extension refusals: they can become the benign skip vendor_gem_patched_in_other_mode (exit 0, counted as patched) when the lock or manifest pins the selected UUID and every installed copy verifies against the patch view.

The download phase defers declaration (and other “use another mode”) refusals when the hosted pin matches the selection and an installed copy exists, so the vendor loop can verify bytes before deciding skip vs failure. get <uuid> settles the same way with the view it already fetched. The takeover preflight in vendor also runs settle_gem_refusal so grouped gems already patched hosted-side skip instead of failing. Core adds refusal_names_another_mode and richer skip messaging; contract and ecosystem docs are updated. E2E tests cover hosted/agent skip paths and refusal when the patch is missing, stale, or the gem is not installed.

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

get imported vendor's settlement directly, an edge between two
command modules that the layering test refuses. The download helper
owns these refusals and already imports vendor: it settles the one
left to the patch view, and get calls the helper.

Refs #2395

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

Copy link
Copy Markdown
Collaborator Author

[agent] PR shepherd: review brief for the approver

What it does
After a gem declared inside a group block is patched in hosted mode (the remedy vendored mode's refusal names), every later scan --mode vendored refused it again and exited 1. Such a gem is now the existing benign skip vendor_gem_patched_in_other_mode (exit 0, counted as patched), under the same conditions as the native-gem skip from #2269: the lock pins the selected patch (or the manifest records it) and every installed copy holds it.

Risk
Low. Every new path falls back to the old refusal when anything doesn't match (no pin, another patch, no installed copy, an unpatched copy). Nothing new is written to disk; the change only turns one refusal into a skip.

Look here

  • [agent_download.rs:1282](https://github.com/SocketDev/socket-patch/blob/6ea072c4821aa182056fc91942c067ccf4cd74a8/crates/socket-patch-cli/src/commands/agent_download.rs#L1282): the download phase leaves a declaration refusal to the view only when the pin is the selected patch and the gem is installed.
  • vendor.rs:4066: the takeover preflight's refusal now goes through settle_gem_refusal.
  • vendor.rs:287: the settlement gate, now refusal_names_another_mode.
  • get.rs:2618: get <uuid> settles with the view it already holds.
  • gem.rs:339: the new code constant and the skip's detail text.

Verified

Changes I made
None.

Open questions
None blocking. The PR itself raises one: a fresh checkout with the pin but no installed copy (a CI job that scans before bundle install) is still refused. The native skip behaves the same way, and the docs now say so.
Nit, safe: the loop at agent_download.rs:1310 takes the first pin for the purl, not the one matching the selected UUID. A mismatch can only keep the refusal, never wrongly skip.


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 1, 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