Skip to content

Fix gem unwind warning naming a re-run that cannot work (#2086) - #2156

Merged
Mikola Lysenko (mikolalysenko) merged 5 commits into
mainfrom
agent/fix-gem-unwind-shared-rerun-remedy
Nov 19, 2026
Merged

Mikola Lysenko (mikolalysenko) merged 5 commits into
mainfrom
agent/fix-gem-unwind-shared-rerun-remedy

Conversation

@mikolalysenko

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

Copy link
Copy Markdown
Collaborator

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

Fixes #2086

Summary

After a hosted gem rollback or remove, a patched copy left in a
shared gem home (no BUNDLE_PATH, a Docker image's GEM_HOME) gets a
warning. That warning said to "re-run with --gem-refresh-shared", but
the re-run exits 1 with "nothing to roll back": the first run already
removed the patch. The user was left on an upstream lock with the patched
gem still installed, and on Bundler 4 a later bundle pristine fails.

Only warning text, the reinstall note and docs change. No run touches a
file it did not touch before.

Before:

… To install it for this project only, run `bundle config set --local path vendor/bundle && bundle install`, or re-run with `--gem-refresh-shared` to replace the shared copy

After:

… To install it for this project only, run `bundle config set --local path vendor/bundle && bundle install`. To replace the shared copy, run `rm -f <home>/specifications/rack-2.2.8.gemspec <home>/cache/rack-2.2.8.gem && bundle install`; another project that still pins the hosted patch of it then loads the upstream code, which `socket-patch scan` reports there

Root cause

crates/socket-patch-cli/src/commands/gem_refresh.rs builds the
shared-home warning from one template for both directions. For a scan a
re-run with the flag works. For an unwind it can't: hosted mode keeps no
ledger, so once the lock is back on its upstream entry nothing records
which gems were patched. The file already knew this for the other unwind
flavors (retry_hint: "An unwind can't be [retried]"), but the
shared-home text was missed.

Making the re-run work is not possible without that state, so the fix
names remedies that work after the unwind.

What changed

  • Unwind warning for a shared gem home (upstream_gem_stale_install,
    human and --json): no re-run. It names the project-local bundle path,
    or the files to remove before bundle install, with what that costs
    another project. The scan direction's text is unchanged.
  • An unwind's out-of-tree project path (a vendor/bundle symlink):
    its reason no longer names --gem-refresh-shared either.
  • rm -f remedies shell-quote a path the shell would split (a gem
    home under /Users/Jane Doe). Paths that need no quoting print as
    before.
  • Rollback's reinstall note and its reinstall_required detail no
    longer claim the next install replaces such a gem. Next to an
    upstream_gem_stale_install warning they add "(Bundler: bundle install keeps an installed gem; see the gem warning for what to run)",
    as they already do for Bun and PyPI.
  • CLI_CONTRACT.md and docs/ecosystems.md describe the above. The
    docs now say to pass --gem-refresh-shared on the rollback /
    remove run itself.

The wrappers under npm/, pypi/ and gem/ don't mention the flag
and need no change.

Evidence

Test Covers
e2e_redirect_gem_stale_install::hosted_unwind_names_no_rerun_for_a_shared_gem_home #2086 end to end, for rollback and remove, human and --json: the shared home is left alone, the warning names no re-run and names the rm -f command, rollback's note defers to it, and a second unwind with the flag exits 1
gem_refresh::tests::an_unwind_names_no_rerun_for_a_shared_home the exact --json detail and human bullets
gem_refresh::tests::the_rm_remedy_quotes_a_path_the_shell_would_split quoting, for the shared and the project-local command
gem_refresh::tests::the_policy_decides_what_is_tried (extended) the out-of-tree reason in the unwind direction
rollback::tests::reinstall_note_defers_to_the_gem_warning the note's qualifier and which code triggers it

The first two were committed before the fix and failed on the old text
(commit 911a108); they pass from 6e00270 on.

The remedy itself, on real Bundler 4.0.18 / Ruby 3.3.6 with a shared
GEM_HOME: rack 2.2.8 installed, its files and cache/ archive
modified to stand in for a patched build. bundle install kept the
modified copy. After rm -f <spec> <archive> && bundle install the app
loaded the upstream code and bundle pristine exited 0.

Local runs:

  • cargo test -p socket-patch-cli --lib: 958 passed
  • --test e2e_redirect_gem_stale_install: 53 passed
  • --test rollback --test cli_global_args --test e2e_vex_redirect: 138, 13 and 35 passed
  • --test e2e_redirect_gem_build --test e2e_vendor_gem_build -- --ignored (real Bundler): 48 and 11 passed
  • cargo clippy --locked -p socket-patch-cli --all-features -- -D warnings (CI's form): clean.
    With --all-targets clippy fails on main too, in files this PR
    does not touch (tests/common/mod.rs,
    src/commands/vendored_backend/repair.rs test code); none of the
    errors is in a changed file.

Review (/code-review high)

Seven findings. Fixed in 7297439: the cost sentence (it said another
project "needs a bundle install too", which would not restore a
patched build there), unquoted rm -f paths, the out-of-tree reason,
two weak assertions in the new end-to-end test, and a contract sentence
that overstated the delete-list rule.

Not fixed here:

  • rollback --dry-run does not preview a shared copy the wet run will
    leave
    , so no run names --gem-refresh-shared before the one run
    where it works. The dry run reports no stale gems at all today (it
    predates this PR), and adding that is a behavior change of its own. The
    docs now say when to pass the flag. A follow-up issue is worth opening.

For the reviewer to decide

The contract said a shared gem home never gets a delete list. In the
unwind direction this PR gives it one, because nothing else can replace
the shared copy once the patch is removed, and a Docker image with one
project in GEM_HOME has no use for the project-local path. If you'd
rather keep that rule, the alternative is to name the project-local path
alone.

https://claude.ai/code/session_011f9aeSmGF7hUwWjuXgRvcM


Generated by Claude Code

Refs #2086

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_011f9aeSmGF7hUwWjuXgRvcM
A hosted rollback or remove that leaves a patched copy in a shared
gem home tells the user to re-run with --gem-refresh-shared. The
first run removed the wiring, so the re-run exits 1. These tests
fail until the unwind names a remedy that works.

Refs #2086

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_011f9aeSmGF7hUwWjuXgRvcM
After a hosted gem rollback or remove, the warning about a patched
copy left in a shared gem home said to re-run with
--gem-refresh-shared. The first run removed the wiring, so the
re-run exits 1 and the shared copy stays patched.

In the unwind direction the warning now names the project-local
bundle path, or the files to remove before bundle install fetches
the upstream gem into the shared home. Rollback's reinstall note
no longer implies that the next install replaces such a copy.

Fixes #2086

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_011f9aeSmGF7hUwWjuXgRvcM
Review of the unwind remedy:

- The cost named for replacing a shared copy by hand was wrong. A
  project that still pins the hosted patch keeps the upstream copy
  on its next bundle install; say that instead.
- A path in the rm -f remedy is shell-quoted when the shell would
  split it (a gem home under a directory with a space).
- An unwind no longer names --gem-refresh-shared for a project
  path outside the project directory either.
- The end-to-end test asserts rollback's reinstall_required detail
  and the reason a second unwind fails.

Refs #2086

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_011f9aeSmGF7hUwWjuXgRvcM
@mikolalysenko
Mikola Lysenko (mikolalysenko) marked this pull request as ready for review November 19, 2026 05:43
@mikolalysenko

Copy link
Copy Markdown
Collaborator Author

[agent] bugbot run


Generated by Claude Code

@cursor

cursor Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

PR Summary

Low Risk
User-facing warning and documentation changes only; gem refresh I/O policy is unchanged aside from clearer out-of-tree reasons on unwind.

Overview
Fixes #2086: after a hosted gem rollback or remove, stale patched copies in a shared gem home were still advised to “re-run with --gem-refresh-shared”, even though that re-run finds nothing to unwind.

Gem refresh messaging now branches on Direction. Scan/apply paths keep the project-local bundle remedy plus optional --gem-refresh-shared. Unwind paths drop any re-run hint, add an explicit rm -f … && bundle install remedy (with shell-quoted paths when needed), and note the cross-project cost if another repo still pins the hosted patch.

Rollback’s generic reinstall_required note gains a Bundler qualifier when upstream_gem_stale_install is present, matching existing Bun/PyPI behavior so it does not imply a plain bundle install fixes the shared copy.

CLI contract, ecosystems docs, unit tests, and a new e2e for rollback/remove encode the behavior. No new on-disk refresh behavior beyond warning text and reinstall guidance.

Reviewed by Cursor Bugbot for commit 7297439. Configure here.

The unwind warning now prints each `rm -f` path through `shell_word`,
which single-quotes any path holding a character outside the safe set.
A Windows path (backslashes) or a temp dir with a space is printed
quoted, but three tests still expected the bare `display()` form:
`an_unwind_names_no_rerun_for_a_shared_home`,
`vendored_unwind_warns_once_in_a_human_run` and
`hosted_unwind_names_no_rerun_for_a_shared_gem_home`. Build the
expected words with the same quoting (a test-side copy of `shell_word`
in the e2e file) so they hold on Windows and with TMPDIR containing a
space. Verified on Linux with both the default TMPDIR and one with a
space.

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_011f9aeQRihEsBSmrqzYJhYi
@mikolalysenko

Copy link
Copy Markdown
Collaborator Author

[agent] PR shepherd: review brief for the approver

What it does
After a hosted gem rollback or remove, a patched copy left in a shared gem home was reported with "re-run with --gem-refresh-shared". That can't work: the first run already removed the patch, so the re-run exits 1 with "nothing to roll back". On that unwind path the warning now names two remedies that do work: the project-local bundle config … path vendor/bundle line, or a shell-quoted rm -f <spec> <cache archive> && bundle install, with what that costs other projects. The scan direction's text is unchanged.

Risk: low. Only message text, a new shell-quoting helper (POSIX single quotes with '\'' escaping, on absolute paths) and docs. No file operation changes. Every stale gem on the unwind path is built with in_place: false, so the in-place branch that still says "re-run" is reachable only from a scan, where a re-run works.

Look here

  • gem_refresh.rs#L424: shell_word / reinstall_command
  • gem_refresh.rs#L519: per-gem --json detail, unwind branch
  • gem_refresh.rs#L809: human summary, unwind branch
  • rollback.rs#L444: Bundler qualifier on the reinstall note
  • [e2e_redirect_gem_stale_install.rs#L2588](https://github.com/SocketDev/socket-patch/blob/05983230c08e33aa58217d259d4a2396afc42684/crates/socket-patch-cli/tests/e2e_redirect_gem_stale_install.rs#L2588): end-to-end test for rollback and remove, human and --json

Verified

  • cargo test -p socket-patch-cli --lib -- gem_refresh:: rollback::tests::reinstall: 14 passed. --test e2e_redirect_gem_stale_install: 53 passed.
  • With main's gem_refresh.rs and this PR's tests, 3 unit tests and the e2e hosted_unwind_names_no_rerun_for_a_shared_gem_home fail, so the tests cover the fix.
  • rustfmt --check passes on the touched files. CHANGELOG.md is untouched, and there are no unrelated edits or debug leftovers. The description matches the code.
  • CI on 0598323: ci-ok and clippy green; 34 checks passed, 20 skipped, none failed.

Changes I made
None in this review. The previous run pushed 0598323 (test expectations follow the shell quoting).

Open questions (neither blocks merging)

  1. The contract used to say a shared gem home never gets a delete list. On the unwind path it now does (rm -f of the gemspec and the cached archive), because nothing else can replace the shared copy after the unwind. Is that acceptable, or should the warning name only the project-local path?
  2. rollback --dry-run still doesn't warn that the real run will leave a shared copy behind, so the one run where --gem-refresh-shared works is never pointed out in advance. Worth a follow-up 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 Nov 19, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[agent] Reviewed at 0598323. Text only, branching on Direction; the scan-direction text is unchanged and may_replace changes only its reason string. The unwind warning now names a command that can work, and shell_word quoting is correct. Non-blocking: this prints a delete command for a shared gem home, which the earlier contract said never gets a delete list (flagged by the author); rollback --dry-run still does not preview the shared copy left behind.

Merged via the queue into main with commit 26d112f Nov 19, 2026
54 checks passed
@mikolalysenko
Mikola Lysenko (mikolalysenko) deleted the agent/fix-gem-unwind-shared-rerun-remedy branch November 19, 2026 14:53
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

3 participants