You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 7bde3ba
Browse filesBrowse the repository at this point in the historyBrowse files
Rebuild gem native extensions in agent-mode apply (#1996) (#1998)
* Rebuild gem native extensions in agent-mode apply (#1996)
Agent-mode apply rewrote a gem's ext/**/*.c in place and reported it
patched, while Ruby kept loading the extension compiled at install time.
When a gem record changes a native-extension build input, apply now
writes the patched sources and rebuilds the extension with RubyGems' own
builder (the step `gem pristine --extensions` runs), using the Ruby that
owns the install. The old build is moved aside first (ExtConfBuilder
never overwrites files already in the extension dir) and backed up once
inside the gem dir; a marker records the source hashes it was built from
and every artifact's hash, including the lib/ copies Ruby may load.
- A failed build puts the sources and the previous build back:
native_extension_build_failed.
- A copy that cannot be rebuilt (precompiled platform gem, no
specifications entry, no matching Ruby) is refused with
native_extensions_unsupported and nothing is written.
- Sources an earlier release patched without a rebuild are rebuilt
(native_extension_rebuilt warning).
- vex / apply --check attest only when the marker matches
(native_extension_not_rebuilt otherwise); hosted copies are unaffected.
- rollback restores the backed-up original build, or rebuilds from the
restored sources without one (native_extension_restore_failed).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Harden gem native rebuild; add --no-gem-native-rebuild
Review fixes:
- rollback restores only the gem's own extensions/<plat>/<abi>/<gem>
dir under its home; a backup or marker naming any other path (or a
symlink) is refused before anything is deleted.
- In a gem that declares no extensions, only C sources under ext/ are
native inputs (templates and fixtures elsewhere stay plain files); a
root-level build script makes only top-level files inputs.
- A build whose record cannot be written is undone like a failed one.
- The Ruby must build into an installed extension dir; a gem without
one (RubyGems < 2.2) is refused.
- Lib copies are restored by stage + rename, never rewritten in place
under a process that has them mapped.
- A build timeout kills the whole process group (Unix).
- Probe output tolerates stray stdout lines; the script requires
rubygems itself (Ruby 1.8 with RUBYOPT cleared) and names a RubyGems
older than 2.2.
- Share gemspec_declares_extensions and copy_tree_blocking.
--no-gem-native-rebuild (SOCKET_NO_GEM_NATIVE_REBUILD) is for a caller
that compiles the extension itself, such as the patches evaluation
harness: sources are written without a rebuild, with a
native_extension_not_rebuilt warning, and vex does not attest them.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Bound gem builds in utils::process; guard reads; dry-run rebuild
- CI (child_deadline_guard): the Ruby probe/build no longer keeps its
own kill_on_drop deadline. New utils::process::build_output_within is
the bounded spawn for builds: stdout and stderr captured, the child in
its own process group (Unix) killed whole at the deadline.
- Bugbot: the lib-copy snapshot, the previous marker, backup.json and
the backed-up lib copies are read through the regular-file guard, so a
FIFO in the gem dir fails fast instead of hanging apply or rollback.
- Bugbot: a dry run over sources that are already patched but whose
extension was not built from them warns native_extension_rebuilt
("apply would rebuild it") instead of reading as plain already_patched.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Copy file name to clipboardExpand all lines: crates/socket-patch-cli/CLI_CONTRACT.md
+43Lines changed: 43 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -705,6 +705,49 @@ are patched by `socket-patch apply` like every other ecosystem:
705
705
or a bare `--global-prefix` cache with no known `go install` directory) the same warning code says
706
706
so, and VEX is not withheld (#422).
707
707
708
+
### Ruby gems with native extensions in agent mode
709
+
710
+
Ruby loads the extension RubyGems compiled at install time
711
+
(`extensions/<platform>/<abi>/<gem>-<version>/`, and its copy under the gem's `lib/`), never
712
+
the `ext/` sources beside it. When a gem record changes a native-extension build input, `apply`
713
+
writes the patched sources and then rebuilds the extension from them with RubyGems' own builder
714
+
(the step `gem pristine --extensions` runs), using the Ruby that owns the install: the one in
715
+
`<prefix>/bin` of a `<prefix>/lib/ruby/gems/<abi>` home, else the `ruby` on `PATH` run from
716
+
`--cwd`. A build input is a changed `.c`, `.h`, `.cc`, `.cpp`, `.cxx`, `.hh`, `.hpp`, `.hxx`,
717
+
`.m`, `.y` or `.rl` file, an `extconf.rb`, a `depend` under `ext/`, or any file under the
718
+
directory of a build script the installed gemspec's `extensions` names (a script at the gem root:
719
+
the files beside it) (#1996). In a gem that declares no extensions, only such a source under
720
+
`ext/` is one (where a precompiled platform gem keeps the sources of the binary it ships), and
721
+
never a grammar file (`.y`, `.rl`), whose generated output the gem packs. The Ruby must build into
722
+
the gem's installed `extensions/<platform>/<abi>/` dir; a gem without one (installed by a RubyGems
723
+
older than 2.2) is refused. The rebuild runs the gem's own build scripts, as `gem install` did.
724
+
725
+
The first rebuild of a copy backs up the install-time build (extension directory and `lib/`
726
+
copies) to `.socket-patch-native-orig/` in the gem directory, and every rebuild records
727
+
`.socket-patch-native-build.json` there: the source hashes it was built from and the hash of every
728
+
artifact it produced. A record whose sources are patched and whose marker matches is
729
+
`already_patched`; sources an earlier release patched without a rebuild are rebuilt, with a
730
+
`native_extension_rebuilt` warning. `rollback` (and `remove`) puts the backed-up build back with
731
+
the sources; without a backup it rebuilds from the restored sources. Only the gem's own
732
+
extension dir under its home is ever replaced, whatever path the backup or marker names.
733
+
734
+
`--no-gem-native-rebuild` (env `SOCKET_NO_GEM_NATIVE_REBUILD`) is for a caller that compiles the
735
+
extension itself (the patches evaluation harness): the patched sources are written as before #1996,
736
+
with no Ruby run and no backup or marker, and the run succeeds with a `native_extension_not_rebuilt`
737
+
warning. `vex` and `apply --check` then omit the patch until a rebuild by `apply` records it.
738
+
739
+
| Code | Run result | Meaning |
740
+
|---|---|---|
741
+
| `native_extensions_unsupported` | refused, exit 1 | The record changes build inputs that cannot be rebuilt in place: the copy is not a RubyGems install with a `specifications/` entry (a Bundler git checkout), the gem declares no extensions (a precompiled platform gem), or no Ruby whose extension directory for the gem is the installed one was found. Nothing is written; use `scan --mode hosted`, where RubyGems compiles the patched gem. |
742
+
| `native_extension_build_failed` | refused, exit 1 | The extension did not build from the patched sources (no compiler or Ruby headers, a build error). The previous build and the original sources are put back; the error carries the build output's tail. |
743
+
| `native_extension_rebuilt` | warning | The sources were already patched (by a release before #1996) and the extension was rebuilt from them. |
744
+
| `native_extension_not_rebuilt` | warning | `--no-gem-native-rebuild`: the sources were written without a rebuild; Ruby loads the old build until the caller compiles it. |
745
+
| `native_extension_restore_failed` | rollback: that copy fails | The sources were restored, but the original compiled extension could not be put back. Run `gem pristine <gem> --extensions`. |
746
+
747
+
`vex` and `apply --check` attest such a copy only while its marker matches the record's patched
748
+
sources and every artifact it lists; otherwise the purl fails with `native_extension_not_rebuilt`.
749
+
Hosted copies are judged on their files alone, since RubyGems compiled them from the patched gem.
0 commit comments