Skip to content

Fix vendored gem refusals naming no remedy (#2091) - #2127

Merged
Mikola Lysenko (mikolalysenko) merged 8 commits into
mainfrom
agent/fix-vendored-gem-refusals-name-no-remedy
Nov 18, 2026
Merged

Mikola Lysenko (mikolalysenko) merged 8 commits into
mainfrom
agent/fix-vendored-gem-refusals-name-no-remedy

Conversation

@mikolalysenko

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

Copy link
Copy Markdown
Collaborator

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

Fixes #2091

Summary

On a stock Rails Gemfile, scan --mode vendored refuses 5 of 7 patched
gems and each error gives only the cause. This PR adds the way out to
the three refusals involved. No behavior changes: the same gems are
refused with the same codes and exit status; only the error detail
text grows, and docs/ecosystems.md gains a short section.

Refusal Detail now ends with
gem in a plain group :test do block …; move it to the top level with the option group: :test, or leave rack to hosted mode (--mode hosted)
gem in another block (platforms, if, nested blocks) …; move it to the top level, or leave rack to hosted mode (--mode hosted)
gem in a source / git / github / path block …; patch rack with --mode agent (hosted mode refuses it too: redirect_gem_source_option)
native_extensions_unsupported (local and served stub) … Patch puma with --mode hosted or --mode agent, which build the extension (--mode agent alone when the declaration picks the gem's source)
platform_gem_unsupported (both branches) … Patch nokogiri with --mode agent, which patches a precompiled gem where it is installed

The wording follows hosted mode's own refusals ("patch GEM with
--mode vendored or --mode agent").

Root cause

crates/socket-patch-core/src/vendor/gem.rs built each refusal from the
cause alone. The remedies existed (the issue verified them) but were in
no message and in no vendored-mode doc.

How it works

  • indented_declaration_remedy reads the blocks open at the declaration
    with the existing formats::gem::ruby::block_stack (the tracker the
    hosted rewriter uses), so it never offers hosted mode inside a
    source-selecting block and spells group: only when exactly one plain
    group … do is open (group_option).
  • The takeover and the vendor eject of a hosted gem raise the same
    refusal, so hosted mode is worded as the mode to leave the gem to,
    which reads true whether or not the gem is hosted already.

Evidence

  • Red first: commit 4926aec adds the assertions; 7 tests in
    vendor::gem failed on it, and pass from ede5101 on.
  • cargo test -p socket-patch-core: pass.
  • cargo test -p socket-patch-cli --test e2e_redirect_gem_build --test e2e_vendor_gem_build --test e2e_gem_native_ext_build -- --include-ignored
    (Ruby 3.3.6, Bundler 4.0.18): pass.
  • cargo clippy --locked --workspace --all-features -- -D warnings
    (CI's command): clean. With --all-targets the test targets of both
    crates already fail on main lints; none is in a line this PR adds.

Tests that cover Fixes #2091:

  • indented_declaration_remedy_fits_the_enclosing_block (every block
    shape, CRLF, tabs, the source-block and hosted variants)
  • test_refuses_unparseable_declaration,
    takeover_preflight_refuses_a_hosted_gem_inside_a_group_block
  • test_refuses_native_extensions, service_native_ext_stub_hard_fails
  • test_refuses_platform_suffixed_dir,
    test_refuses_unexpected_install_dir_name,
    test_refuses_native_platform_qualifier
  • end to end: vendor_eject_keeps_the_hosted_group_pin in
    e2e_redirect_gem_build.rs asserts the text in vendor --json.

Review (/code-review high)

Fixed: hosted mode offered inside a source block; a suggested full
gem line that dropped the declaration's version and options; hosted
mode offered as news to a gem that is hosted already; a quoted whole-project
socket-patch scan --mode hosted (it moves other ecosystems' vendored
patches to hosted mode); hand-rolled indentation tracking.

Not fixed, on purpose:

  • Agent mode can still refuse a platform gem in narrow cases (a JRuby
    build, a precompiled gem with no source archive and no network). The
    remedy names the one mode that can patch such a gem; agent mode's own
    error covers those cases.
  • The other causes of gemfile_declaration_not_editable (parenthesized
    call, duplicate declaration, …) keep their text. The issue is about
    the three refusals above.

Bugbot

One finding, fixed in 2dc2483: the native-extension remedy named hosted
mode for a gem whose declaration picks its source, which hosted mode
refuses. Tests: test_native_extension_remedy_skips_hosted_for_a_source_selecting_declaration,
declaration_selects_source_reads_blocks_and_options.

PR shepherd

5de08b6: declaration_selects_source now reads options with the shared
gemfile::source_option (the reader hosted mode refuses with) instead of its
own key list, which missed gitlab: and custom git_source keys. Test cases
added to declaration_selects_source_reads_blocks_and_options.

Follow-ups

  • The issue also suggests a summary line and next steps that mention
    the refused gems. Not done here: it changes the scan summary for
    every ecosystem and wants its own decision.
  • CLI_CONTRACT.md is untouched: it does not specify these detail
    strings.

https://claude.ai/code/session_011f9aePmQ6T5gENFUUhxnxg


Generated by Claude Code

Refs #2091. Empty commit that opens the draft pull request; the tests
and the fix follow.

Assisted-by: Claude Code:claude-fable-5-2
Refs #2091. The group-block, native-extension and platform-build
refusals must each name a mode that can patch the gem, and never one
that refuses it too. These fail until the next commit.

Assisted-by: Claude Code:claude-fable-5-2
Vendored mode refuses a gem declared inside a block, a gem with native
extensions and a precompiled platform build. Each error gave the cause
and no next step, so a stock Rails Gemfile failed 5 of 7 gems with
nothing to act on.

Each refusal now names a mode that can patch the gem: hosted mode for a
block (with the top-level `group:` form when the block is a plain
`group … do`), hosted or agent mode for native extensions, and agent
mode alone for a platform build, which hosted mode refuses too.

Fixes #2091

Assisted-by: Claude Code:claude-fable-5-2
Review of the first cut found remedies that could mislead:

- A gem inside a source, git, github or path block was sent to hosted
  mode, which refuses it too. The enclosing blocks are now read with
  formats::gem::ruby::block_stack and agent mode is named there.
- The suggested top-level line dropped the declaration's version and
  options. The remedy now names only the group: option to add.
- A gem that is hosted already (the takeover and eject preflight) was
  told to use hosted mode. It is now told it can stay there.
- `socket-patch scan --mode hosted` was quoted as the fix for one gem,
  though a whole-project hosted scan moves the vendored patches of
  other ecosystems. The remedies name the mode for the gem, as hosted
  mode's own refusals do, and the docs say how to patch one gem.

Refs #2091

Assisted-by: Claude Code:claude-fable-5-2
clippy::needless_borrow on the four remedy calls.

Refs #2091

Assisted-by: Claude Code:claude-fable-5-2
The vendor eject of a hosted gem reaches the indented-declaration
refusal through the backend, not the takeover preflight, so the
preflight-only "keep it in hosted mode" wording missed it (the e2e
eject tests failed). One wording now serves every caller: "leave
<gem> to hosted mode (`--mode hosted`)", true whether or not the gem
is hosted already.

Refs #2091

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

Copy link
Copy Markdown
Collaborator Author

bugbot run


Generated by Claude Code

@mikolalysenko
Mikola Lysenko (mikolalysenko) marked this pull request as ready for review November 18, 2026 10:09
@cursor

cursor Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

PR Summary

Low Risk
No change to refusal logic or exit behavior—only error detail strings and documentation are extended.

Overview
Fixes #2091 by appending actionable remedies to vendored-mode gem refusal messages. Refusal codes and when vendoring is blocked are unchanged; only the error detail text grows.

gemfile_declaration_not_editable (indented declarations): Uses block_stack to suggest moving the gem to the top level (including a concrete group: option for simple group … do blocks), leaving the gem on --mode hosted, or --mode agent when the gem sits inside source/git/github/path blocks where hosted mode also refuses.

native_extensions_unsupported and platform_gem_unsupported: Messages now name --mode hosted/agent (native extensions) or --mode agent only (precompiled platform builds), matching which modes can actually handle the gem.

Unit tests, an e2e assertion on JSON refusal output, and a new “Ruby gems: gems vendored mode refuses” section in docs/ecosystems.md lock in the wording.

Reviewed by Cursor Bugbot for commit 6ebb034. 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.

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 6ebb034. Configure here.

Bugbot: the native-extension refusal is raised before the Gemfile
plan, so a native gem inside a source, git, github or path block, or
with one of the source options, was still sent to hosted mode, which
refuses it (redirect_gem_source_option). The remedy now names agent
mode alone for such a declaration.

Refs #2091

Assisted-by: Claude Code:claude-fable-5-2
declaration_selects_source kept its own list of source keys, which left
out `gitlab:` and custom `git_source` keys that hosted mode refuses
(redirect_gem_source_option). For such a gem with a native extension the
remedy named `--mode hosted`, a mode that refuses it as well. Use
gemfile::source_option, the reader hosted mode refuses with.

Assisted-by: Claude Code:claude-opus-5-5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011f9aeNxATwEfTmV9fd2wYR
@mikolalysenko

Copy link
Copy Markdown
Collaborator Author

[agent] PR shepherd: review brief for 5de08b6

What it does: When vendored mode refuses a Ruby gem (declared inside a block, builds a native extension, or is a precompiled platform build), the error now also names a way out: move the line to the top level (and spell the group: option for a plain group block), or use --mode hosted / --mode agent. It never names a mode that would refuse the same gem too. Refusal codes, exit status and what gets written are unchanged. Only the error text changes, and docs/ecosystems.md gains a short section.

Risk: low. It changes message text only. The new helpers just read the Gemfile text, and the block tracker they use is the same one hosted mode already uses. Nothing new is written to disk.

Look here:

  • gem.rs:1371: declaration_selects_source decides whether hosted mode is offered for a native-extension gem
  • gem.rs:1417: indented_declaration_remedy, which picks the wording from the blocks open at the declaration
  • gem.rs:1442: group_option spells group: only when every argument is a plain symbol
  • gem.rs:1545: the byte offset of the declaration line (the lines come from split('\n'), so the offset is correct with CRLF)
  • ecosystems.md:1998: the new doc section

Verified: I read the whole diff, the issue (#2091) and the one Bugbot thread, which was real, fixed in 2dc2483 and is resolved. The new assertions check the remedy text, so they fail without the change. The served-stub path passes hosted = true because the Gemfile plan, which refuses source options, has already passed by then. No unrelated edits, and CHANGELOG.md is untouched. CI on 5de08b6: ci-ok and clippy green.

Changes I made: none.

Open questions: none blocking. One minor gap: declaration_selects_source reads only the declaration's own line. For a gem call whose git: / path: option sits on a continuation line, it would still name --mode hosted, and hosted mode would then refuse with its own clear redirect_gem_source_option. That costs the user one extra run and nothing breaks.


Generated by Claude Code

@mikolalysenko Mikola Lysenko (mikolalysenko) added the Ready for review Agent-verified: mergeable, CI green, Bugbot clean — awaiting human review label Nov 18, 2026
Merged via the queue into main with commit f329b2f Nov 18, 2026
49 checks passed
@mikolalysenko
Mikola Lysenko (mikolalysenko) deleted the agent/fix-vendored-gem-refusals-name-no-remedy branch November 18, 2026 21:51
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