Skip to content

Fix vex attesting nothing after a hosted move of a platform-locked gem - #2497

Open
Mikola Lysenko (mikolalysenko) wants to merge 3 commits into
mainfrom
fix/hosted-gem-vex-platform-reference
Open

Mikola Lysenko (mikolalysenko) wants to merge 3 commits into
mainfrom
fix/hosted-gem-vex-platform-reference

Conversation

@mikolalysenko

@mikolalysenko Mikola Lysenko (mikolalysenko) commented Dec 4, 2026 •

Copy link
Copy Markdown
Collaborator

What was wrong

After a hosted move of a gem that Bundler locks as platform builds (nokogiri (1.18.9-x86_64-linux-gnu)), a standalone socket-patch vex attested nothing: it warned no granted patch matches 1.18.9-x86_64-linux-gnu, omitted the gem as record_unavailable, wrote no statement and exited 1. The move itself, the frozen install and the run's own --vex were fine. This is released 5.2.0 against the production patch service.

There were three causes.

  1. The lookup read the wrong purl. vex finds the patch of each locked build by the purl its package reference states. The patch service states the gem alone there (pkg:gem/nokogiri@1.18.9) for every gem patch, a platform gem's included, so no patch was ever "for" a locked platform. The lookup now takes a patch's platform from the patch search, which lists each patch under its own purl. The reference's purl places only a patch the search does not list.
  2. Events lost the platform. For the same reason a hosted scan / get reported a platform build's applied event under the gem's bare purl. The candidate now keeps the selection's platform when its reference names none.
  3. Every build was checked against every installed copy. The patches of one fix have bytes of their own per build. On a lock that names more than one build (nokogiri (1.18.9) beside nokogiri (1.18.9-x86_64-linux-gnu)), the one installed copy failed the check of every build but its own (hash_mismatch, partialFailure). A hosted gem build is now judged by the copies of its own build, which is what the record check already did. A build this machine does not install is attested from the lock's pin, but not while an installed build of the same gem fails its own patch's check.

The test fixtures hid all three: they served references with qualified purls and one set of bytes for every build of a fix.

Tests

  • Unit tests for the lookup (both reference shapes, a patch the search does not list, a reference that contradicts the search), the candidate purl, the per-build copies and the sibling guard, and an installed copy whose own patch record is unavailable.
  • The real-Bundler capstones (e2e_redirect_gem_build, --ignored) now serve references in three shapes and a patch per build with its own bytes. They also tamper with the installed build and check that vex then attests no build of the gem. Seven arms pass on Ruby 3.4.10 / Bundler 4.0.15. Each fix was removed in turn to confirm an arm fails without it.
  • socket-patch-core lib (9,025 tests), socket-patch-cli lib, and the vex and gem integration targets pass. cargo fmt and CI's clippy command are clean.

Checked against production

A Linux build of this branch, run in ruby:3.3 containers against the production patch service, with nokogiri 1.18.9. Each run is: hosted move, BUNDLE_FROZEN=true bundle install, vex, rollback. All steps exit 0.

Lock Moved by vex
x86_64-linux-gnu only, with CHECKSUMS get <uuid> --mode hosted 1 verified
x86_64-linux-gnu only, with CHECKSUMS scan --mode hosted 1 verified
ruby + x86_64-linux-gnu, with CHECKSUMS scan --mode hosted 2 verified, one statement naming both patches
x86_64-linux-gnu only, no CHECKSUMS (Bundler 2.5.22) scan --mode hosted 1 verified

Not changed here

  • Released 5.2.0 stays broken on these locks until the package reference of a platform gem's patch states that gem's own purl. That needs a matching change in Socket's backend. It would fix 5.2.0 for a lock that names one build; a lock naming several needs cause 3, which is only in this PR.
  • The ruby build's event purl stays bare (pkg:gem/nokogiri@1.18.9) when its reference names the gem alone, while VEX names it ?platform=ruby. That is what 5.2.0 does and what every plain gem's event looks like, so I left it. The capstones pin it. (Review finding 1.)

Review

/code-review high found no blocking bug and six minor points. Five are fixed in the second commit: a reference that contradicts the search no longer matches, an unlisted platform patch with a bare reference is no longer read as the ruby gem's, a reference that says ?platform=ruby is reported as stated, one test fixture served views that did not match its gems, and stale module docs. The sixth is the event purl above.

🤖 Generated with Claude Code


Generated by Claude Code

A hosted move of a gem Bundler locks as platform builds was followed by a
standalone `vex` that attested nothing: the document was empty and the
command exited 1. Three causes, each fixed here.

The patch of a locked build was looked up by the purl its package
reference states. The patch service states the gem alone there
(`pkg:gem/nokogiri@1.18.9`), without the `platform` qualifier, for every
gem patch, so no patch matched a locked platform build. The lookup now
takes a patch's platform from the patch search, which lists each patch
under its own purl, and reads the reference's purl only for a patch the
search does not list.

For the same reason a hosted `scan` / `get` reported a platform build's
event under the gem's bare purl. The event keeps the build's own purl
when the reference names the gem alone.

Each hosted build's record was checked against every installed copy of
the gem version. The patches of one fix have bytes of their own per
build, so on a lock naming more than one build (`nokogiri (1.18.9)`
beside `nokogiri (1.18.9-x86_64-linux-gnu)`) the installed copy failed
the check of every build but its own. A hosted gem build is now judged by
the copies of its own build, as the record check already did. A build
this machine does not install is attested from the lock's pin, but not
while an installed build of the same gem fails its own patch's check.

