Behind a private gem mirror a hosted gem pin cannot be undone: `rollback` and `remove` refuse on a `CHECKSUMS` lock, and without `CHECKSUMS` `rollback` leaves the patched builds installed with no warning that names them

未关闭
#2,230 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@mikolalysenko 已经在做这个了。

开始于 2026年11月25日。

  • #2233 来自 @mikolalysenko —— 未关闭

评估

难度
4/5
预计耗时
3-5 天
新手友好度
12/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
技术栈
ruby, rust
领域
build-system, cli

调研方向

The refusal is raised in crates/socket-patch-core/src/patch/redirect/upstream/gem.rs (the same_remote check against RUBYGEMS_REMOTE, around line 1410), and the stale-install warning is in crates/socket-patch-cli/src/commands/gem_refresh.rs. Read CLI_CONTRACT.md's 'The unwind is exact' and 'Gem stale-install guard' sections first, and check open PR #2233 before starting, since it is already linked. Done means rollback and remove restore the pre-scan Gemfile and Gemfile.lock on a CHECKSUMS lock with a mirror source, or the scan declines to wire the gem, and the Bundler 2.5 case names the patched files to remove.

由索引模型根据 Issue 内容生成。

描述

agent:claimed agent:triaged bug bughunt pm:bundler priority:p1

