Skip to content

Fix apply missing a gem that ships no lib/ dir - #2185

Merged
Mikola Lysenko (mikolalysenko) merged 3 commits into
mainfrom
agent/fix-gem-without-lib-dir
Nov 20, 2026
Merged

Mikola Lysenko (mikolalysenko) merged 3 commits into
mainfrom
agent/fix-gem-without-lib-dir

Conversation

@Tanmay182003

Copy link
Copy Markdown
Contributor

LLM Description written by Claude Code:claude-opus-5-5

Summary

socket-patch now finds an installed gem that ships no lib/ directory and no .gemspec of its own. Before this change, apply exited 1 with "The targeted manifest patch matched no installed package", and scan, vex and rollback did not see the gem either.

Example: cassandra-web (every release, 0.1.0 through 0.5.0) puts app.rb, app/ and bin/ at the gem root. Its files list holds no lib/ and no gemspec, so RubyGems writes the spec only to <home>/specifications/cassandra-web-0.5.0.gemspec. A patch to app.rb (GHSA-8mfv-xhp5-48q9, disable :protection) could not be applied in agent mode or under --global --global-prefix <home>/gems.

Root cause

verify_gem_at_path_sync and its async twin verify_gem_at_path in crates/socket-patch-core/src/crawlers/ruby_crawler.rs accepted a gems/<leaf>/ dir only when it held lib/ or a *.gemspec. Both the PURL lookup (locate_gem_dirs_sync → find_all_by_purls / find_by_purls / find_each_by_purl / find_builds) and the scan (scan_gem_dir) go through that check. The rule has been unchanged since Ruby support landed, so every release through v5.1.0 has it.

The rule

A gem dir also counts as installed when its gem home has specifications/<leaf>.gemspec, the file RubyGems and Bundler load the gem by.

  • A spec under specifications/default/ does not count. A default gem's gems/<leaf>/ dir holds only its executables, and its code lives in Ruby's own lib dir, so counting that dir would aim a patch at files Ruby never loads.
  • A lib-less dir with no installed spec is still not a gem.
  • The async check now calls the sync one instead of keeping a copy of it.

Decisions:

Evidence

Test Covers
ruby_crawler::tests::verify_gem_lib_less_dir_listed_by_its_home_spec A lib-less dir is not a gem with no spec or with only a default/ spec. It is found by verify_gem_at_path, find_by_purls and crawl_all once specifications/<leaf>.gemspec exists.
apply::gem_without_lib_dir::a_gem_with_no_lib_dir_is_patched_by_its_installed_spec Agent-mode apply --offline patches app.rb of a lib-less gem in vendor/bundle.
apply::gem_without_lib_dir::a_gem_with_no_lib_dir_is_patched_under_a_global_prefix The same through --global --global-prefix <home>/gems.
apply::gem_without_lib_dir::a_lib_less_dir_with_no_installed_spec_is_not_a_gem Without the spec, apply still reports the package as not installed and writes nothing.

The new tests fail on main with the production error and pass on this branch. The other 114 ruby_crawler unit tests and the rest of the apply test binary pass. The only failures in that binary are two PyPI tests (in_process_variant_apply_failure) that need python3 -m venv, which the rust:1.93.1-bookworm image lacks, so they fail with or without this change.

End to end: on ruby:2.5, gem install cassandra-web -v 0.5.0, then apply --manifest-path … --cwd … --global --global-prefix "$GEM_HOME/gems" --offline --force with a one-file app.rb patch:

  • v5.1.0 release binary: matched no installed package, exit 1.
  • This branch: 1 of 1 targeted patch applied, exit 0. The patched app.rb is byte-identical to the expected patched file.

🤖 Generated with Claude Code

A gem whose files sit at its root, with no lib/ and no .gemspec of its
own (cassandra-web packs app.rb, app/ and bin/), was never found: the
Ruby crawler took a gem dir as installed only when it held lib/ or a
*.gemspec. RubyGems writes such a gem's spec only to
<home>/specifications/<leaf>.gemspec, so apply exited 1 with "The
targeted manifest patch matched no installed package", and scan, vex
and rollback missed the gem too.

A gem dir now also counts when its gem home has a gemspec for it
(specifications/ or specifications/default/), the file RubyGems and
Bundler load the gem by. A lib-less dir with no such spec is still not
a gem.

Assisted-by: Claude Code:claude-opus-5-5
A default gem's spec sits in specifications/default/, and its
gems/<leaf>/ dir holds only its executables while its code lives in
Ruby's own lib dir. Counting that dir as an installed copy would aim
a patch at files Ruby never loads, so only the installed
specifications/<leaf>.gemspec makes a lib-less dir a gem.

The scan's async check now runs the same function as the PURL lookup
instead of a copy of it, and comments that named only lib/ and
.gemspec say what the check accepts.

Assisted-by: Claude Code:claude-opus-5-5
Assisted-by: Claude Code:claude-opus-5-5
@cursor

cursor Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

PR Summary

Medium Risk
Changes gem verification used by apply, scan, and PURL resolution; incorrect rules could patch wrong dirs or miss gems, though default-spec exclusion and existing path-safety gates limit blast radius.

Overview
Ruby gem discovery now treats a gems/<leaf>/ directory as installed when the gem home contains specifications/<leaf>.gemspec, not only when the dir has lib/ or an in-directory .gemspec. That unblocks gems like cassandra-web whose code lives at the gem root and whose spec lives only under specifications/.

verify_gem_at_path_sync gains home_installed_spec (path must be under <home>/gems/). Specs under specifications/default/ are excluded so default-gem executable-only dirs are not patched. The async verify_gem_at_path now delegates to the sync helper on the blocking pool instead of duplicating checks.

New apply tests cover agent-mode and --global --global-prefix patching, plus the case where a lib-less dir without an installed spec still fails with "matched no installed package". ruby_crawler tests cover verify, PURL lookup, and crawl behavior.

Reviewed by Cursor Bugbot for commit 11db2f3. Configure here.

Merged via the queue into main with commit 3ffe358 Nov 20, 2026
90 checks passed
@mikolalysenko
Mikola Lysenko (mikolalysenko) deleted the agent/fix-gem-without-lib-dir branch November 20, 2026 17:27
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.

2 participants