Repository navigation
Agent mode: apply gem patches on JRuby, and fail the run when a gem patch is written but not in effect - #2155
Mikola Lysenko (mikolalysenko) wants to merge 15 commits into
Conversation
On JRuby a gem is installed as its java platform build, whose compiled code is jars. A record that changed any native build input was refused there with native_extensions_unsupported and nothing was written, so only Ruby-only patches applied, and a patch with a Ruby half and a C half applied nothing at all. The records are written for the ruby platform gem, and the java gem of the same release is another archive: it ships the Ruby files, often the C sources too (nothing on JRuby compiles them), and none of what only a C build reads. apply now gives such a copy the files of the record that are part of its own build, decided per file: - A file the record replaces that the copy holds is verified and written like any patch file. Content that is neither side of the record is the usual mismatch. - A file the record replaces that the copy does not hold is not part of that platform's gem: not written, not required, not missing. - A file the record adds is created, unless it is an input of a C build by its path (under ext/, patches/ or ports/, or a source or build file by name). No Ruby is started, nothing is built and no marker is written. With its applicable files written the record is applied: apply --check is in sync, vex attests it, a second apply has nothing to do and rollback restores what was written. When no file of the record is part of the build, the code the patch changes is not in it: the run exits 0, writes nothing and reports the patch as skipped with not_in_platform_build (a Note on stderr and "N not applicable" in the summary for a person), and the copy is in sync and attested. It is the rule Socket's backend follows when it builds a patched java platform gem, so a copy patched in place holds the same files as one installed from that gem. What cannot be done here is rebuild a jar. A record that names a JVM build input (a .java, .kt or .scala source, a Maven, Ant or Gradle build file, a .jar or .class file) has its applicable files written through the written-without-build path, with the native_extension_not_rebuilt warning, and is never attested. The same rule is read wherever a record is compared with an installed copy, through gem_ext::installed_files: matching a release variant to the copy (discriminating_files), verify_native_build, the vex and apply --check verifier (verify_every_gem_copy) and rollback_files. The hosted verifier and the stale-install probes are not changed here. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The JRuby leg expected a C record to be refused. All three scenarios now pass on a java install of nokogiri: the Ruby record is applied and loaded; the C record's file is written (the java gem ships the C sources), the patch is in sync and attested, and the probe shows no C constant and the jars JRuby loaded before; the libxml2 record has no file in that gem, so apply exits 0, writes nothing and says so, and the install is in sync and attested. Each ends in a rollback to a byte-identical tree. The probe now reports the jars JRuby loaded with their digests. `--build refused` had no other user and is gone. The workflow gets a second JRuby leg, 10.1, the newest release. The pinned setup-ruby knew JRuby up to 10.0.4, so the two setup-ruby steps of this workflow move to v1.338.0, and the JRuby legs set up Java 21 themselves instead of depending on the JDKs of the runner image. tests/docker/Dockerfile.jruby is a JDK with JRuby and Bundler for running the harness on a machine that has neither. The binary under test is mounted, not baked in. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The CLI contract and the ecosystem guide said that the JRuby build of a gem is always refused for a patch to a native build input. They now describe the per-file rule, the not_in_platform_build skip, and the one case that is written and never attested: a patch to what the gem's jars are built from. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
- A java gem that declares extensions (jruby-launcher compiles a native launcher when it is installed) took the JVM path, which builds nothing, so a patch to its C source was written and attested over the old build. The JVM path is now only for a JVM-platform copy whose gemspec declares no extensions. One that declares them is rebuilt like any gem RubyGems built, as before this change. - .jar and .class counted as JVM build inputs, so a record that replaces a jar whole was warned as not in effect and never attested, although JRuby loads the patched jar. Build inputs are sources and build files only; a replaced jar is a plain file of the patch. - The per-file rule (skip a file the copy lacks) applied to every record on a JVM copy in apply, the verifier and rollback; only variant matching kept it to the ruby-platform record. It is for that record in every reader now. A record qualified for a platform, the copy's own java included, is applied whole: a file the copy lacks is the usual missing file. - A not_in_platform_build skip was not counted among the patches a run left in place by the callers that knew only applied and already_patched, so an agent-mode scan left out an advisory that apply --check and vex count as covered. One predicate decides it for all of them. - The summary counted the native_extension_not_rebuilt form of a copy left as it was as "not applicable". It reads "not in effect": that patch does concern the build. - A copy left as it was was recovered by parsing the note of a successful ApplyResult. It is a typed outcome of the gem apply now (LeftAsIs on GemApplied), which the apply command carries beside its results and reports as the patch's skipped event. - vex and apply --check read each gem copy's gemspec twice per record. The verifier reads it once (InstalledGem). - scope_of survived only for tests, a refusal and a copy left as it was built the same result literal twice, and the dry-run warning repeated the wet one's text. The tests use what production uses, and the other two have one definition each. Kept as designed, and now said at the rule: a JVM copy that takes no file of a record, or only a C source nothing there compiles, counts as patched, and a file deleted from such a copy reads as one the build never had. A JVM build input is told by its file name wherever it sits. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The contract and the ecosystem guide now say which java gems the rule is for (no extensions declared), that it reads the ruby-platform record alone while a platform-qualified record is applied whole, that a jar the patch replaces is a plain file and is attested, and how the summary tells a patch with nothing to do from one that is not in effect. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
PR SummaryMedium Risk Overview When nothing in the patch applies to the JVM build, The CLI surfaces these as Docs ( Reviewed by Cursor Bugbot for commit d9a3d1c. Configure here. |
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
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 d9a3d1c. Configure here.
The rule that says which skipped apply events leave a package patched was read by scan from the apply command module, an import between command modules that the layering test forbids. It is about event codes, so it now lives with the event types, where both readers take it from. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
|
[agent] PR shepherd: the final review found two questions for the owner. I added 1. Should
Should that fix land in this PR, or in a follow-up with these doc comments softened for now? 2. Is exit 0 right when nothing of a patch could be applied?
Keep it exit 0 (and say so in the description), or refuse with Also worth an explicit sign-off (no change needed if accepted):
Everything else checked out: the tests would fail on Generated by Claude Code |
A gem patch whose compiled part cannot take effect was written and reported as applied, with exit 0 and a native_extension_not_rebuilt warning: a build that read none of the patch's inputs or left no compiled file, and on JRuby a record that changes sources of the gem's jars. A second run then read as already_patched, so an agent-mode scan counted the advisory as covered while apply --check and vex withheld it. Such a patch is incomplete, and apply now exits 1 for it, on the run that writes the files and on every later one. What is on disk is as before: the files the copy takes stay written, nothing is reverted, no build marker is written, apply --check stays out of sync and vex does not attest. The patch stays recorded, so rollback restores the files. The core result stays a successful write. Incomplete is a typed caveat beside it (GemCaveat::Incomplete on GemApplied, next to NotInBuild), and the apply command turns it into the failure: nothing in core can take it for a failed write and put files back, and the package's event gets its own code without parsing an error string. - The package's event is failed with errorCode native_extension_not_rebuilt, never applied or already_patched. Its error says that the files were written and what is not in effect, and its files list what this run wrote. The warning of the same code stays. The envelope is a partial failure. - A person gets one line, also under --silent: "Error: Patch of <purl> is incomplete: ...". The warning is not printed beside it, the package is not listed as patched, and the summary counts it as not in effect. - The apply that get and scan --mode agent run reports it as a failure of the patch under that code, so they exit 1 as for any failed package and count it among no patches left in place. They keep the record, as they do after any failed apply. - A dry run fails the same way where files alone show the outcome (the JRuby case); what only a build can show it still reports as a pending rebuild. - Not incomplete: --no-gem-native-rebuild (the caller compiles; exit 0 with its warning, now on JRuby too when the gem ships the source), a JRuby copy with nothing of the patch in its build, and already_patched. A best-effort fallback-home copy keeps its non-fatal skip. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The contract and the ecosystem guide said that a gem patch whose compiled part is not in effect is reported as applied with exit 0 and a warning. They now describe the incomplete outcome: the files stay written, apply exits 1 with a failed event and an Error line under native_extension_not_rebuilt, the patch stays recorded for rollback, what a dry run and --no-gem-native-rebuild do, and how the apply that get and scan --mode agent run reports it. The nokogiri harness expects the same of a system-libraries install. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
# Conflicts: # tests/nokogiri/nokogiri_e2e.rb
…mplete copies A second review of the JRuby support found cases where the rule gave the wrong answer. A Ruby file that a patch replaces and the JRuby copy does not hold was skipped as a file the java gem never shipped, so a patch whose target was deleted read as applied, or as having nothing to do there. Only an input of a C build may be absent now: a file under ext/, patches/ or ports/, or a C source or build file by name. Any other missing file is the usual missing-file failure. A record that changes a source of the gem's jars is no longer held up as incomplete when it brings the compiled code itself: when it replaces or adds a .jar or .class file, or when it is the record written for the copy's own platform (?platform=java). A platform gem's copy takes the record written for its own platform alone. apply already did that. apply --check, vex, rollback and the lookup of get and scan now select records the same way, so the ruby-platform record is not judged on a copy that has its own record. A package with an incomplete patch on one copy is not in effect. It is no longer counted or listed as applied because another copy took the patch, and an incomplete bundle-store copy does not make a fallback-home copy best-effort. rollback of a copy that holds no file of the patch reports not_in_platform_build (nothing of the patch was applied there, so there is nothing to restore) instead of no_files. A dry run with --no-gem-native-rebuild says what apply would do, not that it was done. GemCaveat's accessors that only tests used are gone, and the incomplete event takes its file list from the same helper as the applied one. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…s code vex attests a JRuby gem that holds no file of a patch, because the code the patch changes is not in that build. The statement said "Patched via Socket patch <uuid>" under inline_mitigations_already_exist, which is not what happened: nothing was patched. Such a package now gets an impact statement that says the code is not in the installed build of the package and names the patch whose files were looked for. A statement all of whose packages are of that kind carries the justification vulnerable_code_not_present. A statement that also covers a patched package keeps inline_mitigations_already_exist, with one impact part per package. A package with any copy that took a file of the patch is a patched package as before, and a document without such a package is unchanged byte for byte. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Hermetic tests on the hand-laid JRuby gem for each case the review found: a Ruby file missing from the copy, records that bring the jar or are the java gem's own, a manifest with both the ruby and the java record as apply, apply --check and vex read it, a package with one applied and one incomplete copy, rollback and vex after a patch with nothing in the build, and what a dry run with --no-gem-native-rebuild says. The nokogiri harness checks the VEX justification and the rollback event of a libxml2 patch on JRuby. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The contract and the ecosystem guide now say which files of a patch a JRuby gem may lack, which records a source of the gem's jars does not hold up, that a copy's own-platform record is its only record for every command, that a package with an incomplete copy is never applied, what the VEX statement says when the code is not in the build, what rollback reports for such a copy, and what a dry run with --no-gem-native-rebuild warns. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

Summary
Agent mode (
apply) now patches a gem on JRuby. Until now a patch thatchanges any native build input was refused outright on the
javabuild of agem (
native_extensions_unsupported, nothing written), so on JRuby onlyRuby-only patches applied, and a patch with a Ruby half and a C half applied
nothing at all.
The rule mirrors what Socket's backend does when it builds the patched
javaplatform gem for hosted mode, so agent mode leaves the same treehosted mode installs.
It also changes what
applyreports for any gem patch that is writtenbut not in effect: the run now fails with exit 1 (see "An incomplete patch
fails the run").
The rule
It applies to an installed copy whose platform is a JVM one (
java,jruby,universal-java-*) and whose gemspec declares no extensions, andto a patch record written for the ruby-platform gem (unqualified, or
?platform=ruby). Per file of the record:source the java gem happens to ship is simply updated; nothing on JRuby
compiles it.
ext/,patches/orports/, a C source or build script by name) is not part ofthis platform's gem: skipped, not required, not counted as missing. Any
other replaced file that is missing is the usual missing-file failure.
(
ext/,patches/,ports/, a C source or build script by name), whichmeans nothing to a gem with no C build.
.java,.kt,.scala,pom.xml,build.xml,build.gradle,build.gradle.kts,Mavenfile): the gem's jars were builtfrom these and nothing here can rebuild a jar. The record's applicable
files are written, the patch is incomplete (
native_extension_not_rebuilt,exit 1), and the copy is never attested. A record that itself replaces or
adds a
.jaror.classfile carries the compiled code and is not heldup by the sources beside it.
No Ruby is started, nothing is built, and no build marker is needed. A
record with no JVM build input is in sync for
apply --checkand attestedby
vexonce its applicable files are written. When no file of the recordconcerns the copy (a record that only adds a libxml2 patch file), the run
exits 0 with a
skippedevent, codenot_in_platform_build, aNote:lineand "N not applicable" in the summary; it is in sync and attested.
Left as they were:
javagem that declares extensions (jruby-launcher compiles anative launcher at install; checked against
jruby-launcher-2.0.2-java)keeps the native rebuild pipeline.
?platform=javaincluded, is applied whole: a missing file is the usual failure. When the
manifest holds a record for the copy's own platform, that record is the
copy's only record for every reader (
apply,apply --check,vex,rollback, and the lookupgetandscanuse).patch, written and attested.
verify,apply --check,vex,rollback,--dry-run, variant matchingand
scan --mode agentcoverage all read a record through the same rule.An incomplete patch fails the run
A gem patch can be written without being in effect: a build that exits
cleanly having compiled nothing of it (nokogiri built against the system's
libxml2, a gem whose build script downloads its binary), or a JRuby patch
that changes Java sources. #2136 reported those with exit 0 and a warning.
They are now a failure of the run, on the first run and on every later one:
applyError:line on stderr (also under--silent): the patch of<purl>is incomplete, its files were written, and which sources are not in the compiled code and why. The package is not listed under patched packages; the summary counts it as "not in effect".apply --jsonstatus: partialFailure, afailedevent witherrorCodenative_extension_not_rebuiltand the files this run wrote, and the same code inwarnings[].apply --dry-runget,scan --mode agentNothing on disk changes with this: the files stay written (a gem that
builds its patched binary on first start relies on its Ruby half), no build
marker is written,
apply --checkis out of sync,vexdoes not attest,and
rollbackrestores the tree byte for byte. A re-run of a patch whosefiles are already written ends the same way, never
already_patched, sonothing that counts patches in place can count it.
Exit 0 as before: a patch with nothing left to do (
already_patched,not_in_platform_build), and--no-gem-native-rebuild, where the callercompiles. On JRuby that flag now writes the files and exits 0 with a warning
that names it, unless the gem ships none of the record's files.
What a reviewer should weigh
JRuby with at most a dead C source changed. When no copy takes any file
of the record, the VEX statement says so: justification
vulnerable_code_not_present, and an impact statement that the code isnot in the installed build, in place of "Patched via". The reasoning: the patch is
the upstream fix, and the upstream-fixed java gem differs from the old one
by exactly the files applied here; the libxml2 the patch fixes is not in
the JRuby build. It is also what hosted mode reports with the backend's
javagem. Nothing here proves the Java implementation has no equivalentbug. Withholding instead is a small change if you prefer it.
javagem in one case. Aruby-platform record that replaces a non-C file the
javagem nevershipped fails here as a missing file, where the backend's repack skips it.
The alternative waved a deleted Ruby file through as "not applicable" and
attested it.
backend tells it, so a
pom.xmltemplate blocks attestation. That errs onthe side of not attesting.
whole nokogiri workflow, because the old pin knows no JRuby past 10.0.4.
The JRuby legs also get an
actions/setup-javastep for Java 21. Thatworkflow is not required for merge.
JRuby copy has no cached archive to judge it by, the hosted stale-install
guard still reads the full record. A follow-up routes it through the same
reader.
Code review
Bugbot's finding on this PR (
scan --mode agentcounted a patch whose jarscould not be rebuilt as in place) is fixed by the change above: an
incomplete patch is a
failedevent on every run./code-review highran a second time, on the exit-code change, and raisedten more; six were reproduced with the built binary. Fixed: a missing Ruby
file read as "not applicable" and was attested; a record carrying a
replacement jar and its source was incomplete forever;
applyandvexdisagreed when the manifest held both a ruby-platform and a java-platform
record; an incomplete copy still counted as applied in the run's state and
tally;
rollbackand a dry run with--no-gem-native-rebuildprinteduntrue messages; the VEX statement of a copy the patch changes nothing in
said "Patched". Kept as the owner decided: attesting a C-only record on
JRuby, and exit 1 on every run of an incomplete patch. The cost of the
second is real: an install whose nokogiri is built against system libraries
rebuilds the extension and fails on every
applyorscan --mode agentwhile a libxml2 patch is recorded, until the record is removed or
--no-gem-native-rebuildis passed.The first
/code-review highraised ten findings. Fixed: ajavagem that declaresextensions lost its rebuild and was attested; a replacement jar counted as
unbuildable; the lenient rule applied to platform-qualified records;
scancoverage not counting the nothing-applies outcome as patched; one summary
phrase for two different outcomes; an outcome carried by parsing an error
string (now a typed field); the gemspec parsed twice per record in the
verifier; and three leftovers. Kept, with comments in the code: attesting a
copy the record changes nothing in, and JVM build inputs told by leaf name
(both above).
Testing
tests/nokogiri/nokogiri_e2e.rb(a Ruby record, a C record, a libxml2record), in a Linux container built from the new
tests/docker/Dockerfile.jruby:C source, is attested, and JRuby loads the same jars as before; the
libxml2 record writes nothing, exits 0, is in sync and attested. Each
ends in a rollback to a byte-identical tree.
jruby-9.4andjruby-10.1.leaves-no-compiled-file and
.javatests expect exit 1, thefailedevent, the files still written and a clean rollback, and re-apply to see
the second run fail the same way. A new test runs
scanandgetover anincomplete patch (it fails, and the patch stays recorded). Real nokogiri
built with
--use-system-librarieson macOS: 43 checks pass, the libxml2record being the incomplete case.
e2e_gem_native_ext_build, 52 pass): Ruby plus a shipped Cfile; files the copy has no use for; a C-build-only record; a
.javarecord (written, warned, not attested); a replacement jar; a
platform-qualified record applied whole; a
javagem that declaresextensions; a mismatching shipped file. Each asserts no Ruby ran and, but
for the mismatch, rolls back to a byte-identical tree.
gem_197 andvex::888; the CLI library (969); the layering test;e2e_redirect_gem_build49 ande2e_vendor_gem_build18;cargo fmt --checkand CI's clippy command clean, on the branch merged withmain.JDK 25); Windows.
The nokogiri script and workflow are also changed by #2150 and #2154; the
last of the three to land needs a rebase.
🤖 Generated with Claude Code