[agent] Found by the scheduled Bundler (RubyGems) bug-hunt routine (ledger #316).

Summary

When a project's Gemfile names a private gem mirror as its source (source "https://gems.example.com": Artifactory, Nexus, Gemstash, a static gem generate_index server), scan --mode hosted wires the gems and replaces the installed copies with the patched builds as usual, but the pin can't be undone with socket-patch afterwards:

  • Lock with CHECKSUMS (Bundler 2.6 and later, 4.x): rollback and remove always refuse with "its upstream GEM remote … is not rubygems.org, so its CHECKSUMS sha256 cannot be re-derived" (exit 1). The scan that wired the gem printed socket-patch rollback pkg:gem/<gem>@<version> as the way to move it to a newer release, so its own remedy can't be followed. The refusal's remedy, git checkout -- Gemfile Gemfile.lock, restores the pair but leaves the patched builds in vendor/bundle: the app keeps loading the patched code, socket-patch rollback then says "No patches in this project", and bundle pristine fails on the checksum (exit 37), removes the gems, and the app no longer loads.
  • Lock without CHECKSUMS (Bundler 2.5): rollback exits 0 and restores the pair byte for byte, but leaves the patched builds installed and says only "2 unwired packages keep their patched bytes in installed trees until the next package-manager install". That is not true for Bundler: bundle install keeps them and bundle pristine reinstalls them from the patched archive in cache/. No upstream_gem_stale_install warning names the files to remove.

The mirror serves the very same .gem files as rubygems.org here (same sha256), so the checksum to restore is the one the lock held before the scan and the one the rubygems.org index lists.

A mirror set with bundle config mirror.https://rubygems.org is not affected (the lock still says remote: https://rubygems.org/). This is about a source line that names the mirror, which is how many companies reach gems.

Impact

A project that installed cleanly can't get back to its pre-scan state with the tool. On Bundler 2.6+ the documented way out ends in a failing bundle pristine and a broken gem home. On Bundler 2.5 rollback reports success while the app still runs the patched gems. rollback pkg:gem/<gem>@<version> of one gem out of several (to upgrade it, as the scan suggests) is impossible: git checkout of the pair drops every pin.

Repro

Uses the repo's stand-in patch service (tests/nokogiri/patch_service.rb) for rack 2.2.8 and rake 13.2.1 on a loopback port; every socket-patch call below also takes --api-url <mock> --patch-server-url <mock> --api-token fake --org nokogiri-e2e. Ruby 3.3.6.

# a private mirror holding the unmodified upstream gems
mkdir -p mirror/gems && cd mirror
(cd gems && gem fetch rack -v 2.2.8 && gem fetch rake -v 13.2.1)
gem generate_index -d . && python3 -m http.server 18091 --bind 127.0.0.1 &
cd ..

mkdir app && cd app
printf 'source "http://127.0.0.1:18091"\n\ngem "rack", "2.2.8"\ngem "rake", "13.2.1"\n' > Gemfile
bundle config set --local path vendor/bundle && bundle install   # Bundler 4.0.18
cp Gemfile Gemfile.orig && cp Gemfile.lock Gemfile.lock.orig

socket-patch scan --mode hosted
#   Replaced the installed copy of 2 gems with the patched build: rack 2.2.8, rake 13.2.1.
#   ... To move one to a newer release, run `socket-patch rollback pkg:gem/<gem>@<version>`, ...

socket-patch rollback pkg:gem/[email protected]      # exit 1
#   Error: Cannot restore pkg:gem/[email protected] to its upstream registry entry: its upstream GEM remote
#   http://127.0.0.1:18091/ is not rubygems.org, so its CHECKSUMS sha256 cannot be re-derived; restore it
#   from version control instead (`git checkout -- Gemfile Gemfile.lock`)
socket-patch remove pkg:gem/[email protected]        # same error, exit 1
SOCKET_RUBYGEMS_URL=http://127.0.0.1:18091 socket-patch rollback   # same error

# the remedy the refusal names
cp Gemfile.orig Gemfile && cp Gemfile.lock.orig Gemfile.lock
bundle install            # "Bundle complete!"; the app still loads the patched rack and rake
socket-patch rollback     # Error: No patches in this project; nothing to roll back.
bundle pristine           # exit 37: "Bundler found mismatched checksums", gems removed
bundle exec ruby -e 'require "rack"'   # LoadError

With Bundler 2.5.22 (no CHECKSUMS section) on the same project:

socket-patch scan --mode hosted
socket-patch rollback     # exit 0, Gemfile and Gemfile.lock byte-identical to the originals
#   Note: 2 unwired packages keep their patched bytes in installed trees until the next package-manager install.
bundle install && bundle pristine
bundle exec ruby app.rb   # still the patched rack and rake

rollback --json there has status: success and one warning, reinstall_required; no upstream_gem_stale_install.

Expected

  • CLI_CONTRACT.md ("The unwind is exact"): rollback / remove give back the pre-scan pair byte for byte. The task of this routine states the same bar. If hosted mode can't undo a pin for a lock it is about to edit, the scan should either not wire the gem (warn and name --mode agent), or be able to restore it: the pre-scan sha256 is in the lock the scan rewrites, the upstream archive is in the gem home's cache/ before the scan replaces it, and the mirror serves a compact index (info/<name>) with the checksum.
  • The hold note should not offer socket-patch rollback pkg:gem/<gem>@<version> where it will refuse.
  • CLI_CONTRACT.md ("Gem stale-install guard", the unwind direction): "a gem from another remote is refreshed only from an archive already on disk" and "what is still the patched build is warned about once (upstream_gem_stale_install)", naming the files to remove before bundle install. On the Bundler 2.5 lock no such warning is printed, only the generic note, whose "next package-manager install" does not replace anything under Bundler.

Actual

See the summary. On a CHECKSUMS lock the pin is one-way; without CHECKSUMS the pair is restored and the patched installs stay, unreported.

Versions

Result
main e685fb1 (5.1.0 + 33 commits), Bundler 4.0.18, Ruby 3.3.6, mirror as the only top-level source reproduces: rollback and remove refuse; git checkout remedy leaves patched installs, bundle pristine exits 37
main e685fb1, Bundler 2.5.22, Ruby 3.3.6, same project reproduces the second form: pair restored, patched builds stay, no upstream_gem_stale_install
main e685fb1, Bundler 4.0.18, source "https://rubygems.org" does not reproduce: "Replaced the installed copy of 1 gem with the upstream build", pair byte-exact

Linux only. Nothing here looks platform-specific. First bad release not searched; the refusal text predates 5.1.0.

Suspect code

  • crates/socket-patch-core/src/patch/redirect/upstream/gem.rs:1410 (the same_remote(&remote, RUBYGEMS_REMOTE) refusal; nothing on the scan side checks it before wiring).
  • crates/socket-patch-cli/src/commands/rollback.rs:2803 (the generic note) and crates/socket-patch-cli/src/commands/gem_refresh.rs:58 (upstream_gem_stale_install, not raised for a gem from another remote with no upstream archive on disk).

Generated by Claude Code

主要语言
Rust
星标
9
派生
2
平均合并
1 天 8 小时
30 天内合并 PR
309

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

SocketDev/socket-patch 的其他 Issue

查看 SocketDev/socket-patch 的全部 Issue

相似的 Issue

更多 Rust Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。