Repository navigation
Description
[agent] Found by the scheduled Bundler (RubyGems) bug-hunt routine (ledger #316).
Summary
docs/ecosystems.md ("Ruby gems: native extensions") names argon2 as the example of a gem that agent mode rebuilds from its installed tree: "A gem that builds a library into its own directory and loads it from there (an FFI gem such as argon2) is always rebuilt from its installed tree."
On a real argon2 2.3.0 install the rebuild can never succeed. The gem's ext/argon2_wrap/extconf.rb renames Makefile.real to Makefile, so after the first install the tree has no Makefile.real and a second run of extconf.rb raises Errno::ENOENT. Every agent-mode patch to an argon2 build input fails with native_extension_build_failed, and the remedy it prints first ("Install a compiler toolchain and the Ruby headers and apply again") does not help: both are installed.
The installed gem is left as it was and the app still works, so this is a missed patch plus a misleading remedy, not a broken install.
Impact
argon2 is a password-hashing gem, a likely target for a security patch to its C wrapper or its vendored phc-winner-argon2 sources. In agent mode such a patch cannot be applied, on any machine, and the documentation says it can.
Repro
Linux, Ruby 3.3.6, a compiler toolchain. No Socket API needed: the record is written by hand.
mkdir argon2-repro && cd argon2-repro
printf 'source "https://rubygems.org"\ngem "argon2", "2.3.0"\n' > Gemfile
bundle config set --local path vendor/bundle && bundle install
G=vendor/bundle/ruby/3.3.0/gems/argon2-2.3.0
# mkrec.py: write an agent-mode record (.socket/manifest.json + blobs) for one changed file
cat > mkrec.py <<'PY'
import sys, json, hashlib, os
purl, key, before, after = sys.argv[1:5]
os.makedirs(".socket/blobs", exist_ok=True)
def gh(b): return hashlib.sha256(b"blob %d\0" % len(b) + b).hexdigest()
b, a = open(before, "rb").read(), open(after, "rb").read()
for x in (b, a): open(".socket/blobs/" + gh(x), "wb").write(x)
json.dump({"patches": {purl: {"uuid": "77777777-7777-4777-8777-777777777772",
"exportedAt": "2026-01-01T00:00:00Z",
"files": {key: {"beforeHash": gh(b), "afterHash": gh(a)}},
"vulnerabilities": {"GHSA-aaaa-bbbb-cccc": {"cves": ["CVE-2026-0001"], "summary": "s", "severity": "HIGH", "description": "d"}},
"description": "synthetic test patch", "license": "MIT", "tier": "free"}}},
open(".socket/manifest.json", "w"), indent=2)
PY
cp $G/ext/argon2_wrap/argon_wrap.c before.c
(cat before.c; printf '\nint socket_patched_marker(void) { return 1; }\n') > after.c
python3 mkrec.py pkg:gem/argon2@2.3.0 ext/argon2_wrap/argon_wrap.c before.c after.c
socket-patch apply; echo "exit=$?" # exit=1Expected
The patch applies, as the docs say for this gem by name, for example by building from the source gem in a stage directory that sits at the installed gem's path layout, or by restoring the files a first build consumed (Makefile.real is in the source gem in cache/) before the in-place build.
If that is not possible, the docs should not name argon2, and the error should say that this gem cannot be rebuilt in place and point at hosted mode only.
Actual
Error: Failed to patch pkg:gem/argon2@2.3.0: native_extension_build_failed: the native extension did not build from the patched sources (ext/argon2_wrap/argon_wrap.c); the sources and the previous build were put back. Install a compiler toolchain and the Ruby headers and apply again, or use `socket-patch scan --mode hosted`. It was built from the installed gem's own files, which a build can leave incomplete, because it could not be rebuilt from its source gem (the source gem's build leaves lib/libargon2_wrap.so in the gem's own tree, which is where it is loaded from, and a build staged elsewhere cannot take its place).
.../rubygems/ext/builder.rb:125:in `run': ERROR: Failed to build gem native extension. (Gem::Ext::BuildError)
current directory: .../vendor/bundle/ruby/3.3.0/gems/argon2-2.3.0/ext/argon2_wrap
/opt/rbenv/versions/3.3.6/bin/ruby extconf.rb
extconf.rb:5:in `rename': No such file or directory @ rb_file_s_rename - (Makefile.real, Makefile) (Errno::ENOENT)
extconf failed, exit code 1
Summary: 0 of 1 targeted patch applied, 0 already patched, 1 failed, 0 not found on disk
The whole message is printed twice (once as Error:, once as Warning:). The gem tree is unchanged afterwards and Argon2::Password.create still works.
Versions
| socket-patch | Ruby | Bundler | Result |
|---|---|---|---|
main 3b14afc |
3.3.6 | 4.0.18 | fails as above |
main 3b14afc |
3.3.6 | 2.6.9 | fails as above |
| 5.1.0 release | 3.3.6 | 4.0.18 | fails the same way (in-place build) |
scrypt 3.0.8, another FFI gem built in its own tree, does rebuild in place on the same versions.
Linux only was tested; the cause is the gem's one-shot extconf.rb, so macOS should behave the same.
First bad version
5.1.0 fails the same way. The sentence naming argon2 was added to the docs by #2098 (610ba8d).
Suspect code
crates/socket-patch-core/src/patch/gem_ext.rs:2638-2690 (the decision that a gem with in-tree products "can still be rebuilt in place, from its own tree") and gem_ext.rs:2372 (rebuild). docs/ecosystems.md:2016.
Generated by Claude Code
Activity
bundler: 2026-11-17 run (agent native rebuild; #2104, #2105, #2106)
mikolalysenko commentedon Nov 18, 2026
[agent] Janitor: partial change on
main, leaving this open. #2112 (89c482d) rewrote the paragraph indocs/ecosystems.md: it now names scrypt and digest-crc as gems rebuilt from their installed tree (docs/ecosystems.md:2031) and no longer names argon2. The defect itself is not addressed: nothing onorigin/maindeals with argon2'sextconf.rbrenamingMakefile.real, so an agent-mode patch to an argon2 build input should still fail withnative_extension_build_failedand print the compiler-toolchain remedy. The Bundler ledger (#316) still lists this as a fail on89c482d.Generated by Claude Code
Show the cause of a failed gem extension build
mikolalysenko commentedon Nov 19, 2026
[agent] Claiming this issue. Branch: agent/fix-gem-in-place-consumed-build-files.
Generated by Claude Code
Test a gem build script that uses up a file
Give a gem build the files its first run used up
Give used-up gem files back with their own times