Repository navigation
Fix in-place gem rebuild ignoring in-tree build products (#2104, #2105) - #2108
Conversation
Claim commit for #2104 and #2105: the in-place rebuild of a gem's native extension neither backs up nor records the libraries the build leaves in the gem's own tree. 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_011f9aePpTeM1ZTDzN1jcpr1
Three host capstones over a gem that builds its library into its own tree and loads it from there. Each fails on main: - rollback leaves the patched library in place, and nothing records it (#2104) - a build that takes the old library for current passes for a rebuild, with and without the source gem to compare (#2105) 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_011f9aePpTeM1ZTDzN1jcpr1
A gem that builds a library into its own tree and loads it from there (scrypt, digest-crc) has no artifact in the RubyGems extension dir, which is all the in-place rebuild backed up, recorded and put back. The rebuild now snapshots the gem's tree before the build. What a finished build replaced or added there is backed up with the original build and attested by the marker, so rollback restores it byte for byte and vex notices it changing (#2104). A failed or interrupted build is undone from the snapshot. The products the source gem's build was seen to make are removed before the in-place build, as a fresh install has none, so a build script that takes an existing library for current compiles the patched source. With none known, a build of a changed input that leaves no compiled code changed fails instead of passing for a rebuild (#2105). 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_011f9aePpTeM1ZTDzN1jcpr1
From the review of the previous commit: - Keep the tree snapshot beside the parked extension dir, not in the gem dir, where a build script that globs for sources would find a second copy of them. - Leave the parked build in place when the tree cannot be put back, so the next run retries from the snapshot instead of dropping it. - Refuse a build that compiled nothing only for a gem that keeps a library in its own tree. A gem with no library anywhere compiles nothing on this platform, and passes as before. - Hand the products the source gem's build makes to a rollback's in-place rebuild too, and hold that rebuild to the same check. - Attest and back up a product that was rebuilt with the bytes it had, so the restore does not take it for one to remove. - Hash a snapshotted file from the bytes already read. 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_011f9aePpTeM1ZTDzN1jcpr1
|
[agent] bugbot run Generated by Claude Code |
PR SummaryMedium Risk Overview Before running the build, known in-tree build products from a staged source-gem build are removed so scripts that reuse an existing library cannot skip compiling patched sources. Builds that exit successfully but produce no new compiled artifacts are rejected as Failed or interrupted in-place rebuilds restore the gem tree from the snapshot (alongside extension-dir recovery). Docs and e2e/unit tests cover attestation, stale-library forcing, and compile-nothing refusal. Reviewed by Cursor Bugbot for commit f8e88d0. Configure here. |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
❌ 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 f8e88d0. Configure here.
A run that died after it wrote the marker of an in-place build, before it dropped the parked build and the tree snapshot, left all three on disk. The next run restored the gem's tree from the snapshot, putting the old in-tree library back under a finished build. Recovery now tells that state apart: the extension dir is a finished build, and the marker was written after the snapshot was taken and matches the tree. Such a build stands, and the snapshot is dropped. Found by Cursor Bugbot on the PR. 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_011f9aePpTeM1ZTDzN1jcpr1
|
[agent] PR shepherd: review brief What it does Risk: medium. Only the in-place gem rebuild path changes. Staged builds from the source gem and precompiled gems are untouched, but this new path writes, deletes and restores files inside a user's installed gem. The backup and marker formats only gain entries, and older releases ignore Look here
Verified
Changes I made Open questions (non-blocking)
Generated by Claude Code |
Main gained the in-tree build products fix (#2108) and the hosted scan's refresh of the archive beside an agent-patched gem (#2103). Both touch files this branch changes; three hunks conflicted, each resolved by keeping both sides. crates/socket-patch-core/src/patch/gem_ext.rs, `recover_interrupted_rebuild_sync`: this branch's `refuse_link(&ext, ..)` (a link, or an extension dir that cannot be probed, is refused) in place of main's unchanged `is_symlink` check, followed by main's new restore of the gem's tree from the snapshot of an interrupted in-place build. crates/socket-patch-cli/src/commands/gem_refresh.rs, `report`: main's two headlines for gems patched in place become arms of this branch's `known` headline, which the count of copies that could not be checked is then added to. The words "the switch to hosted patches" come from `switch`. crates/socket-patch-cli/src/commands/gem_refresh.rs, `stale_after_restore`: this branch's listing of a copy that cannot be judged whether or not its archive is cached, with main's new `in_place: false` field. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The in-tree build products fix (#2108) acts on what a listing lacks: a file the tree snapshot does not show is removed when a build is undone, and a rollback removes what the marker lists and the backup does not hold. Its probes read an error as "nothing there": - `restore_tree` listed the snapshot's copies with a walk that skips what it cannot read. A snapshot whose copies could not be listed was read as holding none, and every file of the gem's own tree was removed. `snapshot_tree` listed the gem's tree the same way, so a directory that could not be read was left out and its files were the next undo's to remove. Both now use `try_tree_files`, which fails instead. - Recovery took a snapshot dir it could not probe for no snapshot and settled the extension dir without putting the tree back; so did the failed-snapshot path of `rebuild`. `build_committed_since` took a marker it could not probe for no marker. Each is an error now. - `back_up_tree_changes` and `note_absent_files` took a backup description that is there and cannot be read for no backup, recorded nothing, and let the build be committed. `try_read_backup_info` fails instead, and the build is undone. The marker and backup formats are as #2108 left them, and `read_marker_strict` and the restore read them unchanged. The contract still said an in-place rebuild leaves a library in the gem's own tree as last built, next to #2108's account of backing it up. That sentence now says what the code does. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

LLM Description written by Claude Code:claude-fable-5-2
Fixes #2104
Fixes #2105
Summary
An agent-mode patch to a native build input of a gem that builds a library into its own tree and loads it from there (scrypt via ffi-compiler, digest-crc via a Rakefile) is rebuilt in the installed tree. That in-place rebuild only knew about the RubyGems extension dir, which such a gem leaves empty. This PR makes it track what the build does to the gem's own tree:
rollbacknow restores the library (and every other file) the build replaced, byte for byte (Agentrollbackof a gem that builds its library in its own tree (scrypt, ffi-compiler gems) restores the source but leaves the patched binary loaded, and no command lists it afterwards #2104).apply --checkandvexstop attesting once one changes.applyreports a digest-crc C patch applied andvexattests it, but the gem's Rakefile build is a no-op and Ruby keeps loading the unpatched extension #2105). The products the source gem's build makes are removed first, so the patched source is compiled. When they aren't known (no source gem) and the build changes no compiled code, the package fails withnative_extension_build_failedand the gem is left as it was.Staged rebuilds from the source gem (the normal path) and precompiled gems are not changed.
Root cause
rebuildincrates/socket-patch-core/src/patch/gem_ext.rsbacked up, recorded and restoredartifact_rels(extension_dir)and theirlib/copies only. For an in-tree gem that set is empty: the marker was written with"extArtifacts": {}, "libArtifacts": {}, so nothing was backed up, nothing could be verified, and a build that exited 0 was trusted whatever it produced.How it works
extensions/<platform>/<abi>/.<gem>.socket-patch-tree, beside the parked build and outside the gem dir. The record's own files are left out: the patch engine writes and reverts those.StageFailure::InTree) are removed, as a fresh install has none of them..socket-patch-native-orig/lib/, listed inlibFiles); added files are listed in a newcreatedFilesfield. Loadable ones are hashed into the marker'slibArtifacts.recover_interrupted_rebuilddoes the same for a run that died.The backup and marker formats only gain entries: an older release reads the new
libFilesandlibArtifactsentries with its existing code and ignorescreatedFiles.Evidence
Real gems, Ruby 3.3.6, Linux (the repros from the issues):
applyexit 0,patched=false,vexnot_affectedpatched=trueafter apply;rollbackgivespatched=false;diff -rqof the wholevendor/against the pre-apply copy is empty.soleft afterrollbackext/scrypt/x86_64-linux/libscrypt_ext.so; afterrollbacknm -Dshows no patched symbol anddiff -rqis emptyTests (all failed on main, commit
1d18d1eadds them before the fix):rollbackof a gem that builds its library in its own tree (scrypt, ffi-compiler gems) restores the source but leaves the patched binary loaded, and no command lists it afterwards #2104:a_gem_that_loads_its_library_from_its_own_tree_is_rebuilt_in_place(e2e) andan_in_place_build_of_the_gems_own_tree_is_recorded_and_restored(unit).applyreports a digest-crc C patch applied andvexattests it, but the gem's Rakefile build is a no-op and Ruby keeps loading the unpatched extension #2105:a_build_that_keeps_a_stale_library_is_made_to_rebuild_itanda_build_that_compiles_nothing_is_refused_and_not_attested(e2e),a_build_that_leaves_no_compiled_code_is_stale(unit).a_failed_in_place_build_leaves_the_gems_own_tree_as_it_was,an_interrupted_in_place_build_gets_its_tree_back,a_product_rebuilt_with_the_same_bytes_survives_the_restore(unit).Local runs:
cargo clippy --all-targetsfails locally on main too (44 errors in test code of files this PR does not touch); CI's clippy command does not use--all-targets.Review
/code-review highran on the diff. Fixed inf8e88d0: snapshot moved out of the gem dir, parked build kept when the tree can't be restored, the "compiled nothing" refusal limited to gems that keep a library in their tree, rollback's in-place rebuild given the known products, identical rebuilt products attested and backed up, one read per snapshotted file, shared helpers.Not fixed, with reasons:
Cursor Bugbot found one issue on
f8e88d0: recovery after a crash between writing the marker and dropping the parked build undid a committed build's tree. Fixed in82ed2bfwitha_committed_in_place_build_is_not_undone_by_the_next_run.Follow-ups
applycan never rebuild argon2, the gem the docs name as rebuilt from its installed tree: its one-shotextconf.rbfails onMakefile.real, and the remedy says to install a compiler #2106 (argon2's one-shotextconf.rb) is a different defect and still fails withnative_extension_build_failed.docs/ecosystems.mdnow names scrypt and digest-crc, which were verified, as the examples of in-tree gems..bundle/.dylibnames.https://claude.ai/code/session_011f9aePpTeM1ZTDzN1jcpr1
Generated by Claude Code