The capstone fixtures now serve references in both shapes, and a patch
per build with its own bytes. One new arm names the ruby gem's patch
`?platform=ruby` in the search, its view and its reference.

Released 5.2.0 keeps failing on such a lock until the reference states
the build's own purl, which needs a matching change in Socket's backend.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…shapes

Review follow-ups to the hosted platform-gem `vex` fix.

A patch the search lists is still held to its reference: one that names
another gem, or carries the `platform` of another build, matches no
locked build. The two spellings of the glibc Linux platform are one. A
platform gem's patch the search does not list, whose reference names the
gem alone, is no longer read as the ruby gem's patch: nothing states its
platform, so it matches no build.

A hosted candidate takes the selection's platform only where its
reference names none. A reference that says `?platform=ruby` is reported
as it states.

The capstone fixture for bare references now lists the ruby gem's patch
under `?platform=ruby` in the search and its view, as the patch service
does, and the lock-gaining test serves views that match the gems it
builds. The docs of the hosted copy lookup say a gem build's purl gets
the copies of its own build.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@cursor

cursor Bot commented Dec 4, 2026 •

Copy link
Copy Markdown

PR Summary

Medium Risk
Changes verification and attestation logic for hosted multi-platform gems; incorrect matching could omit or mis-attest patches, but scope is limited to gem hosted/vex paths with substantial new unit and e2e coverage.

Overview
Fixes standalone socket-patch vex (and related hosted reporting) for gems locked as multiple platform builds after a hosted redirect, when the patch service references use a gem-only purl without ?platform=.

Patch ↔ lock matching now uses the patch search listing (qualified purl per build) to pair each locked platform with its granted patch; reference purls still disambiguate only when a patch is not in search, with guards for contradictory or bare platform-gem references.

Hosted redirect candidates keep the selection’s platform-qualified purl when the grant names the gem alone, so applied events align with the build being pinned.

VEX consumption judges each gem build against only that build’s installed copies (not every copy of the gem version), and withholds lockfile-basis excuses for sibling builds while any installed build of the same gem fails verification—so one wrong on-disk platform build does not falsely attest other builds.

Docs and e2e capstones are updated to describe per-build attestation, distinct patched bytes per platform, and multiple reference-purl shapes.

Reviewed by Cursor Bugbot for commit 01dd5ee. Configure here.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

❌ 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 01dd5ee. Configure here.

`locked_build_patch` already treats `x86_64-linux` and `x86_64-linux-gnu`
(and case) as one platform when deciding whether a reference contradicts
the search, but the lock match itself compared exactly. A patch stated
as `x86_64-linux` then matched no `x86_64-linux-gnu` build, and
standalone `vex` attested nothing for it. Fold the platform there too;
the registry digest still pins the build's exact bytes.

Found by Cursor Bugbot.

Assisted-by: Claude Code:claude-opus-5-5
@mikolalysenko

Copy link
Copy Markdown
Collaborator Author

[agent] PR shepherd: final review brief for the approver.

What it does. After a hosted move of a gem that Bundler locks as platform builds (such as nokogiri x86_64-linux-gnu), a standalone socket-patch vex now attests each locked build by its own patch. Before this change it attested nothing and exited 1, because the patch service's references name the gem without its platform. It now takes each patch's platform from the patch search and checks an installed copy only against its own build's patch. Hosted scan/get events also keep the build's ?platform= qualifier.

Risk: low–medium.

  • Only hosted gems locked as platform builds are affected, and every match is still pinned by the registry sha256.
  • The vex changes can only narrow or tighten what gets attested.
  • The medium part: it changes how patches are matched against the live patch service's data. A lock that names several builds is covered only by fixtures and by the PR's production table.

Look here

  • gem_fixes.rs:631-686: locked_build_patch, which matches a build to its patch by the search's platform and treats a reference that contradicts the search as no match.
  • gem_fixes.rs:610-617: same_platform (glibc spelling and case folding).
  • engine.rs:448-460: the candidate purl keeps the selection's platform.
  • vex.rs:1793-1808: each hosted gem build is checked only against copies of its own build.
  • vex.rs:1820-1826: the lock pin can't attest a build while another installed build of the same gem fails its own patch's check.

Verified

  • cargo test -p socket-patch-core --lib hosted: 545 passed.
  • cargo test -p socket-patch-cli --lib vex: 58 passed.
  • Real-Bundler capstones e2e_redirect_gem_build --ignored gem_hosted_platform_prebuilds (Ruby 3.3.6 / Bundler 4.0.18): all 4 arms passed.
  • I removed the per-build narrowing and the search lookup one at a time, and a capstone arm fails each time. Without the search lookup it fails with record_unavailable, the symptom reported in production.
  • CI is green on this head: ci-ok and clippy pass. The earlier Bugbot thread was fixed in 3687794 and is resolved.
  • CHANGELOG.md is untouched.

Changes I made. None in this review. The glibc-spelling fix (3687794) came from an earlier shepherd run.

Open questions. None blocking. The PR notes that released 5.2.0 also needs a matching change in Socket's backend, so that a platform gem's package reference states its own purl.


Generated by Claude Code

@mikolalysenko Mikola Lysenko (mikolalysenko) added the Ready for review Agent-verified: mergeable, CI green, Bugbot clean — awaiting human review label Dec 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Ready for review Agent-verified: mergeable, CI green, Bugbot clean — awaiting human review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants