Skip to content

Remove hosted and vendored mode for gems locked as platform gems - #2226

Draft
Mikola Lysenko (mikolalysenko) wants to merge 2 commits into
mainfrom
fix/remove-gem-prebuild-path
Draft

Mikola Lysenko (mikolalysenko) wants to merge 2 commits into
mainfrom
fix/remove-gem-prebuild-path

Conversation

@mikolalysenko

@mikolalysenko Mikola Lysenko (mikolalysenko) commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

Removes hosted and vendored support for a gem that Gemfile.lock pins as precompiled platform gems (nokogiri (1.18.10-x86_64-linux-gnu)). That support was merged in #2150 and #2154 after 5.1.0 and has not been released. Agent mode is not touched.

Why

Both modes read per-platform "prebuilds" that the patch service attached to a gem's ruby-platform patch: gemPlatforms in the grant, and the gem-platform and gem-platform-stub-gemspec artifacts. Socket's backend is dropping those. A platform gem is going to be published as a patch of its own instead, one per platform, and the CLI will be taught that shape separately. Until then nothing serves what this code reads, so it could never run, and it should not ship in a release as if it did.

What a platform-locked gem does after this (as in 5.1.0)

Mode Outcome
Hosted Skipped with the warning redirect_gem_platform_unsupported, exit 0, no file changed. The scan's closing totals count the gem as left to patch.
Vendored With the platform copy installed: platform_gem_unsupported, exit 1; the detail names agent mode, which patches a precompiled gem where it is installed. With nothing installed (a fresh checkout), the gem is not seen and nothing is reported. With a ruby-platform entry beside the platform ones, the lock edit fails and nothing is written.
Agent Unchanged.

One thing is better than 5.1.0 and is kept: a hosted run reads a gem that the lock names only as platform builds from the lock alone, so the skip is reported on a fresh checkout too. 5.1.0 found such a gem only through an installed copy and said nothing otherwise.

What is removed

Net +1,596 / −9,512 lines in 58 files. The added lines are mostly the pre-feature code coming back where the feature had rewritten it, plus the tests below.

  • Hosted: gemPlatforms in the registry override and its grant checks; the rewrite of platform entries and their CHECKSUMS lines, and the restore that put them back; lockfile discovery of platform specs under a Socket GEM section; the stale-install guard and the unwind refresh for installed platform builds.
  • Vendored: the one-tree-per-platform layout (<name>-<version>/<platform>/) with its lock edit, its checks in vendor --check, vex and repair, the restore of a damaged copy and ledger recovery; the platform of a served artifact; the codes vendor_prebuilt_platform_pending and vendor_gem_gitignore_neutralized, which nothing else raised.
  • Tests and CI: the hosted and vendored legs of the nokogiri workflow, their scenarios in tests/nokogiri/nokogiri_e2e.rb, the stand-in patch service, and the real-Bundler capstones for platform locks.
  • Docs: CLI_CONTRACT.md and docs/ecosystems.md describe the skip and the refusal as they are now. platform_gem_unsupported gets a contract row of its own.

Follow-ups to the two PRs:

A project that a development build already wired

  • Vendored: can still be undone. The ledger's gemPlatforms field is ignored on read, and the revert still reads the array-form CHECKSUMS record, so rollback puts the Gemfile and the lock back byte for byte and removes the copies. A re-scan fails with vendor_stale_lock_checksum, which names vendor --revert.
  • Hosted: is not unwound. No command changes the pair: a hosted scan rewrites nothing for the gem, and rollback and remove stop with hosted_wiring_contested (or hosted_restore_refused when the lock has the ruby-platform entry beside the platform ones). Both name the lock lines and version control as the way back.
  • A reference response that still carries the retired fields parses as the grant of the ruby-platform gem.

Each of these is held by a test.

Testing

  • cargo fmt --all -- --check and cargo clippy --locked --workspace --all-features -- -D warnings: clean.
  • cargo test --locked -p socket-patch-core --lib --no-fail-fast: 8,380 passed, 0 failed. Core redirect_golden and upstream_restore_golden: 1 + 62 passed.
  • cargo test --locked -p socket-patch-cli --no-fail-fast, all 218 binaries: 5,714 passed, 3 failed, 486 ignored.
    • One failure was a new test of this branch with a wrong premise. It was fixed, and e2e_redirect_gem_stale_install (62) and hosted_memory_parity (46) pass; the full suite was not repeated after that fix.
    • Two failures are in e2e_vendor_cargo_build, which this branch does not touch: Bad CPU type in executable, an x86_64 toolchain on an arm64 Mac.
  • Real Bundler (Ruby 3.4.10, Bundler 4.0.15): e2e_redirect_gem_build and e2e_vendor_gem_build with --ignored: 49 + 12 passed, one version-gated skip.
  • A new golden fixture, redirect/gem/bundler/platform-locked, holds the hosted skip; the disk and in-memory engines are compared on it.

Not run: the docker-e2e suites, the remaining nokogiri workflow legs, JRuby and Windows. CI covers them. vendor --revert and scan --prune on a development build's vendored state take the same revert path as rollback but were not run.

Review findings, not fixed yet

