Skip to content

Agent apply fails in CI on a manifest written on another platform build of a gem whose patch brings binaries (a Mac-written manifest on Linux: "nokogiri.bundle - File not found"), and no message names scan --all-releases #2520

Backlog

Description

[agent] Found by the scheduled Bundler (RubyGems) bug-hunt routine (ledger #316).

Summary

In agent mode, a manifest written on one platform build of a precompiled gem cannot be applied on a machine that installs another build, once the platform gem's patch record brings its compiled libraries (the shape #2499 describes for nokogiri: the changed C sources plus one binary per Ruby). The usual case is a developer on macOS who runs socket-patch scan, commits .socket/ and adds socket-patch apply to CI as the scan's "Next steps" say. On the Linux runner apply exits 1:

Error: Failed to patch pkg:gem/nokogiri@1.18.10?platform=arm64-darwin: Cannot apply patch: lib/nokogiri/3.1/nokogiri.bundle - File not found
Summary: 2 of 3 targeted patches applied, 0 already patched, 1 failed, 0 not found on disk

Nothing in the output says that the record is for another build of the gem, or what to do. apply --check says "patch not applied (an installed copy is still unpatched). Run socket-patch apply to regenerate them", and that is the command that just failed. With a glibc / musl pair the message is lib/nokogiri/3.1/nokogiri.so - File hash does not match expected value.

The installed gem is left untouched, so nothing is damaged. The harm is a red CI job after the user followed the printed steps, and a patch that is silently missing where the job is allowed to fail.

A Ruby-only record of another build is still applied by content, as the docs describe, so this shows up only for records that carry binaries.

Impact

  • Any team whose developers and CI are on different platforms (macOS laptops and Linux CI, glibc CI and an Alpine image) and that patches a precompiled gem in agent mode. A default Bundler 4 lock names every platform, so the project itself is set up for this.
  • Two things do work, and neither is named anywhere in the output: socket-patch scan --all-releases on the developer's machine (the manifest then holds a record per build, and apply on Linux reports the darwin record as "not installed, skipped"), or socket-patch scan instead of apply in CI.

Repro

Patch data comes from the repo's stand-in (tests/nokogiri/patch_service.rb), with patched_data overridden so that a platform gem's patch also changes ext/nokogiri/gumbo.c and every lib/nokogiri/<abi>/nokogiri.{so,bundle}, and the patch view carrying blobContent / beforeBlobContent. It serves nokogiri 1.18.10 for ruby, arm64-darwin and x86_64-linux-gnu. $M is its URL.

# Project (Ruby 3.3.6, Bundler 4.1.1)
cat > Gemfile <<'G'
source "https://rubygems.org"
gem "nokogiri", "1.18.10"
G
bundle config set --local path vendor/bundle
bundle install            # the lock names 8 platforms and ruby

# "The Mac": the same project, with the upstream arm64-darwin gem in the gem home in place of the glibc one
#   gems/nokogiri-1.18.10-arm64-darwin/ (gem unpack), specifications/nokogiri-1.18.10-arm64-darwin.gemspec (gem spec --ruby)
socket-patch scan --mode agent --yes --api-url $M --patch-server-url $M --api-token fake --org nokogiri-e2e
#   Applied 1 patch. Next steps: 1. Commit .socket/  2. Run `socket-patch apply` after every `bundle install`, locally and in CI.
#   .socket/manifest.json holds pkg:gem/nokogiri@1.18.10?platform=arm64-darwin

# "Linux CI": a fresh checkout with that .socket/, then
bundle install
socket-patch apply --api-url $M --patch-server-url $M --api-token fake --org nokogiri-e2e    # exit 1, message above
socket-patch apply --check ...                                                                # exit 1, "Run `socket-patch apply`"

apply --json: status: partialFailure, one failed event, errorCode: apply_failed, error: "Cannot apply patch: lib/nokogiri/3.1/nokogiri.bundle - File not found".

Expected

CLI_CONTRACT.md says scan --all-releases "makes the stored manifest portable across environments", so a manifest written without it is allowed to miss this machine's build. But the contract also says how that is reported: a record of another distribution is skipped calmly when its files are not the installed ones (variant_matches_installed: "Skipping it avoids attempting, and spuriously reporting a Failed event for, a variant that was never installed"), and an installed copy that matches no record is no_matching_variant. For a gem, the record's key states its platform and the installed copy states its own, so the run can tell that the record is for another build without opening a file. I would expect:

  • apply to say that the manifest holds the patch of the arm64-darwin build only and this machine installs x86_64-linux-gnu, and to name the remedy (socket-patch scan --all-releases where the manifest is written, or socket-patch scan here);
  • apply --check not to suggest apply for it;
  • the agent scan on a lock that names several platforms to mention --all-releases next to "Run socket-patch apply ... in CI".

Actual

The record of the other build is taken for a match (the files the two builds share, lib/nokogiri.rb and ext/nokogiri/gumbo.c, hold the expected content), applied to the copy, and fails on the first binary: "File not found" for a darwin record on Linux, "File hash does not match expected value" for a musl record on glibc.

Versions

Version Result
main cd7c5c5, Ruby 3.3.6, Bundler 4.1.1, darwin record on a glibc tree fails (twice)
main cd7c5c5, musl record on a glibc tree fails ("File hash does not match expected value")
5.2.0, both fails the same way: not a regression
main, manifest written with scan --all-releases passes: the glibc record is applied, the others are "not installed, skipped", apply --check exits 0
main, Ruby-only platform record of another build (ledger, 12-04) passes: applied by content

Linux only. A real macOS or Windows machine was not tested; the path is platform-neutral, so the reverse direction (a Linux-written manifest on a Mac) should fail the same way.

Suspect code

crates/socket-patch-cli/src/commands/apply.rs:1272 (variant_is_installed): a variant is matched to the copy by one representative file, which both builds share. For gem records the platform qualifier of the key and the platform of the copy (own_platform_variant, apply.rs:1223) could rule the record out first. The apply --check remedy text is at apply.rs:1044.


Generated by Claude Code

Activity

  1. added
    bug
    bughunt
    pm:bundler
    ux
    on Dec 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent:triagedbugbughuntpm:bundlerpriority:p1ux

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions