Repository navigation
Fix patch update refused for qualified gem records (#2376) - #2392
Mikola Lysenko (mikolalysenko) wants to merge 4 commits into
Conversation
Refs #2376. 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_011f9aeRLXgywqBzkw2e1bPs
A gem copy that holds an earlier Socket patch's output must take a newer patch from a record that names its platform. Four cases fail today with no_matching_variant; four guards (another platform's copy, no gemspec, a local edit, --strict) pass and must keep passing. Refs #2376. 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_011f9aeRLXgywqBzkw2e1bPs
A manifest record that names its platform (pkg:gem/x@1?platform=ruby) is applied to a copy only when the copy's representative file holds the record's original or patched content. A copy that holds an earlier Socket patch for the same release holds neither, so every update to a newer patch failed with "no matching variant found" before the mismatch policy, which overwrites Socket content, was consulted. The gate now also admits a gem copy whose file is a stored blob when the copy's gemspec gives it to the record: a copy of the platform the record names, or, for the ruby record, a platform gem's copy that no record of the version names. The gemspec says which distribution the copy is whatever its files hold, so a record is still never written over a copy of another platform, a copy with no gemspec, or a local edit, and --strict still refuses. Fixes #2376. 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_011f9aeRLXgywqBzkw2e1bPs
Review of the first cut found two ways it could write a record over bytes it was not made for: - The ruby-platform record was admitted on a platform gem's copy that no record names. The gemspec does not say such a copy is that record's distribution (it is matched to it by files alone), and a stored blob may be another record's original content, so a pristine platform copy could be overwritten. That fallback is gone: a record is admitted only on a copy whose gemspec names its platform. - A platform copy patched by the ruby-platform record had its own platform's record forced over that patch. A blob that is one side of another record of the version is a state the manifest describes, not an earlier patch, and no longer admits a record. The contract note says which gated records the rule covers. Refs #2376. 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_011f9aeRLXgywqBzkw2e1bPs
|
bugbot run Generated by Claude Code |
PR SummaryMedium Risk Overview The installed-distribution gate now also accepts a gem copy when its gemspec names the record's platform, the representative file's content is a stored
Reviewed by Cursor Bugbot for commit 0cad491. Configure here. |
|
[agent] PR shepherd: review brief for the approver What it does Risk: medium. It widens a safety gate that decides which files Look here
Verified
Changes I made: none. Open questions
Generated by Claude Code |
LLM Description written by Claude Code:claude-fable-5-2
Refs #2376
Summary
In agent mode, moving a gem to a newer patch of the same gem version failed
for every record that names its platform (
pkg:gem/rack@3.2.9?platform=ruby):apply, and the apply insidescan --mode agent/get, refused the gemwith
no matching variant foundand exited 1, although the installed fileheld an earlier Socket patch whose blob was still in
.socket/blobs/.With this change the newer patch is written over the earlier one, with the
content_mismatch_overwrittenwarning, as it already was for an unqualifiedrecord. It applies to a gem copy whose gemspec names the platform the record
was written for: a ruby-platform copy under the
rubyrecord, and a platformgem's copy under its own platform's record.
Root cause
A record that names its platform is applied to a copy only after an
installed-distribution gate: the record's representative file must hold its
original or patched content. A file holding an earlier patch's output holds
neither, so the record was skipped before the engine's mismatch policy (which
overwrites content a Socket patch wrote) was ever consulted.
The gate exists because the file hash was the only thing telling a record's
distribution from another one (a lone
x86_64-linuxrecord must never bewritten over an
arm64-darwincopy). But the copy's gemspec states itsplatform whatever its files hold. So the gate now also admits a copy when all
of this holds:
gem version in the manifest;
--strict.The engine then handles the files as it does for an unqualified record: every
file is verified first, and nothing is written unless each one is original,
patched, or Socket content.
What stays refused (each has a test)
--strict.rubyrecord's current patch: its ownplatform's record is not written over it.
Not fixed here (why this is
Refs, notFixes)The
rubyrecord on a platform gem's copy (a precompiled nokogiri under a?platform=rubyrecord, with no record for its platform). The first cut ofthis PR admitted it; the review showed it can overwrite a pristine platform
copy whose bytes the record was never made for, because a stored blob may be
another record's original content and the gemspec does not say the copy is
the ruby record's distribution. That branch was removed, so this case still
fails closed with
no matching variant found, as onmain. A safe fix needsreal proof of the copy's pristine bytes, for example the copy's own archive in
the gem home's
cache/.Other things the review raised that this PR leaves alone:
apply --check,vex,rollbackand the download filter ofget/scanselect records through the core selection, which still does not match a copy
holding an earlier patch. Before the update is applied,
apply --checkreports such a copy as
no_matching_variant, andgetkeeps every variantof the release. Both were so before; after
applyruns the copy matches.?artifact_id=) and Maven records are gated the same way and probablyfail the same update. Not measured, and they need their own distribution
proof.
that was patched through the
rubyrecord of an earlier patch: on updateits own platform's record is now admitted (the earlier blob is no longer in
the manifest, so nothing tells which record wrote it). The engine still
verifies every file before writing. On
mainthis case exits 1.Evidence
The issue's script (real Bundler 4.0.18, Ruby 3.3.6,
rack 3.2.9,pkg:gem/rack@3.2.9?platform=ruby):main1b3f422no matching variant found, exit 1# patch A1 of 1 targeted patch applied, warning, exit 0# patch BAfter it,
apply --checksaysPatches are in syncandrollbackrestoresthe published file.
Tests (
crates/socket-patch-cli/tests/apply/gem_patch_update_qualified.rs,real binary, offline). The first commit adds them against
main: the threeupdate cases failed with
no_matching_variant, the guards passed.applyand the re-scan fail with "no matching variant found" for a?platform=rubyrecord, and CI with a cachedvendor/bundleexits 1 #2376:ruby_record_replaces_earlier_patch,own_platform_record_replaces_earlier_patch,sibling_platform_record_is_not_written_over_earlier_patch.other_platform_copy_holding_a_stored_blob_stays_refused,ruby_record_on_platform_copy_holding_a_stored_blob_stays_refused,copy_without_gemspec_holding_a_stored_blob_stays_refused,local_edit_stays_refused,strict_refuses_the_update,own_platform_record_is_not_written_over_a_sibling_records_patch(failswhen rule 3 is removed).
copy_is_of_the_platform_its_gemspec_namesin coregem_ext.Local runs, all passing:
cargo clippy ... --all-targetsreports 71 errors in test code onmainwithout this change (CI's clippy job does not pass
--all-targets); none arein the lines this PR touches.
CLI_CONTRACT.mdgains the rule beside the existing "content a Socket patchwrote" paragraph. The
npm/,pypi/andgem/wrappers call the binary andneed no change.
https://claude.ai/code/session_011f9aeRLXgywqBzkw2e1bPs
Generated by Claude Code