Skip to content

Fix vendored transitive gem loading at boot (#2084) - #2097

Merged
Mikola Lysenko (mikolalysenko) merged 4 commits into
mainfrom
agent/fix-vendored-gem-transitive-require
Nov 16, 2026
Merged

Mikola Lysenko (mikolalysenko) merged 4 commits into
mainfrom
agent/fix-vendored-gem-transitive-require

Conversation

@mikolalysenko

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

Copy link
Copy Markdown
Collaborator

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

Fixes #2084

Summary

Vendored mode patches a gem the Gemfile doesn't declare by appending a managed block that declares it. The declaration had no require: false, so Bundler.require (what a Rails app runs at boot) started loading the gem, which it did not do before the scan. The block is now written as:

# >>> socket-patch vendor (managed) >>>
gem "rake", "13.0.6", path: ".socket/vendor/gem/<uuid>/rake-13.0.6", require: false
# <<< socket-patch vendor (managed) <<<

Hosted mode already writes require: false on the line it adds for such a gem.

Root cause

plan_gemfile_edit in crates/socket-patch-core/src/vendor/gem.rs formatted the appended declaration as gem "<name>", "<version>", path: "<rel>". Bundler auto-requires every declared gem of the default group unless the declaration says otherwise.

What changed

  • New blocks carry , require: false (LF and CRLF Gemfiles).
  • Blocks written by 5.1 or earlier gain the option when a patch update re-vendors the gem (the RewireOurs path). Only a block line that ends at the closing quote of its path: value is changed, which is the exact form older releases wrote. A line with anything after it (an option, a comment, if ..., ;) was edited by hand and is repointed as before, byte for byte.
  • A top-level declaration outside the block never gains the option: the Gemfile had it before the patch.
  • Revert needed no change. It already accepts a block with or without the option, and a test now pins that for a ledger an older release wrote.
  • CLI_CONTRACT.md describes the option in the vendoring table.

Evidence

Check Result
cargo test -p socket-patch-core --lib 7741 passed
cargo test -p socket-patch-cli --test e2e_vendor_gem_build -- --ignored (Ruby 3.3.6, Bundler 4.0.18) 11 passed
cargo test -p socket-patch-cli --test in_process_vendor --test e2e_vex_vendor 35 and 148 passed
cargo clippy --locked --workspace --all-features -- -D warnings (CI's command) clean

Tests for #2084:

  • appended_block_declares_the_gem_require_false, and the updated byte-exact block assertions in five existing tests. Commit c63b043 holds the tests alone; 7 of them fail there and pass from a65c8b6.
  • gem_vendor_transitive_dep_fresh_checkout_and_revert (end to end, real Bundler) now boots the fresh checkout with Bundler.require(:default) and fails if lib/rack.rb is loaded. Without the fix it fails with "Bundler.require loaded the vendored transitive gem".
  • revendor_adds_require_false_to_an_older_block, revert_removes_an_older_block_without_require_false (LF and CRLF), revendor_keeps_an_edited_block_line_as_it_is, revendor_never_adds_require_false_outside_the_block.

cargo clippy -p socket-patch-core --all-targets reports 44 errors in test targets on main too (none in the files of this PR); CI's clippy job does not lint test targets.

Review findings not fixed

/code-review high reported four findings. One was a real bug and is fixed in 3fbeeea (the option could land after a statement modifier on a hand-edited block line). The other three are left as they are:

  1. A project already vendored by 5.1 keeps its block until the patch is updated. A re-run at the same patch uuid takes the "already vendored" path and writes nothing, so the old block stays and the gem is still loaded at boot. vendor --revert followed by a new vendor run rewrites it. Healing it on a no-op run means rewriting a committed Gemfile and its ledger record on a run that today changes nothing, and warning about it means a new warning code. Both change CLI behavior, so they need a maintainer's decision (see below).
  2. A user who removes require: false from the block on purpose gets it back at the next patch update. That line can't be told apart from one 5.1 wrote. Writing require: true keeps the gem auto-required, since a line with an option after path: is never changed.
  3. The literal , require: false exists here and in hosted mode's added_line. Sharing a two-word constant would add the hosted rewriter to this diff for no change in behavior.

For a maintainer

Should a same-uuid vendor / scan --mode vendored run rewrite a 5.1 block to add require: false, warn about it, or leave it (current behavior)? I can do either in a follow-up PR.

https://claude.ai/code/session_011f9aePqWf8D86MUbLkwZbv


Generated by Claude Code

Refs #2084

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_011f9aePqWf8D86MUbLkwZbv
A gem the Gemfile does not declare gets a managed block from vendored
mode. The tests pin that its declaration carries `require: false`,
that a block an older release wrote gains it on a re-vendor and can
still be reverted, and that an edited block line is left alone.

These fail until the next commit.

Refs #2084

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_011f9aePqWf8D86MUbLkwZbv
Vendored mode declares a gem the Gemfile does not name in a managed
block at the top level of the Gemfile. The declaration had no
`require: false`, so `Bundler.require` loaded the gem at boot,
which it did not do before the scan. Hosted mode writes the option
on the line it adds for the same reason.

The block is now written with `require: false`. A block an older
release wrote gains the option when a patch update re-vendors the
gem; a block line with anything after its `path:` was edited by
hand and is repointed as before. The revert already accepts both
forms.

The transitive end-to-end test now boots the fresh checkout with
`Bundler.require` and fails if the gem is loaded.

Fixes #2084

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_011f9aePqWf8D86MUbLkwZbv
A re-vendor gave the managed block's line `require: false` whenever
no keyword option or comment followed its `path:`. A hand-edited
line with a statement modifier or a `;` after the path passed that
test, and the option landed outside the call's arguments: a Ruby
syntax error in the Gemfile, or an option on another gem's call.

The option is now added only when the line ends at the closing quote
of its `path:` value, the form older releases wrote. Any other line
is repointed and otherwise left alone.

Refs #2084

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_011f9aePqWf8D86MUbLkwZbv
@mikolalysenko
Mikola Lysenko (mikolalysenko) marked this pull request as ready for review November 16, 2026 18:12
@mikolalysenko

Copy link
Copy Markdown
Collaborator Author

bugbot run


Generated by Claude Code

@cursor

cursor Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

PR Summary

Low Risk
Targeted Gemfile formatting for gem vendoring with migration on re-vendor; boot behavior change is intentional and covered by e2e tests.

Overview
Fixes #2084: vendored transitive gems were appended to the Gemfile in a managed block without require: false, so Bundler.require auto-loaded a gem the app never declared before patching.

Gemfile wiring in gem.rs now appends , require: false on new managed blocks. Re-vendor (RewireOurs) adds the same option only for legacy block lines that end right after path: (releases ≤5.1); hand-edited lines and direct path: declarations are unchanged. CLI_CONTRACT.md documents the option.

Tests: unit coverage for append/revert/revendor edge cases; the transitive e2e capstone runs Bundler.require(:default) and asserts the vendored transitive gem is not loaded at boot.

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

Merged via the queue into main with commit c575699 Nov 16, 2026
82 checks passed
@mikolalysenko
Mikola Lysenko (mikolalysenko) deleted the agent/fix-vendored-gem-transitive-require branch November 16, 2026 20:35
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.

Vendored mode declares a transitive gem without require: false, so Bundler.require starts loading it at boot (hosted mode adds the option)

3 participants