This PR is a draft. /code-review high found no blocking correctness bug and no dangling reference, and reported the items below. Each is to be fixed, or answered here, before the PR is marked ready.

  1. The stale-install guard takes the first installed copy of a version again, not the build the lock names. With a lock that has only foo (1.0) and a gem home that holds only foo-1.0-x86_64-linux, the scan would call the gem stale and try to refresh a file the registry does not serve. The guard should look for the ruby-platform leaf alone.
  2. Vendored mode gives three outcomes for one lock (the table above). A fresh checkout says nothing, and the lock-edit failure's remedy ("re-resolve it before vendoring") cannot work on a lock Bundler itself wrote and does not name agent mode.
  3. docs/ecosystems.md, the native-extensions table: the Vendored row says "Use hosted or agent mode" although hosted skips a precompiled gem too, and it does not name platform_gem_unsupported.
  4. A stale vendor/cache archive can be reported twice when two record purls of one gem share an installed copy, because the covered set is keyed by purl again and not by archive path.
  5. The array-form CHECKSUMS record is still read so that a development build's vendored state can be undone, while the hosted state of the same builds is refused. Either both get a way back or neither needs the second record grammar.
  6. The unwind refresh reads the lock and builds an HTTP client once per restored gem.
  7. The restored platform check parses the lock three times and compiles a regex per gem.

🤖 Generated with Claude Code

Vendored mode could vendor a gem that Gemfile.lock pins as precompiled
platform gems (`nokogiri (1.18.10-x86_64-linux-gnu)`). It did so from
artifacts the patch service attached to the gem's ruby-platform patch:
one patched platform gem and one stub gemspec per platform
(`gem-platform`, `gem-platform-stub-gemspec`, each naming its
`platform`). The patch service is dropping those artifacts, so the code
that reads them goes. The support was merged after 5.1.0 and never
released.

Removed:

- the vendored layout of one tree per platform
  (`<name>-<version>/<platform>/`): its lock edit, the checks of the
  trees in `vendor --check`, `vex` and `repair`, the restore of a damaged
  copy, ledger recovery, and the `gemPlatforms` field of a ledger entry;
- the `platform` of a served artifact, and the request that listed a
  patch's artifacts without downloading its archive;
- the codes `vendor_prebuilt_platform_pending` and
  `vendor_gem_gitignore_neutralized`, which nothing else raised;
- lockfile discovery of platform specs in a vendored `PATH` section;
- what followed a vendored unwind for such a gem only: the refresh of
  installed platform builds and the cache-dir check of each platform
  build's archive;
- the vendored legs of the nokogiri workflow, the vendored scenario of
  its script, and the real-Bundler capstone.

A gem that is installed as a platform gem is refused with
`platform_gem_unsupported` again, as in 5.1.0. The detail names agent
mode, which patches a precompiled gem where it is installed.

A project that a development build wired this way can still be undone.
Reading its ledger does not fail: the `gemPlatforms` field is unknown
now and ignored. The revert of a gem entry still reads the `CHECKSUMS`
record that build wrote, an array of lines on each side, and pairs each
line with the original of the same entry. So `rollback`,
`vendor --revert` and `scan --prune` put the Gemfile and the lock back
byte for byte and remove the copies. Nothing writes the array form any
more.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Hosted mode could redirect a gem that Gemfile.lock pins as precompiled
platform gems. It moved every platform entry of the gem to the patch
registry and pinned each to a patched platform gem that the patch
service listed in the grant (`gemPlatforms`, one `{platform,
gemChecksumSha256}` per platform). The patch service is dropping that
list, so the code that reads it goes. The support was merged after 5.1.0
and never released.

Removed:

- `gemPlatforms` in the registry override's identifiers, and its checks
  in the grant;
- the rewrite of platform entries and their `CHECKSUMS` lines, and the
  restore that put them back on the upstream registry;
- lockfile discovery of platform specs under a Socket `GEM` section as
  one hosted pin;
- the stale-install guard and the unwind's refresh for installed
  platform builds, with the reader of the builds a lock names that they
  shared;
- the hosted legs of the nokogiri workflow, the hosted scenario of its
  script with the stand-in patch service, and the real-Bundler capstones.

A gem whose lock holds platform builds of the patched version is skipped
with `redirect_gem_platform_unsupported` again, in the words of 5.1.0:
"<lock> locks platform-specific builds of <name> <version> (`<name>
(<version>-<platform>)`) — the patch registry serves only the ruby
platform gem; redirect skipped". Neither file changes for it.

Kept, because it is not about the removed artifacts:

- A hosted run still reads a gem that the lock names only as platform
  builds from the lock alone, so the skip is reported on a fresh
  checkout too, by the scan, by `get --mode hosted` and by the in-memory
  engine. 5.1.0 found such a gem only through an installed copy.
- The closing totals of a scan still count a refused platform-only gem
  as left to patch, in hosted and in vendored mode.
- Rollback's reinstall note for vendored gems, which is now computed for
  the ruby-platform gem alone, as vendored gems are.
- The check of a rules_ruby hub's `gem_checksums` is handed the one
  build the redirect pins.

The golden fixture `gem/bundler/platform-locked` holds the skip, and the
disk and in-memory engines are compared on it.

A pair that a development build redirected this way is not unwound. No
command changes it: a hosted scan rewrites nothing for the gem, and
`rollback` and `remove` stop with `hosted_wiring_contested` (or
`hosted_restore_refused` when the lock has the ruby-platform entry
beside the platform ones), which name the lock lines and version control
as the way back. Tests hold both that and the vendored undo.

A reference response that still carries the retired fields (`platform`
on an artifact, the `gem-platform` artifact kinds, `gemPlatforms`) is
read as the grant of the ruby-platform gem: none of them is parsed, so
none can fail the response.

The CLI contract and the ecosystems guide describe the skip and the
vendored refusal as they are now, and `platform_gem_unsupported` has a
row of its own in the contract.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant