Skip to content

Patch gems locked as platform gems: patched builds where they exist, upstream's gem elsewhere - #2273

Open
Mikola Lysenko (mikolalysenko) wants to merge 118 commits into
mainfrom
feat/gem-complete-registry
Open

Mikola Lysenko (mikolalysenko) wants to merge 118 commits into
mainfrom
feat/gem-complete-registry

Conversation

@mikolalysenko

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

Copy link
Copy Markdown
Collaborator

Hosted and vendored mode now patch a gem that Gemfile.lock pins as precompiled platform gems, with no decision asked of the user. This replaces the platform-gem support of #2150 and #2154 (merged after 5.1.0, not released) with the shape Socket's backend serves today. Agent mode is not touched. It supersedes #2257 and #2226.

Why

A native gem such as nokogiri is locked as platform gems (nokogiri (1.19.3-x86_64-linux-gnu), nokogiri (1.19.3-arm64-darwin)), and a real lock names several platforms at once: linux and macOS, often Windows and JRuby. A patched build exists only for the platforms the patch service can rebuild and prove, and Bundler takes one source per gem. A rule of "every locked platform or nothing" would leave most real projects unpatched.

The patch service now gives a gem's patch a registry that serves every platform of the gem version: the patched gem where a patched build exists, and upstream's own gem everywhere else. The package reference says, for each platform, which it is. So the gem always moves, the platforms that can be patched are, and nothing breaks on the others.

What a user sees

Hosted, one line per gem and no warning:

nokogiri 1.19.3: patched for aarch64-linux-gnu, x86_64-linux-gnu;
  upstream gem kept for arm64-darwin (no patched build yet)
Case What happens
At least one locked build is patched The gem moves to the patch registry. Each lock entry and each CHECKSUMS line takes the sha256 the registry serves for it.
A later scan, more builds patched The registry URL and the changed checksums are refreshed: nokogiri 1.19.3: now also patched for arm64-darwin; already patched for x86_64-linux-gnu.
No locked build is patched yet The gem is left on its upstream registry, exit 0: nokogiri 1.19.3: no patched build yet for …; left on its upstream registry.
The registry does not list a locked platform The gem is left as it is, exit 0: nokogiri 1.19.3: the patch registry does not list arm64-darwin, so the gem is left as it is.
A newer fix has fewer patched builds than the lock has now The lock stays on the patch it is on, so a build that is patched today is never turned back into upstream's gem: the newer fix has no patched build for x86_64-linux-gnu yet; the lock stays on the patch it is on.
A patched build is withdrawn The lock goes back to upstream's sha256 for that platform, and an installed copy of the withdrawn build is replaced with upstream's gem: upstream gem back for arm64-darwin (its patched build was withdrawn). This also holds while the lock is waiting for a newer fix: a lock that stays on its patch follows that patch's current list.
The gem is locked as its ruby gem alone Exactly as in 5.1.0: the registry URL has no key, and a pair pinned by 5.1.0 is left byte for byte. A fresh bundle install builds the patched ruby gem.
The same lock, with upstream's precompiled gem already installed For a lock whose PLATFORMS is only ruby, Bundler picked the machine's precompiled gem at install time and keeps loading it. As in 5.1.0, the scan reports that copy with the command that installs the patched gem, and its closing line says the gem is still unpatched on disk instead of "Nothing left to patch." vex exits 0 and states the gem as affected.
bundle lock --add-platform <p> afterwards Works from the patch registry by itself.

Vendored mode needs a patched build for every locked platform, because a path: gem is not fetched. With one, it vendors one tree per platform, each from its own platform's patch and checked against that patch's record. Without, it writes nothing, exits 0 and says which platform is missing and that hosted mode can patch the others now.

How it works

  • One request per gem. The reference of the gem's patch is asked with "gemBuilds": true and answers the registry URL and the list of builds: for each platform the sha256 the registry serves and the patch that built it, or none for upstream's gem. There is no per-platform lookup and no index request before writing. Without the list (an older service, or a gem with no platform gems) the patch is a ruby-gem-only patch, as in 5.1.0.
  • The registry URL carries a key (…/<uuid>/s/<key>/, lowercase hexadecimal) that names one fixed list, so the checksums a lock pins stay valid for as long as it names that key. A list with more patched builds has another key, which the next scan takes. A gem locked as its ruby gem alone keeps the URL without a key: under a keyed URL, a lock whose PLATFORMS is only ruby would let Bundler install the local platform's gem, which can be upstream's (confirmed with real Bundler).
  • Events and counts. Each patched build is a counted applied event under its own patch UUID, with details.gemFix, details.platform and details.newlyPatched. A build that keeps upstream's gem is an event that is not counted, with gem_upstream_build_kept. Rollout budgets and severity floors count the gem as one package.
  • A platform gem is a patch of its own, and is judged as one. Socket's backend stamps the files of every patch with a header that names that patch, and a compiled build also changes binaries. So the files of a patched platform gem are never the files of the gem's patch, and no copy of one is checked against the gem patch's record. vex checks the installed copies of a patched build like any installed package, against the record of that build's own patch (asked without file contents, one request per installed patched build), and every copy has to verify. The hosted scan's stale-install guard first looks at the archive RubyGems installed the copy from (cache/<leaf>.gem): its sha256 says whether Bundler installed the gem the lock pins. Where the gem home keeps no archive it reads the build's own record. With neither, the copy is not called stale and not replaced. Where vex cannot read that record it states the build as affected under vex_gem_build_unknown. Vendored mode reads the build's record when it vendors or restores a tree (one request per platform gem) and keeps its file hashes in the ledger.
  • VEX states each build as it is. A patched build is not_affected under its own patch; a build on upstream's gem is affected. Standalone vex attests a build only when the sha256 the lock installs is that patch's. It makes two small requests per such gem (three for a lock with no CHECKSUMS section): the gem's record, the list of builds and, where the lock pins no checksum, the registry's index. Each patched build that is installed costs one more, for that build's record. A build it cannot show patched is written as affected with what settles it, and the run exits 0. Vendored mode attests each tree from its ledger, offline, with no request.
  • A restore is tied to the gem's fix. repair does not take the vendor ledger's word for what to unpack: the patch an entry records for a platform's tree must be the one the fix's listing names for that platform, the entry must pin the gem and the gemspec, the stub gemspec must state the entry's name, version and platform, and the tree is held to the record the service serves now. An entry that fails this is refused before a download, with the tree left as it was.
  • get <uuid> of a platform gem's patch resolves to the gem's patch it was built from and proceeds with that.
  • Platform-qualified patch records (?platform=<p>) are for agent mode. Hosted and vendored mode never select one as a fix of its own.

Codes against main: added redirect_gem_no_patched_build, redirect_gem_platform_unlisted, redirect_gem_newer_fix_waits, gem_upstream_build_kept, vex_gem_build_unknown, vex_gem_install_unpatched, platform_gem_patch_not_taken; none removed; redirect_gem_platform_unsupported now covers only a reference with no list and Bundler before 2.2; vendor_prebuilt_platform_pending also covers a platform on upstream's gem. The retired gemPlatforms field and the gem-platform / gem-platform-stub-gemspec artifact kinds are no longer read. CLI_CONTRACT.md and docs/ecosystems.md describe all of it.

Before this is released

Socket's backend also reads a project's Gemfile.lock to decide what is patched. It must understand a registry URL with a key before a CLI that writes one is released, or it would count upstream's gems under that URL as patched. That change is in progress on the backend and is a condition of the release, not of this merge: nothing here reaches a user until a release is cut.

The backend also keeps a client that does not ask for the list of builds on the answers it gets today: the registry URL without a key lists the ruby gem alone, and no search returns the patch of a platform gem. That needs a matching change in Socket's backend, which is in review. The released 5.1.0 was run against a backend with it, with and without a patched platform build published: its output, the files it writes and its vex are the same in both.

Released 5.1.0 does not read a gem vendored as platform gems: it has no platform-gem vendoring. On a project this branch vendored (both locked platforms patched) its vendor --check exits 1 (vendor_check_failed: a patched file is missing) and its vex exits 1 with no document (the gem is left out, vendor_unwired). It attests nothing wrongly. CLI_CONTRACT.md and docs/ecosystems.md now say so, and say to check and attest such a project with the release that vendored it or a later one; a test pins the sentence in both.

Also in this change

  • A vendor ledger entry in the shape only unreleased builds wrote (gemPlatforms) is no longer read; a ledger that has the key still parses, and vendor --revert and rollback restore the pair.
  • A grant URL no longer appears in the Referer of a followed download redirect. This touches every download from the patch server.
  • The Node binding: redirected[] entries gain optional gemFix, platform and newlyPatched, and a gem locked as platform builds has one entry per patched build; new optional upstreamBuilds[]; a redirect.patches[] row for a build on upstream's gem has action: "upstream_kept"; three new skip reasons.

Limits, stated in CLI_CONTRACT.md

  • A withdrawn build on a machine whose gem home keeps no downloaded archive is not detected, so it stays loaded until the gem is reinstalled.
  • A lock that stays on an earlier patch under --patch-mirror-url does not follow that patch's current list when one of its builds is withdrawn; it is left as it is.
  • A vendored scan with nothing installed does not see a gem locked only as platform gems, as on main.
  • A file of an installed patched build that is changed after install, while cache/ still holds the patched archive, is not repaired by the scan: its guard goes by the archive's sha256 and does not compare the installed files with it. vex leaves such a build out.
  • When upstream stops publishing a platform gem that a lock names, the patch registry no longer lists that platform. The gem is then reported redirect_gem_platform_unlisted on each scan and left as it is, also for a lock that is already on the patch, and vex states that platform's build affected with the remedy (bundle lock --remove-platform). It is not handled further, because that platform's gem can no longer be installed from upstream either.

Review findings

/code-review high on 0cf668f8c reported nine findings. Eight are fixed with a test; the seventh was not a defect:

  1. The hosted guard judged a platform build with a pruned cache/ by the gem patch's record, and called a healthy copy stale on every run. Fixed: archive, then the build's own record, else unjudged (a_patched_platform_copy_with_a_pruned_cache_is_judged_by_its_own_patch).
  2. A restore took each tree's patch, pins and hashes from the committed ledger. Fixed: tied to the fix's listing, empty pins refused, the stub's identity checked, the tree held to the service's record (core a_lost_platform_tree_is_rebuilt_by_a_rerun_and_by_restore; CLI step 5b of a_platform_locked_gem_vendors_and_reports_per_platform_gem).
  3. A lock on this patch's registry was reported redirect_gem_platform_unlisted and dropped when the new listing omitted a locked platform. Fixed at the source: Socket's backend no longer leaves a platform out of a listing while its build is in progress, so the client-side handling first added for this was deleted again (see the second review).
  4. Which record judges a platform build was decided in several places. Fixed for installed copies: a platform build is judged by its own patch everywhere, the in-run --vex included (an_installed_copy_is_evidence_about_its_own_build_alone). The resolver first written for this was replaced after the third review, below.
  5. On the public proxy a build's record is the full view with file contents. vex reads one record per installed patched build (see the third review). The proxy itself ignores include_blobs=false today (checked read-only against production with a free patch: the same 23,134 bytes either way), so the request is unchanged there.
  6. vex had its own copies of the registry index URL and read. Fixed: it uses the hosted scan's helpers.
  7. retract_vendored leaves summary.skipped alone when it drops a gem's advisories. That is right: a vendor advisory is an event the summary never counted. The doc and the test now say so.
  8. fetch_vendor_patch_summary copied the route and query logic. Fixed: one summary_path.
  9. Two module docs said a platform patch's own record is never read. Fixed.

Left, and why:

  • A vendored tree whose ledger entry records no per-build file hashes is still checked against the gem patch's files. Only unreleased builds of this branch wrote such entries, and changing it means deciding what the ledger stores, which is out of scope here.
  • A build's record on the public proxy is still the full view. Making it small needs a matching change in Socket's backend (the proxy would have to honour include_blobs=false, or serve a hash-only route).
  • Three test files still name a platform in a reference purl (e2e_redirect_gem_platform_builds.rs in part, hosted_memory_parity.rs, hosted_gem_closing_total.rs), and the real-Bundler capstone still builds every gem from one patched file and asserts that a vendored gem whose ledger was deleted is attested. With the real service such a gem is left out as vendor_hash_mismatch.

Second review

A second /code-review high on the commits of the first review's fixes reported ten findings.

Fixed, each with a test:

  • 1 and 10 (vex bookkeeping). A platform build now has one outcome from all of its installed copies, attested only when every copy is shown to be the patched build, and it joins the verdicts right after verification, before the in-run gates, the sort and the omission lines. Two gem homes with the same stale build are one entry, and a build is never both attested and affected (an_installed_copy_is_evidence_about_its_own_build_alone).

  • 5 (restore). A restore of a build the fix no longer names for its platform answers vendor_prebuilt_replaced: the copy cannot be restored as it was vendored, nothing is unpacked, and the message names socket-patch rollback <purl> and socket-patch scan --mode vendored. It is no longer worded as tampering or as a first vendoring. The stub check accepts the stubs the backend serves and the stand-in's (s.name = "…".freeze).

  • 7 and 8 (the run's own pins, the archive alone). Both were about attesting a build from the archive in the gem home. That attestation was removed after the third review, below: a build is attested by its own record alone.

  • 9 (record read). The guard reads a build's own record without its file contents, and compares a record's uuid case-insensitively.

  • 2, 3, 4 and 6 (a lock kept on its earlier listing). These were all in the path that kept a lock on its earlier listing while a new listing left one of its platforms out. That case no longer exists: Socket's backend now lists every platform gem upstream publishes in a fix's listing, and a build in progress changes neither the listing nor its key (a member that was never built changes nothing until it is built; a member being rebuilt keeps its entry). The path is deleted here (the rewriter's kept-on-snapshot marker, the engine's confirmation of it, the guard's skip and their test: 143 lines removed, 28 added). A platform the listing lacks is one upstream does not publish; it keeps the neutral report it had, and vex gives it a remedy that is true (a scan changes nothing for it). This needs the matching change in Socket's backend, which is in review.

  • 7, 1 and 10, tests. the_vex_of_the_run_that_moved_the_lock_checks_a_build_by_its_own_record holds the in-run --vex; a_platform_build_in_two_gem_homes_has_one_vex_outcome holds one outcome per build across two gem homes.

Third review

A third /code-review high, on the commits of the second round, reported eight findings. Five came from comparing an installed tree with the archive in the gem home, so that comparison is deleted, not repaired.

  • 1, 3, 7 and 8 (the archive-versus-tree comparison). It had its own path rule (a ./ entry made a correct install look altered, for good), counted a missing or unreadable file as stale evidence, read the archive whole up to three times a run and repeated the gem data walk of the vendored fetch. It is gone, with the attestation of a build from its archive. vex now judges an installed platform build as it judges any installed package: the existing installed-files check, with its own rules for missing and unreadable files, against the record of that build's own patch. That is one request per installed patched build. The guard keeps the archive's sha256 as its first sign that Bundler installed another gem than the lock pins, falls back to the build's own record where there is no archive, and does not compare trees (a_platform_copy_is_attested_by_the_record_of_its_own_patch).
  • 2 (the in-run exemption). The --vex of the run that moved the lock exempted its confirmed pins by the purl without qualifiers, so the gem's pin erased a build's own failure. A build that has an installed copy is now never exempt, in whatever gem home, and where its record cannot be read it is stated affected under vex_gem_build_unknown, as vex states it (a_platform_build_in_two_gem_homes_has_one_vex_outcome, whose last case fails without the fix; the_vex_of_the_run_that_moved_the_lock_checks_a_build_by_its_own_record).
  • 4 (a lock on its own snapshot). First fixed by keeping such a lock on the snapshot it names; that path was deleted after the fourth review, below, and the case is a stated limit.
  • 5 (texts). The comment and the contract paragraph that still said the service leaves a platform out while its build is being made are corrected.
  • 6 (the digest's route). vex no longer needs the digest, so it no longer travels through the pin reports. The guard takes its facts from the reference's list.

Lines for this round: 483 added and 601 removed in 14 files, of which the source files are 196 added and 428 removed.

The rebuild window

While Socket's backend builds a patched gem again, its registry lists what it listed: the gem keeps the sha256 it last built, so the registry's key does not change. A project already on the patch must not be moved off the patched build and back, and its vex must not state a patched build affected for the length of a rebuild, which can fail a CI gate.

  • A reference request about a patch presents the key of the registry snapshot the project's lock takes that gem from: "gemSnapshotKeys": { "<patch uuid>": "<key>" }. During a rebuild Socket's backend answers by that key:

    The request presents Answer
    the registry's own key the registry as it stands: the scan reports the gem as already on its patch, and vex attests its builds
    another key (a lock on an earlier snapshot of the patch) pending_build: the pair is left untouched, exit 0, and the first run after the rebuild moves the lock once
    no key the ruby gem's registry alone, with no list, as a client that asks for none gets

    Outside a rebuild the key changes no answer. There is no new outcome code and no new branch for the window.

  • A build being rebuilt is never taken for a withdrawn one. A locked build goes back to upstream's sha256 only on an answer that lists upstream's gem for it, and the backend gives none for a registry it is still building a gem of.

  • A request with no key is byte for byte the request it was. A lock that names the gem as its ruby gem alone is left as it is and reported as on its patch. A project whose lock names platform builds and is not on the patch yet gets the existing warning redirect_gem_platform_unsupported for the length of the rebuild (exit 0, nothing written) and moves on a run after it; the warning now says what is true in every case, that the service names no platform gem of the version right now. Making this case the quiet redirect_gem_no_patched_build would be one more branch in the rewriter; it is not in this change.

  • The key is read from the lock of the pair the rewriter is given, which is the one Bundler loads: gems.locked for a gems.rb project (an orphan Gemfile.lock beside it is not read), the pair BUNDLE_GEMFILE names where both spellings are present, and none for a twin that nothing settles. The scan and the in-memory engine read it through the filter the rewriter's own files go through.

  • The keys are an argument of the reference call (PatchApi::fetch_registry_references), not state on the client. The scan reads them off the lock, the withdrawn-pin check and the read of a patch a lock stays on included; vex takes them from the registry each gem's lock names; get <uuid> presents none. The in-memory engine reads them from each root's lock and asks about a patch once for each snapshot of it that a root names, and once for all the roots that name none. A request names a patch once, the requests of a run are sent together under the engine's bound, and each root is answered what a checkout of it alone would be. The request it hands a host's provider is the API's body: uuids, gemBuilds: true and, where a lock names one, gemSnapshotKeys. A host that builds its own body from uuids is unaffected: it gets references with no list, and a lock of platform builds is then left alone.

  • Vendored mode presents no key. A vendored copy that is intact asks for no listing, so a rebuild never touches it: a re-scan, repair and vendor --check say what they said (shown on the full stack, for a rebuild of the vendored build and of the gem's own patch). A damaged or missing copy is worded by the answer. When the fix's reference carries no list, or the service says the patch is not ready, its restore says vendor_prebuilt_required: the patch service lists no builds for <gem> right now; run this again later, in the same words on a re-scan and on repair, and changes nothing. A project that is not vendored yet, or whose lock gained a platform, is skipped for the length of the rebuild, exit 0, whichever of the two the service answers: <gem> is not vendored: the patch service lists no builds for it right now. Run this again later. (<gem> was not brought up to date: … Run this again later; its vendored copy stays in force as it is. for a copy that is there). vendor_prebuilt_replaced and the word "withdrawn" are used only when a list is there and names another build, or none, for the platform.

  • The stand-in patch service of the nokogiri workflow and the fixture service of the hosted suite answer by the table above, and the hosted scenario of the workflow runs through the window.

  • Needs the matching change in Socket's backend, which is in review.

Fourth review

A fourth /code-review high, on the commits of the third round and of the window, reported ten findings. Seven were in the path that kept a lock on its snapshot when the list lacks a locked platform, so that path is deleted.

  • 1, 2, 3, 4, 5 and 8 (the lock that stays). The path judged each build by the lock's own pins, and was wrong where the lock has no CHECKSUMS, for the ruby-platform entry, for a build the list does not vouch for, and in writing the lock's own remote: into the Gemfile without the URL check. With the backend's listing rule a list lacks a locked platform only when upstream stopped publishing that gem, so the lock is broken at upstream as well. The gem gets the neutral outcome an unlisted platform always had: reported once, nothing written, no string of the lock in the Gemfile; vex attests the build the lock still installs patched and states the unlisted one affected with the remedy. It is a stated limit (a_lock_on_its_patch_whose_platform_the_list_no_longer_names_is_reported_and_left).
  • 6 (a ruby-only lock in the window). Closed by the backend's rule: a request without a key is answered the current listing, so a lock on the plain URL is not told the patch is being built while a platform build is rebuilt.
  • 7 (side state). The snapshot keys were state on the API client that each host had to remember to set. They are an argument of the reference call now.
  • 9 (build records one at a time). vex reads the records of the installed patched builds several at a time, with the helper its other reads use, and with the same fallback to the public proxy when the API refuses the credential (a_build_record_the_api_refuses_is_read_from_the_public_proxy).
  • 10 (the ruby-platform gem's sha256). The guard knows the sha256 the reference's list gives for the ruby-platform gem again (the_ruby_gem_of_a_platform_lock_is_judged_by_its_list_entry, which fails without it).

Fifth review

Seven findings, on the commits of the fourth round.

  • The key came from the wrong lock. It was read from both gems.locked and Gemfile.lock, with Gemfile.lock winning, while the rewriter edits gems.locked wherever the project has a gems.rb. One helper (gem_project_snapshot_keys) now reads it from the lock the rewriter selects, and the scan, the registry refresh and the in-memory engine use it. Tests: a_projects_registry_snapshots_are_those_of_the_lock_a_run_rewrites, the_key_presented_is_the_one_of_the_lock_the_run_rewrites (both spellings on different snapshots).
  • The in-memory engine presented no key, though it rewrites the same pairs. It reads each root's lock and passes the keys through its provider call. Tests: each_root_is_answered_by_the_snapshots_its_own_lock_names, and the parity case parity_gemfile_platform_lock_on_its_patch_through_a_rebuild (both engines leave the pair byte for byte and present the lock's key).
  • A build being rebuilt and a withdrawn build looked the same to a lock on an earlier snapshot. The backend now answers pending_build there, and the contract says so. Test: a_lock_on_an_earlier_snapshot_waits_out_a_rebuild_and_then_moves_once.
  • Texts that stated an older rule: the request type's docs, the trait's, the stand-in's header, the contract paragraph and the guide. The rule is stated once, on GemSnapshotKeys, and the others point at it.
  • Vendored mode in the window: see "The rebuild window".
  • Two doc links named the build-record reader by its old name.
  • The build-record read asked the authenticated API first even after an earlier read of the run had fallen back. A shortcut for that was taken out again by the sixth review.

Sixth review

Ten findings, most in the places the snapshot key had spread to. The surface is smaller now.

  • The key came from the raw project files (a regression of the fifth round): with BUNDLE_GEMFILE naming the Gemfile beside a gems.rb, it came from gems.locked while the rewriter edited Gemfile.lock. It is read from the pair the rewriter is given. Tests assert which file is rewritten and which key is presented: a_gems_rb_project_presents_and_rewrites_gems_locked_beside_an_orphan_lock, a_twin_presents_and_rewrites_the_pair_bundle_gemfile_names, the_snapshots_presented_come_from_the_pair_bundler_loads.
  • Build records went to the public proxy alone after any refusal (a regression of the fifth round), so records of paid builds came back unread. The shortcut is gone: each record is asked of the authenticated API first and only a refused one goes to the proxy. No state is recovered from the text of a note.
  • The provider request carried a key but no gemBuilds, and the service reads a key only on such a request. One builder states the request, with a test: the_provider_request_asks_for_gem_builds_and_presents_the_snapshots.
  • One key for all roots. The in-memory engine asks with the snapshots each root's own lock names (by patch and snapshot since the seventh round). Test: each_root_is_answered_by_the_snapshots_its_own_lock_names (a root on the current snapshot, one on an earlier one, one not on the patch, in one run during a rebuild).
  • Vendored mode (three findings): the key is removed, see "The rebuild window". Tests: a_damaged_copy_whose_fix_lists_no_builds_is_told_to_run_again_later, and the no-list case of a_locked_platform_without_a_patched_build_is_a_skip_that_downloads_nothing.
  • Tests that asserted nothing are replaced by the ones above.
  • The contract said redirect_gem_platform_unsupported means the patch covers the ruby gem alone. It says when a reference carries no list, and that a lock of platform builds is never moved to the ruby gem's registry.
  • A host that answers plain references for a lock that is on a snapshot registry: both engines leave the pair byte for byte (parity_gemfile_platform_lock_on_a_snapshot_given_plain_references).
  • The released 5.1.0 on a pair this CLI moved to a snapshot registry leaves the Gemfile and the lock byte for byte: its scan exits 0 and skips the gem (redirect_unattributable: "lockfile discovery could not attribute its pin to one package version, so nothing was written for it"). Its vex does not read the snapshot URL as a patch registry: it warns that the remote "is on the Socket patch server but is not a patch-registry/gem/// index" and exits 2 with "No patches in this project; nothing to attest". A project that mixes 5.1.0 and this CLI keeps a working pair, but 5.1.0 cannot attest it.

Seventh review

No correctness bug on the hosted side; nothing dangles after the removals of the sixth round, and older ledgers still read. Ten lower-severity findings, fixed without a new mechanism.

  • One rebuild was a failure or a skip, depending on the answer. For a lock of platform gems, a fix that names no builds right now was the exit-0 skip when its reference carried no list, and a failure when the service said the patch was not ready. Both are the skip vendor_prebuilt_platform_pending now, for a project with an intact copy and for one that is not vendored yet. Tests: a_fix_that_lists_no_builds_is_the_same_skip_for_either_answer, and both answers on the full stack (below).
  • The wrapped line. The words were a sentence with a remedy, which did not fit kept the vendored patch <old>: <detail> for patch <new>. They are a phrase now and each caller ends its own line. With the skip above they no longer reach that wrap.
  • The skip's line was a bare lowercase sentence that did not say the gem was not vendored. It opens like its neighbours: nokogiri@1.18.10 is not vendored: the patch service lists no builds for it right now. Run this again later. (the wording of the eighth round). For a copy that is there it reads … was not brought up to date: … Run this again later; its vendored copy stays in force as it is., and for a hosted pin …; the gem stays hosted. Test: a_fix_that_names_no_builds_says_what_the_gem_is_left_with.
  • The contract. The rows of vendor_prebuilt_platform_pending and vendor_prebuilt_replaced quote the lines as printed (a restore words every patch the service does not serve as vendor_prebuilt_required: …), the row of vendor_prebuilt_pending names the gem case that is a skip of its own, and the list of gem warnings points at the passage as it reads today.
  • read_build_records had no test after the sixth round. a_build_record_goes_to_the_proxy_only_when_the_api_refuses_it pins the rule: the authenticated API first, only a refused record to the proxy, a paid record the API serves is read, one note.
  • After a 401 every build record was still asked of the authenticated API first. The run's client remembers a 401 to an authenticated request (one flag that its clones share), and from then on the run's client is handed out as the public proxy's, to all three reads of vex (the eighth round moved the rule there). A 403 is about one patch and keeps the per-record rule. Nothing is recovered from the text of a note. Test: the_run_stays_on_the_proxy_after_the_credential_is_refused.
  • The in-memory engine's reference requests were grouped by a root's whole map of snapshots and awaited one after another, so roots whose maps differed in one entry asked again about every patch they shared. They are grouped by patch and presented snapshot and sent together, after a cancellation checkpoint. Tests: a_patch_is_asked_about_once_for_each_snapshot_presented, and each_root_is_answered_by_the_snapshots_its_own_lock_names with five roots and three requests.
  • The provider request is the serialized request type of the API client, not a hand-written copy of it.
  • A comment said the mirror gate needs a candidate. A Bundler mirror of every source needs none, so such a project presents no key (no gem of it is redirected, whatever the answer). The comment and the doc say so.
  • The addon's smoke test asserts what a provider receives for a gem: gemBuilds: true on every call, the patch named once per call, and the snapshot of one lock or none.

Eighth review

The seventh and the eighth /code-review high found no correctness bug. The eighth returned six low-severity findings, and a refresh of the public docs found four places where the CLI's own texts disagreed. All are fixed.

  • Every line of a fix that lists no builds says what to do, in words that hold under vendor, scan and get: … the patch service lists no builds for it right now. Run this again later, then what the gem is left with. The failure of a damaged wired copy had lost the remedy, and "until then" referred to nothing. Tests: a_fix_that_names_no_builds_says_what_the_gem_is_left_with, a_damaged_copy_whose_fix_lists_no_builds_is_told_to_run_again_later.
  • One rule for a refused credential. The swap to the public proxy is done once, where the run's client is handed out, so the special case in the read of build records is gone. The flag is set by one helper for every authenticated 401, whichever kind of request met it. Tests: the_run_stays_on_the_proxy_after_the_credential_is_refused, a_refused_credential_is_remembered_whichever_request_met_it.
  • The in-memory engine computes what each root asks for once and plans from borrowed answers: no reference is cloned for a root.
  • A trade-off that is kept: the first round of reference requests carries the keyless references beside the first snapshot of every keyed patch, in the same chunks. That is fewer requests, and one failed request now fails roots that a request per root would have kept apart.
  • A platform the fix's list leaves out was "no patched build yet" in vendored mode, with hosted mode offered, while hosted mode reports it as not listed (redirect_gem_platform_unlisted) and leaves the gem alone. The patch service lists every platform gem upstream publishes, so no build of such a platform is on its way. Vendored mode now says what hosted mode says, with the remedy vex names: nokogiri@1.19.3 is not vendored: the patch registry does not list java. Vendored mode needs every locked platform, and a re-run does not change what the registry lists: this is settled once the lockfile no longer names java (bundle lock --remove-platform java), or the registry lists a gem for every locked platform. The code and the exit status are unchanged (vendor_prebuilt_platform_pending, exit 0). Tests: the unlisted cases of a_locked_platform_without_a_patched_build_is_a_skip_that_downloads_nothing, a_wired_copy_that_cannot_be_rebuilt_fails_instead_of_skipping, the real-Bundler gem_vendor_platform_gems_fresh_checkout_bundle_install_and_revert, and the full stack (below).
  • Texts: the contract row of vex_gem_install_unpatched says that partialFailure is the envelope's status and that the process exits 0; the docs paragraph on vex_gem_build_unknown states the outcome once; the vendored row of the native-extensions table covers a fix with no builds and a platform the registry does not list.

Review

/code-review high reported ten findings on the first version of this branch. All are fixed with tests; the two that mattered most are the rule that a lock is never moved to a fix that patches fewer of its locked builds, and the URL without a key for a ruby-only lock.

The first CI run then found three more things, also fixed: "now also patched for …" was never reported for a lock with no CHECKSUMS section (it now asks the earlier list once when the key changes), a new real-Bundler test assumed which build Bundler names in an error, and the VEX generator's future had grown enough to overflow a test thread's stack in the coverage build (three futures are boxed, and a test bounds the size).

Checked against Socket's backend

The backend's own serving, search and reference code was run on this machine against a private database, with the gem patch and one platform gem's patch published the way the service publishes them, real nokogiri 1.19.3 and Bundler 4.0.15. That run found what this PR's last commits fix: a platform gem's files are stamped per patch, so the client has to check each build against its own record; a ruby-only lock still loads a precompiled copy; and the stand-ins in this repository did not answer the way the service does.

Run Result
Hosted, lock of arm64-darwin and x86_64-linux-gnu, no CHECKSUMS Frozen install loads the patched arm64-darwin gem. vex exits 0 with 4 requests: not_affected for arm64-darwin, affected for x86_64-linux-gnu, no warning. Rollback restores both files byte for byte.
Hosted, Bundler's default lock (eight platforms, CHECKSUMS) Same, vex with 3 requests: one statement not_affected, seven affected, no warning.
Vendored, arm64-darwin only The scan vendors the tree with 8 requests. A frozen install makes no request to the service and loads the patched gem. vex attests it with no request. Rollback is clean.
Vendored, arm64-darwin and x86_64-linux-gnu (one has no patched build) Nothing is written, exit 0, one line naming the platform.
Hosted, PLATFORMS with ruby alone A fresh checkout builds and loads the patched ruby gem. With upstream's precompiled copy installed, the scan reports it with the command, vex exits 0 and says affected; after the command the patched gem loads and vex says not_affected.
Hosted, the gem home's cache/ removed Two scans leave the patched copy alone, say nothing and download no gem. vex attests it with one read of the build's own record (3 requests), as it does with the archive present.
Vendored, a platform tree removed, then repair The tree is restored from the patch the fix names. With the ledger's build uuid edited to another served patch, repair answers vendor_prebuilt_replaced, downloads nothing and unpacks nothing.
Hosted, a file of the installed gem altered while cache/ holds the patched archive vex leaves the build out once, as hash_mismatch, by the build's own record (3 requests), and also with the file gone. The scan says nothing of the copy: its guard goes by the archive's sha256. With the file back, vex attests the build again.
Hosted, the same patched build in the trees of two Rubies vex attests it with one record request for both copies. With one copy altered, neither the scan's own --vex (5 requests) nor a later vex attests the build.
A member inserted as pending for a locked platform The fix's listing has the same key and still serves upstream's line; the scan and vex say nothing new.
A listed member requeued for a rebuild (by the backend's own requeue, claim and build steps) The fix's listing keeps its key. A reference that presents that key is answered the listing: the same key, the same builds. So a scan of the project on the patch says what it said before (the gem already on its patch, nothing left to patch), with the lock, the Gemfile and the gem home untouched and the same 3 requests, and vex attests the patched build with no warning. A request with no key is answered the plain registry and no list, and one that presents another key is pending_build. A project not on the patch yet is left on its upstream registry. The file of the gem being rebuilt is a 404 meanwhile. After the rebuild everything is as before.
The gem's own patch requeued for a rebuild A request with no key, or with another key, is not ready (pending_build). One that presents the lock's key is answered the listing, so the scan and vex of the project on the patch say what they said before. After the rebuild everything is as before.
Vendored, the vendored build or the gem's own patch requeued for a rebuild A re-scan (already_vendored, 2 requests), repair and vendor --check (no request) exit 0, say what they said at rest and leave every committed file byte-identical, while the build is queued and while it is building.
Vendored, a file of the vendored tree damaged during the rebuild A re-scan and repair both say the patch service lists no builds for nokogiri@1.19.3 right now; run this again later, change nothing, and say nothing of a replaced or withdrawn build or of rolling back. No request presents a snapshot. After the rebuild repair restores the tree. The same for a rebuild of the vendored build and of the gem's own patch.
Vendored, a project that is not vendored yet scans during the rebuild The scan exits 0 and skips the gem in one line (nokogiri@1.19.3 is not vendored: the patch service lists no builds for it right now. Run this again later., wrapped within the width on a terminal of 80, 100 and 120 columns), writes nothing, and the scan after the rebuild vendors the build. The same for a rebuild of the vendored build, which is answered a reference with no list, and of the gem's own patch, which is answered pending_build.
Hosted, a lock that names the gem as its ruby gem alone, during a rebuild of a platform build The request names no key and is answered the plain registry. The scan and vex say what they said (Nothing left to patch, one statement not_affected), and nothing changes.
The released 5.1.0 on a pair this CLI moved to a snapshot registry The Gemfile and the lock stay byte for byte (scan exit 0, redirect_unattributable), Ruby still loads the patched build, a frozen install works, and this CLI's next scan finds the pair as it left it. 5.1.0's vex exits 2: it does not read the snapshot URL as a patch registry. With another patch that 5.1.0 understands in the same project (an applied patch with its record in the manifest), its vex exits 0 and writes that patch's statement; it warns that the gem's remote "is on the Socket patch server but is not a patch-registry/gem/// index" and writes no statement for the gem.
Vendored and hosted, a lock that names a platform the registry does not list Vendored: exit 0, one skip, nokogiri@1.19.3 is not vendored: the patch registry does not list x86_64-freebsd. Vendored mode needs every locked platform, and a re-run does not change what the registry lists: this is settled once the lockfile no longer names x86_64-freebsd (bundle lock --remove-platform x86_64-freebsd), or the registry lists a gem for every locked platform., wrapped within the width on a terminal of 80, 100 and 120 columns. Hosted: exit 0, redirect_gem_platform_unlisted (nokogiri 1.19.3: the patch registry does not list x86_64-freebsd, so the gem is left as it is). Neither writes anything.
An installed patched copy with a file changed after install vex leaves the build out (hash_mismatch). bundle pristine nokogiri restores the copy from the patched archive in the gem home's cache/, and vex attests the build again. With the archive pruned from cache/, bundle pristine restores nothing ("Cached gem … does not exist", exit 0) and bundle install --redownload fails; with the copy's gemspec removed from specifications/, bundle install installs it again from the lock's registry and vex attests it.
A patched build is withdrawn The next scan puts the lock back on upstream's gem for that platform and replaces the installed copy.
bundle cache --all-platforms, a checkout with nothing installed, get by a platform gem's uuid Pass.
The released 5.1.0 against the same backend, with and without a published platform build The two transcripts (output, files written, vex) are identical.
The released 5.1.0 on a project this CLI vendored as platform gems (arm64-darwin and x86_64-linux-gnu, both patched) vendor --check exits 1: pkg:gem/nokogiri@1.19.3?platform=ruby: committed artifact .socket/vendor/gem/<uuid>/nokogiri-1.19.3 is missing a patched file (file_not_found). vex, online and offline, exits 1 and writes no document: it warns that the lock's platform entries are not wiring it knows, omits the gem (vendor_unwired) and ends with Error: No applied patches with vulnerability metadata to attest. No request is made. This CLI's vendor --check and vex pass on the same project (one statement, both builds not_affected).

Testing

  • cargo fmt --all -- --check and cargo clippy --locked --workspace --all-features -- -D warnings: clean.
  • cargo test --locked -p socket-patch-core --no-fail-fast: 9,435 passed, 0 failed, 3 ignored.
  • cargo test --locked -p socket-patch-cli --no-fail-fast: 5,991 passed, 2 failed, 538 ignored. The 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 4.0.15 on Ruby 3.4.10, with --ignored: e2e_redirect_gem_build 72 passed, e2e_vendor_gem_build 13 passed. They cover a lock with one patched and one upstream platform (frozen mode too), no locked build patched, a later list with more patched builds, bundle lock --add-platform, locks with and without a CHECKSUMS section, a ruby-only lock, a withdrawn build (the unchanged pair fails to install, the scan repairs it, a fresh checkout installs upstream's gem), and a newer fix with fewer builds.
  • The stand-in patch service of the nokogiri workflow now answers as the backend does (a stamped file and a record per patch, references without a platform, artifacts named after the gem and its version under a token per patch, no search result for a platform gem's patch). With it the workflow's hosted and vendored legs fail on the commit before the per-build check (vex exits 1 with hash_mismatch; the vendored scan exits 1) and pass now: 36 and 26 checks with real nokogiri 1.18.10. The hosted leg runs through a rebuild of the installed build: the lock's key is answered the registry, a request with no key the plain registry and no list, and another key pending_build.
  • The Node addon's smoke test (node --test crates/socket-patch-node/npm/test/smoke.mjs, addon built from this branch): 15 passed.
  • Output is checked by a test on a pty at 80, 100 and 120 columns, and was read with real nokogiri 1.19.3.
  • The last commit (50489f84c) adds the sentence about released 5.1.0 to the contract and the guide, and its test. On it: fmt and clippy clean, --test vendor 165 passed, the contract tests 3 passed. The full suites above were not run again for it: it changes no code.

Not run: the nokogiri workflow itself and the docker-e2e suites (CI runs them), Linux, other Bundler versions for most cases. The gems of the two real-Bundler suites are still built from one patched file, so their per-build records list the same hashes; the vendored suite asserts that vex attests a vendored gem whose ledger was deleted, which does not hold once each build's file differs. With the real service such a gem is left out as vendor_hash_mismatch.

🤖 Generated with Claude Code

A gem patch's reference now lists every platform gem of the gem's
version (`registryOverride.identifiers.gemBuilds`): for each platform
the sha256 the patch registry serves and, where there is a patched
build, the patch it comes from. A platform with none is served as
upstream's own gem, which the registry lists and hands on unchanged.
The registry URL carries the snapshot the list was made at
(`…/<uuid>/s/<n>`); a later reference names a newer one.

This replaces the list of patched platforms only (`gemPlatforms`), under
which a lock moved only when every locked platform had a patched build,
and one platform without one kept the whole gem unpatched.

The gem rewriter:

- moves every locked build to the registry together as soon as one of
  them is patched, each pinned to the sha256 the registry serves for it
  (a platform still on upstream's gem keeps the sha256 it had);
- leaves the gem where it is, with no warning, while no locked build is
  patched: moving it would gain nothing (`gem_unpatched`);
- still skips with `redirect_gem_platform_unsupported` when the registry
  does not list a locked platform, or the reference carries no list at
  all (a patch of the ruby gem alone, as before);
- reports per locked build which patch is in place and whether this run
  put it there (`gem_builds`).

A registry URL is recognised with any snapshot or none, under any grant
token, by the manifest wiring, the lock rewrite and lockfile discovery,
so a pair an earlier run wired is refreshed in place when the snapshot
changes. A snapshot URL is written closed by a slash, as Bundler writes
every remote.

The pin of a gem stays one per package. `engine::pin_reports` turns the
confirmed pins into what a run reports: a gem locked as platform builds
once per locked build, each patched build under its own patch, each
build on upstream's gem with none. `engine::gem_unpatched_skips` gives
the quiet skip of a gem that was left alone.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
A gem patch's registry lists every platform gem of the gem's version: a
patched build for some platforms, upstream's own gem for the rest. A lock
that names platform builds moves to it as one pin, so a run that reported
that pin once said the gem was patched where one locked platform still
installs upstream's gem, and it named the gem's patch where each patched
build has a patch of its own.

Both hosted engines report such a gem per locked build, from the one
expansion of the confirmed pins they share (`engine::pin_reports`):

- `scan --mode hosted` and `get --mode hosted` record one `applied`
  (`verified` on a dry run) event per patched build, under that build's
  own patch, with `details.gemFix` (the gem's patch), `details.platform`
  and, when the run put the build in place, `details.newlyPatched`. A
  build the registry serves as upstream's gem is one `skipped` event
  with no `uuid` (`errorCode: gem_upstream_build_kept`), which `summary`
  does not count. A person gets one plain line per gem on stdout, such
  as `nokogiri 1.19.3: patched for x86_64-linux-gnu; upstream gem kept
  for arm64-darwin (no patched build yet)`. On a terminal it breaks
  after a clause, not in the middle of a word.
- The in-memory engine's `redirect.patches[]` holds the same rows
  (`pinned` per patched build, `upstream_kept` for the others), its
  `redirected[]` lists the patched builds with `gemFix`, `platform` and
  `newlyPatched`, and the new `upstreamBuilds[]` lists the rest.

A gem left on its upstream registry because no locked build is patched
yet is skipped under `redirect_gem_no_patched_build` in both engines,
before the unpinned patches are worked out. It is no warning and never
`redirect_unconfirmed`, and a person reads one plain line of it instead
of the "No patches could be switched" block.

Everything else keeps working on the pins, one per package: the package
counts of the human summary, the rollout budget and the severity floor,
the takeover, the stale-install probes, VEX and telemetry.

The gem mock of the stale-install suite serves `gemBuilds`, with a patch
per patched build, under a snapshot URL. The parity suite covers a build
on upstream's gem and a gem with no patched build, from the new
`platform-pass-through` fixture.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
A hosted gem locked as platform builds keeps upstream's own gem for a
platform with no patched build: its lock entry pins upstream's sha256,
and a machine of that platform holds the right copy. The guard judged
that copy like any other. Its cached archive passed only because the
sha256 of upstream's gem was counted among the patched artifacts. With
the archive pruned, the patch's file hashes called upstream's files
stale, and the run downloaded upstream's gem from the registry to
replace the install with the bytes it already held, and reported a
refresh.

Such a build is not judged at all, installed or committed to the cache
dir: nothing is reported, nothing is refreshed, no gem is downloaded
and no patch record is fetched for it. The patched artifacts are those
of the patched builds alone. A platform with a patched build is handled
as before.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Four refinements of how a gem patch's registry is read.

The list is asked for. The patch service answers a reference request as
it always has unless the request carries `gemBuilds: true`, so that a
release that knows no list keeps getting the ruby gem's registry alone.
Every package reference request now carries it: the hosted lookup, the
vendored one, and the public-proxy route.

The list names the ruby gem too (`platform: "ruby"`, the patch itself).
The entry was refused as a malformed platform, which cost the gem its
grant. It is accepted, and the ruby gem's checksum is read from it
where it is there, so every locked build is pinned from the one list.

A platform can be missing from the list for a while: the service leaves
it out while its patched build is being made. A lock that names such a
platform was skipped with a warning, as if the registry were wrong. The
gem is now left as it is with no warning (`gem_unlisted`, skip reason
`redirect_gem_build_pending`) and moves on a later run. The warning
`redirect_gem_platform_unsupported` remains for a patch with no list at
all and for the merged lock of Bundler < 2.2.

The snapshot level of a registry URL is an opaque key of lowercase hex
digits, not a number. It is recognised and never read for a meaning.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
A gem the Bundler lock names as precompiled platform gems is vendored as
one unpacked patched platform gem per locked platform. Those gems are no
artifacts of the gem's patch: each patched platform gem has a patch of
its own, and the gem patch's package reference lists every platform gem
of the version (`registryOverride.identifiers.gemBuilds`), with the
sha256 its registry serves and, where there is a patched build, the patch
it comes from. The per-platform artifact kinds `gem-platform` and
`gem-platform-stub-gemspec`, and the `platform` field of an artifact, are
not served, so they are no longer read.

Vendoring such a gem:

- asks for the gem patch's reference once, to learn the patch of each
  locked platform's build, and for the references of those patches in
  ONE request (`ApiClient::fetch_vendor_references`);
- downloads each platform's gem (its patch's `tarball`) and stub gemspec
  (`gem-stub-gemspec`), a few at a time, and verifies each against the
  digest its own reference states and the gem also against the sha256
  the gem patch's registry lists for that platform. A mismatch refuses
  with `vendor_prebuilt_integrity_mismatch`, names the platform, and
  leaves an existing copy as it was;
- keeps verifying the trees against the gem patch's record for the
  patched files they ship. No record of a platform's patch is fetched;
- records per tree which patch it came from and the digests its
  downloads passed (`VendorEntry::gem_builds`, `gemBuilds` in the
  ledger). A restore fetches each tree again by its recorded patch, in
  one reference request, and checks the downloads against the recorded
  digests.

While a locked platform has no patched build (the registry serves
upstream's own gem for it, does not list it, or the reference carries no
list) the gem is not vendored: nothing is downloaded or written, and the
skip (`vendor_prebuilt_platform_pending`, as before) is one line that
names the platforms. A gem already vendored stays in force as it is when
the lock gains such a platform; a copy that is damaged and cannot be
rebuilt is still the `vendor_prebuilt_required` failure.

An entry that names only the platforms of its copy (`gemPlatforms`,
written by builds before this one) still reads, verifies and reverts.
It is no longer written: the next vendor run rebuilds the copy from each
platform's patch and records them. A restore of such an entry says to
vendor again, since nothing names a patch to fetch its trees by.

`gems_locked_as_platform_gems` tells a caller which gems the lock
resolves that way.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Each patched platform gem has a patch of its own
(`pkg:gem/<name>@<version>?platform=<platform>`), which a package search
returns beside the patch of the gem itself. Agent mode takes it for the
installed copy of that platform. Vendored mode patches a gem through the
patch of the gem itself, whose reference names the patched build of
every locked platform, so there the platform gem's patch is no fix of
its own: selected as one, it reached the gem backend and failed as
`platform_gem_unsupported`, or made the gem's records ambiguous.

`scan --mode vendored` now drops those patches from the batch offers and
from the selection (`ScanPolicy::leave_out_platform_gem_patches`), and
`get --mode vendored` from its search results, before anything is
reported, downloaded or handed to the vendor engine. A platform gem's
patch named by its UUID in `get` is the caller's exact intent and still
reaches the backend's own refusal.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
A gem vendored as platform gems is one committed copy, verified as one
against the record of the gem's patch. What an install loads from it is
one platform gem's tree, and each tree was built by a patch of its own,
which the vendor ledger records. A VEX document that named the gem under
the gem's patch said nothing a scanner could match to the platform gem
it found, nor which patch built it.

So the document names each platform gem
(`pkg:gem/<name>@<version>?platform=<platform>`) under the patch of its
tree, with the vulnerabilities of the gem patch's record: the fix is the
same in every one of them. The copy is still verified once, before the
view is widened, and nothing is fetched: the ledger entry says which
patch built which tree. An entry that names no patch for its trees is
attested as the gem itself, as before.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Hosted mode reports a gem locked as platform gems once per locked build,
each under that build's own patch. Vendored mode reported it as one event
under the gem's patch, so the two modes disagreed about which patches a
run put in place, and telemetry never named the platform patches.

The vendor engine now turns the outcome of such a gem into one counted
event per platform gem (`pkg:gem/<name>@<version>?platform=<platform>`,
`uuid` the platform's patch, `details.gemFix` the gem's patch,
`details.platform`): `applied` when this run vendored or rebuilt it,
`skipped` / `already_vendored` on an in-sync re-run, `verified` for a dry
run of a recorded copy, and `verified` or `failed` per platform gem
under `vendor --check`. The builds come from the entry the backend hands
back, else from the ledger. The gem is still one package: the human
summary, the in-sync line and the vendored count of telemetry take the
events of one gem once. A retracted run drops the gem's advisories with
its per-platform events.

A gem with a locked platform that has no patched build prints the
backend's one line as it is, without the `Skipping <purl>:` lead, and
passes through whatever the ledger holds: the line already says which
vendored copy stays in force. For a gem the lockfile pins hosted (a
takeover, an eject) it says the pin stays instead of naming hosted mode
as what to run; an eject is refused whole on it, as for any pin it
cannot vendor.

Two things kept such a gem from being vendored at all:

- the installed-variant probe hashed a patched file in the installed
  copy, which is one platform's gem at most and often ships none of the
  patched files, and skipped the gem silently on a miss. A gem the lock
  resolves as platform gems is not probed;
- a damaged copy of an entry that names no patch for its trees was sent
  to the restore, which has nothing to fetch them by. It goes to the
  backend, which rebuilds it from each platform's patch.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The patch service has a patch record per patched platform gem
(`pkg:gem/<name>@<version>?platform=<platform>`), which a search returns
beside the gem's own. Agent mode takes it for the installed copy of that
platform. A hosted run patches a gem through the patch of the gem
itself, whose reference lists the patched build of every platform, so
there the platform gem's record is no fix of its own. Selected as one it
was asked about in the reference request, skipped with "the hosted patch
server has no artifact for this patch" (or left "not hosted"), and every
later scan offered it as a newer patch of the gem.

A hosted `scan` and `get` now leave those records out as a vendored run
does, before anything is reported, looked up or written, and so does the
in-memory engine's selection. The predicate lives in core
(`engine::is_platform_gem_patch`) so that the engines share it.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
A gem is not moved to the patch registry while no locked build is
patched. The same rule kept a lock that is ALREADY on the registry where
it was when the build it pins was withdrawn and no other locked build is
patched: the snapshot the lock names refuses that build from then on,
so `bundle install` fails on that platform until someone unwinds by
hand.

A lock on the registry now follows the reference whatever it lists: the
URL moves to the current snapshot and the withdrawn build's checksum
goes back to the upstream gem's, which that registry hands on. A lock
that was never moved still stays upstream.

Also brings the vendored arm of the "left to patch" test to the line
vendored mode prints for a platform without a patched build.

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

A gem patch's registry serves a patched build for some platforms and
upstream's own gem for the others, and a lock that names platform builds
takes all of them from it under one `GEM` section. The lock's wiring
therefore says that the gem is on the registry, not which locked build
is patched. A reader that has only the committed files and the patch
service to go by (a VEX document made after the run that moved the lock)
had nothing to decide that with.

`vex::gem_builds` decides it per build, by the one thing a patched gem
and upstream's gem never share: the sha256 of the archive.

- `locked_gem_pins` reads the builds a lock names of a gem version, each
  with the sha256 its `CHECKSUMS` pins.
- `gem_build_states` holds each against the list a gem patch's reference
  carries (`gemBuilds`). A platform build is the patched build of its
  platform's patch only on the sha256 the list gives beside that patch,
  and upstream's gem only on the one it gives beside none. For a build
  the lock's `CHECKSUMS` does not pin, the archive is the one the lock's
  own registry serves, read from that registry's compact-index document
  (`gem_index_url`).
- Anything else is `Unknown`, with why: nothing names the archive the
  lock installs, the list leaves the platform out, or the lock installs
  another archive than the list names. The last is a list of a later
  registry than the one the lock names: a build that is patched there is
  not shown patched for a lock that does not pin it.

The ruby-platform gem a patch's registry serves is the patch itself, so
that entry is the gem's patch by the lock's wiring, as for a gem locked
as its ruby-platform gem alone.

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

A hosted scan breaks the line about a gem's builds after a clause when
it prints on a terminal, so that no platform name is cut in two. `vex`
is about to print a line of the same shape, and a command module may not
import another one's helpers.

`wrap_line`, `wrap_words` and `wrap_tokens` move from the hosted scan to
`ui::text`, with their tests, unchanged. The hosted scan takes them from
there.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
A gem that a Bundler lock takes from its patch registry as platform
builds is one hosted pin, and a VEX document attested it as one: the gem,
under the gem's patch. The registry serves a patched build for some
platforms and upstream's own gem for the others, so that statement said
`not_affected` of a platform that installs the unpatched gem, and it
named the gem's patch where each patched build has a patch of its own. A
scanner that finds the platform gem of such a platform was told to drop
a finding that is real.

The gem is still judged as the one pin it is. The document then names
each locked build (`pkg:gem/<name>@<version>?platform=<platform>`, and
the gem's own purl for a ruby-platform entry beside them):

- a patched build is `not_affected` under its own patch, with the
  vulnerabilities of the gem patch's record, since the fix is the same
  in every build;
- a build the lock installs as upstream's own gem is `affected`, with
  what changes that as its action statement. This is the document's
  rule for a package the build is known to take without its patch, the
  one a Bazel hub already falls under;
- a build of which neither is shown is left out, and a warning names
  the gem, the reason and what to run (`vex_gem_build_unknown`).

The records of all of them stay in the view the document is built from,
so no statement names a form of the gem (the purl without a platform)
that also stands for a build the document does not call patched.

Where the builds come from:

- `scan --mode hosted --vex` and `get --mode hosted --vex` hand over
  what the run reports per locked build (`engine::pin_reports`), so the
  run's own document costs no request beyond the run's.
- A later `vex` (and the `--vex` of `apply` and `vendor`) reads the lock
  and asks the patch service once for the references of the gems' patches
  (one request for all of them). A build is attested by its patch only
  when the sha256 the lock's `CHECKSUMS` pins for it is the one the
  reference lists beside that patch. For a lock with no `CHECKSUMS`, the
  index of the registry the lock names is read too, once per gem: that is
  what such a lock installs. The reference can be of a later registry
  than the lock's; a build it lists as patched while the lock pins
  another archive is not attested.
- `--offline`, a failed request, a reference with no list: nothing is
  known of the platform builds, and none is attested. A ruby-platform
  entry beside them is the gem's patch by the lock's wiring, as before.
- A gem locked as its ruby-platform gem alone, and every other
  ecosystem, are as they were, with no request of their own.

An installed copy is evidence about its own build alone. A machine of a
platform on upstream's gem holds upstream's gem, as its lock entry names
it; judged as the gem's copy it withheld the builds the lock does
install patched. The copy of a build the lock does not install patched
is not judged, and the copy of one it does still is.

What a run says:

- `vex --json` reports a build on upstream's gem as the hosted scan
  does: an uncounted `skipped` event under `gem_upstream_build_kept`,
  which does not make the run a partial failure. The events of every
  build named in place of a gem carry `details.gemFix` (the gem's patch)
  and `details.platform`, a gem vendored as platform gems included.
- For a person, `vex` prints one line per gem under its summary, in the
  words of the scan's own line (`nokogiri 1.19.3: patched for
  x86_64-linux-gnu; upstream gem kept for arm64-darwin (no patched build
  yet)`), with `not attested for <platform>` for a build left out. On a
  terminal it breaks after a clause.
- The line that folds several omissions of one reason names a platform
  gem with its platform, since the builds of one gem share its name.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The hosted scan leaves the installed copy of a platform on upstream's
gem alone: it is the gem that platform's lock entry names. The VEX of
such a machine has to agree with that, in the run's own document and in
a later `vex`: the copy must not be attested as patched, and it must not
withhold the build of the other platform, which the lock does install
patched.

The stale-install suite already builds that machine, with a real gem
home, with and without the gem's cached archive. It now also checks both
documents there: the other platform's build under its own patch, this
machine's build as affected.

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

Two things the full suites check that the tests of the platform builds
did not meet.

The golden fixture of a lock that names a platform the list leaves out
still expected `redirect_gem_platform_unsupported`. That platform is one
whose patched build is being made, which is no warning: the fixture
expects none, and is named for what it holds (`platform-build-pending`).

The hosted and vendored end-to-end files read the `--json` envelope with
helpers of their own under names the shared readers have
(`warning_codes`, `events`). They use `common::envelope` for it.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The stand-in patch service of the nokogiri end-to-end script still
answered the way the patch service did before a gem's fix became one
patch: it named the patched platform gems as artifacts of the gem's
patch (`gem-platform`, `gem-platform-stub-gemspec`) and as
`gemPlatforms`, under the plain registry URL. The CLI reads none of
that any more, so the hosted and vendored legs of the nokogiri workflow
had nothing to install from.

The stand-in now answers as the service does:

- each patched platform gem has a patch of its own, which the search
  routes return beside the gem's and whose reference serves that gem
  (`tarball`) and its stub gemspec; one reference request answers for
  every uuid it names;
- a reference request that carries `gemBuilds: true` gets the registry
  under a snapshot URL, whose key is derived from what the registry
  lists, and the list of the version's gems (the ruby gem, each patched
  platform gem with its patch, each platform still on upstream's gem
  with none); a request without it gets the plain URL and no list;
- the registry under a snapshot lists every gem of that list, and
  answers the file of a platform with no patched build with a 302 to a
  stand-in of the upstream registry's file host on a second port, which
  serves the real gem. Nothing leaves the machine for it;
- `publish` makes a platform's patched build appear under a newer
  snapshot, and the earlier snapshot keeps answering as it did.

The script's hosted scenario checks what a run reports per locked build
and that every reference request asks for the list. With
`--pass-through` (and `--add-platform`, to lock a platform nothing here
installs) one locked platform has no patched build at first: the lock
keeps upstream's checksum for it, a frozen install on that platform gets
upstream's nokogiri through the redirect, and the scan after `publish`
moves the lock to the newer snapshot and the install to the patched gem.
With no locked build patched, nothing moves. The vendored scenario
checks that the platform patches are asked for in one request, that no
record of theirs is fetched, and that a gem with a platform that has no
patched build is not vendored until it has one.

The workflow gains two hosted legs (the runner's own platform passed
through, and another one) and one vendored leg.

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

The real-Bundler hosted capstones for a gem locked as precompiled
platform gems mounted a patch API that named the patched platform gems
as `gemPlatforms` and `gem-platform` artifacts of the gem's patch, under
the plain registry URL. The CLI reads the list of the version's gems
(`gemBuilds`) under a registry snapshot instead, so all five failed at
the scan, and nothing proved the new behaviours against a bundler.

The platform cases now share one fixture, `PlatformProject`: the gems,
a project the real bundler locked and installed, and a stand-in for the
patch service that answers as the wire contract has it. Each patched
platform gem has a patch of its own, which the search routes return
beside the gem's; a reference request gets the snapshot URL and the
list only when it asks (`gemBuilds: true`), and every helper that reads
the reference requests asserts that each one asked; the registry under
a snapshot lists every gem of that list and answers the file of a
platform with no patched build with a 302 to a second wiremock, the
stand-in of the upstream registry's file host, so nothing leaves the
machine; a later listing is a newer snapshot beside the earlier ones.

The five capstones are converted (every locked build patched: with and
without `CHECKSUMS`, with the ruby entry beside the builds, and taken
over by a vendored run, which now asks for the platform patches in one
request) and assert the per-build events. New cases, all on a
`CHECKSUMS` lock:

- one platform patched and one on upstream's gem, with this machine in
  either role: the scan moves both, `bundle lock` agrees byte for byte,
  and a fresh checkout installs frozen, in deployment mode and unfrozen.
  The machine of the patched platform gets the patched gem; the other
  gets upstream's gem through the redirect, and the scan downloads
  nothing for it. `rollback` restores the pair;
- no locked build patched, then one platform missing from the list:
  nothing moves, quietly, until the list has it;
- a newer snapshot: the URL and the one changed checksum are rewritten,
  the build is reported as newly patched, `bundle install` installs it,
  and the earlier snapshot still installs what it did;
- `bundle lock --add-platform` over a hosted lock resolves the new
  platforms from the registry, patched or not, and a re-scan reports
  them and writes nothing;
- the refresh's download of `gems/<file>` follows a redirect the
  registry answers with.

A machine of platform X is this machine: bundler installs the platform
gem of its host, so the cases that turn on which platform is patched
run twice with the roles swapped.

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

The vendored platform-gem capstone served the patched platform gems as
`gem-platform` / `gem-platform-stub-gemspec` artifacts of the gem's
patch and expected the wording of that model (backticked platforms,
"kept the vendored patch"), so it failed at its second step. Vendored
mode takes each platform's gem from that platform's own patch, which
the gem patch's reference names in `gemBuilds`.

Its stand-in service now answers that way (one request answers for
every uuid it names, the list only on request, a platform with no
patched build listed as upstream's own gem), and the capstone checks,
against the real bundler:

- one locked platform with no patched build: exit 0, the one line, a
  counted skip, the gem patch's reference alone asked for, nothing
  downloaded or written;
- every platform patched: the gem patch's reference and then ONE
  request for the platform patches, each tree that platform's own gem
  (the fixture gems carry a file that names their build), the ledger's
  `gemBuilds`, one event per platform gem, and one package for a person;
- `vex` and the manifest-less `vex` attest each platform gem under the
  patch of its tree, `vendor --check` gives one verdict per platform gem;
- a newer patch that lacks a platform leaves the vendored one in force,
  in the line the engine prints for it;
- a ledger entry that names platforms only (`gemPlatforms`) still
  checks and reverts, and the next run records each tree's patch.

The frozen and unfrozen installs from the committed tree, the tampered
foreign tree, the in-sync re-run and the byte-for-byte revert stay.

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

A hosted lock names the registry snapshot it was moved to, and installs
from it until the next scan: the patch service keeps a snapshot
answering as it did after a later one exists. The stand-in does that
too, but nothing in the script looked. The hosted scenario now reads
what the earlier snapshot lists before and after the missing builds are
published, and requires the two to be the same and the newer snapshot
to be another URL.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
A locked platform can lack a patched build in two ways: the patch
registry lists upstream's own gem for it, or its build is still being
made and no list names it yet. Vendored mode treats both the same (the
gem is not vendored, one line, exit 0, nothing written), and the
capstone only served the first. Its not-vendored step now runs against
both.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The five converted capstones run on every bundler from 2.2 on, of which
only 4.0.15 is on the machine they were converted on. Holding a run's
warnings to an exact list there would turn a caveat another bundler
line adds into a failure of a case that is about something else. They
assert what they asserted before: the codes that must not appear, the
one a lock with no `CHECKSUMS` section brings, and the refresh note.
The cases added for `CHECKSUMS` locks keep the exact lists.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Seen on a terminal with real nokogiri at 80 and 100 columns.

A clause wider than the terminal wraps at a word, and the clause after
it was then put on a row of its own although the row had room: the
"left on its upstream registry" line ended in a row holding one
platform name and another holding the last three words. A clause now
goes on from where the wrapped one left the row.

The one line vendored mode prints for a gem with a platform that has no
patched build was not wrapped at all (211 columns for three platforms),
where the hosted line of the same gem breaks after a clause. It is
wrapped the same way when a person is at the terminal, and stays one
line in a pipe.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The real-Bundler capstones of a gem locked as platform builds ended in
the VEX matrix written for a gem locked as its ruby gem: one statement
under the gem's own patch. `vex` attests such a lock per build, each
patched build under that build's patch, so all five capstones failed on
a correct document.

Their VEX step is a matrix of its own. Over the fresh checkout the real
bundler installed, `vex` and `apply --vex` must name each locked build
under its own patch, and the ruby-platform entry under the gem's, from
exactly the requests the lock's shape calls for: the gem patch's record
and one package reference, plus the index of the lock's registry where
the lock has no CHECKSUMS to say what it installs. `--offline` attests
nothing (`record_unavailable`, no document) and asks nothing, and the
pair reverted to its registry version names the patch nowhere. The
scan's own `--vex` document is held to the same statements.

The file's own `warning_codes` goes, for the one in `common::envelope`:
the lint of the `cli` suite allows no private envelope reader.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
No real-Bundler case read the document of a lock the hosted scan moved
with one patched build and one the registry passes through to upstream.
That is the lock a wrong document over-claims on: the gem is one pin
under one patch, and the build that installs upstream's gem must never
be attested by it.

The case takes the lock the real bundler wrote through the scan, a
checkout with nothing installed and a frozen install, with this
machine's platform as the patched build and as the one on upstream's
gem. Each time the patched build is `not_affected` under its own patch
and the other `affected`, with exit 0: the copy on the machine changes
what is said of neither. A third run has a lock without CHECKSUMS, where
the index of the lock's registry is what says which build is which.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Describe hosted and vendored mode for a gem a Bundler lock names as
precompiled platform builds as they are: the list of a version's gems on
the gem patch's reference, the registry URL with its snapshot key, the
one line and the per-build events, the two quiet cases, per-build VEX,
all-or-nothing vendoring from each platform's own patch, and the codes
that go with them.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
A serve URL holds its grant token in the path, and the client that
downloads from one follows redirects: a patch registry may answer the
file of a gem it has no patched build of with a redirect to the upstream
registry. The HTTP client set a `Referer` on the redirected request, so
the host it was sent to received the whole serve URL, token included.

The plain client sets no `Referer`. The redirect is still followed.

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

For a gem a Bundler lock takes from a patch registry as platform builds,
a build whose state could not be told (the lock pins another archive than
the patch service lists, the reference or the registry's index could not
be read, `--offline`) was left out of the document under a `skipped`
event, the run became a partial failure, and it exited 1 when nothing
else was attested. A reader of the document could not tell such a build
from one the project does not have, and a scanner fed the document kept
no statement about it.

`vex` states what it knows. Such a build is in the document as
`affected`, with an action statement that says it could not be shown
that the lockfile installs a patched build for that platform, why, and
what settles it. It names no patch. The run's status and exit code are
what they are without it: `vex_gem_build_unknown` stays the warning (one
per gem and reason) and becomes the code of the build's uncounted event,
shaped like the one of a build on upstream's gem. The line for a person
says `not shown patched for <platform>`.

`--offline` with no local record is as it was: with no record there is
no vulnerability to state anything of, and the gem is omitted as
`record_unavailable`.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
A patched platform build can be withdrawn, because it is unsafe. The
next hosted scan puts upstream's sha256 back into the lock for that
platform, but a machine that had installed the build kept loading it:
the stale-install guard passed over every build the patch registry
serves as upstream's own gem, and `bundle install` keeps a gem it has
installed.

The guard judges the copy of such a build, and its archive in Bundler's
cache dir, by the sha256 the reference lists for the platform. An
archive that is upstream's gem is the right copy, as before: nothing is
said, downloaded or fetched for it. A readable archive with another
sha256 is replaced with upstream's gem, downloaded from the patch
registry (which hands that file on) and verified against the listed
sha256 before a byte is used, under the switches of every other refresh
(`--no-gem-install-refresh`, `--gem-refresh-shared`, `--dry-run`). What
cannot be replaced is warned about under the guard's own codes, in words
that say a withdrawn build is still installed and how to remove it. The
lines of a refresh name the upstream gem and never call the result
patched, and so does the next step.

Such a copy keeps nothing of the gem out of the run's VEX: the document
says `affected` of that build whatever is installed, and still attests
the other builds.

A copy whose gem home holds no archive of it is not judged.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The snapshot keys a reference request presents were state on the API
client that each command had to remember to set, and the `PatchApi` trait
could not carry them: a new call site that forgot regressed without a
compile error.

They are an argument of the call now, on the client and on the trait
(`GemSnapshotKeys`), so every host says which snapshots it presents:

- the scan reads them off the project's lock, for its reference requests,
  the withdrawn-pin check and the read of a patch a lock stays on;
- `vex` takes them from the registry each gem's lock names;
- `get <uuid>` and vendored mode present none;
- the in-memory engine and the Node host do not ask for a gem's listing
  with this call (their request names the uuids alone), so they present
  none. That is unchanged, and stated where they pass the empty map.

A key is the snapshot level the rewriter recognises in a remote:
lowercase hexadecimal digits.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
`vex` read the record of each installed patched platform build one
request after another, and had no fallback when the API refused the
credential: a stale token turned every installed patched build into
`vex_gem_build_unknown`.

The records of a run are read several at a time, with the helper the
other reads of `vex` use, and a record the authenticated API refuses
(401/403) is asked of the public proxy, with the same note as those
reads.

Tests: a refused record is read from the proxy and the build is attested;
and, for the guard's facts restored with the unlisted change, a lock that
names the ruby-platform gem beside a platform build has no stale install
when the reference's own checksum is not the list's entry.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
A reference request presents the snapshot the project's Bundler
lock names for a patch. The key was read from both `gems.locked`
and `Gemfile.lock`, with `Gemfile.lock` winning, while the rewriter
edits `gems.locked` wherever the project has a `gems.rb`. A stale
lock of the other spelling could so present a key the project is
not on.

One helper reads the key from the lock the rewriter selects, and
the scan and the registry refresh both use it.

The in-memory engine presented no key at all, though it rewrites
the same pairs. It now reads each root's lock with that helper and
passes the keys through its provider call, and the Node provider
sends them in its request (`gemSnapshotKeys`, beside `uuids`).
Where two roots name different snapshots of one patch, the first
root's is presented.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
A gem vendored as platform gems is restored tree by tree from the
builds its fix names today. That request named no registry
snapshot, so while one of the builds was being made again the
patch service answered with no list, and `repair` told the user
the build was replaced and to roll back and vendor again.

The ledger entry now records the key of the snapshot the fix named
when the trees were vendored (`gemSnapshot`), and a restore
presents it, in a request of its own. A build that is only being
made again is then still named, and the restore waits for it.

An entry written before this asks with no key as before; its
message now says a rebuild is one of the causes and to run again.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The read of the records of installed builds asked the
authenticated API first even when an earlier read of the same run
had been refused by it and had fallen back to the public proxy.
It now starts on the proxy in that case, and says nothing twice.

Two doc comments linked to the reader under its old name.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
While a gem a patch's registry lists is being built again, the
registry lists what it listed, under its key. A request that
presents that key is answered the registry, one that presents
another key is told the patch is not ready, and one with no key is
answered the ruby gem's registry alone.

The request docs, the contract, the guide, the stand-in service of
the nokogiri suite and the fixture service of the hosted suite said
an older rule. They say this one now, and the suite holds it: a
lock on an earlier snapshot waits out a rebuild and is never read
as a withdrawal, and a project not on the patch yet is left alone.

The warning for a lock of platform builds that is answered no list
says what is true in every case: the service names no platform gem
of the version right now.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The vendor ledger recorded the snapshot a gem's fix named, and a
restore presented it. Only that one path did, the wording of a
miss went by whether a key was sent and not by what was answered,
and a keyed request left the prefetch plan's batch.

An intact vendored copy asks for no list, so a rebuild never
touched it. The key, the ledger field and the special case are
gone. A damaged or missing copy is now worded by the answer: when
the fix's reference carries no list, or the service says the patch
is not ready, the run says the patch service lists no builds for
the gem right now and to run again later, in the same words on a
re-scan and on a restore. "Replaced" and "withdrawn" are said only
when a list is there and names another build, or none, for the
platform.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The read of the records of installed builds went to the public
proxy alone once any earlier read of the run had been refused,
also after a refusal of one patch. Records of paid builds the
authenticated API would have served then came back unread, and
those builds were stated as unknown. The state was also recovered
from the text of a note.

Each record is asked of the authenticated API first again, and
only a refused one goes to the proxy.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The snapshot a reference request presents was read from the raw
project files. With BUNDLE_GEMFILE naming the Gemfile beside a
gems.rb, the key came from gems.locked while the rewriter edited
Gemfile.lock. It is read from the pair the rewriter is given now,
the one Bundler loads, by the scan and by the in-memory engine.

The in-memory engine presented one key per patch for every root,
the first root's, so a root could get an answer its own lock
would not have got. It asks once per distinct set of snapshots:
roots that name the same share a request, a root with others or
none has its own.

The request the engine hands a host's provider says what it
needs: gemBuilds beside uuids and gemSnapshotKeys. The service
reads a key only on such a request.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The contract named the lock by its spelling and the first root's
key. It names the pair Bundler loads and one request per set of
snapshots, says when a reference carries no list, and gives the
vendored wording for a fix that lists no builds.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
A fix names no builds to vendor from while the patch service has not
read the version's gems or is building one of them again. It says so in
two ways: a reference with no list, or a patch that is not ready. For a
lock of platform gems the first was the exit-0 skip and the second a
failure, so one rebuild failed or skipped a scan depending on which
answer came back. Both are now the skip
(`vendor_prebuilt_platform_pending`), for a project with an intact copy
and for one that is not vendored yet.

The skip's line opens like the line of a platform with no patched build
and ends with what the gem is left with:

  nokogiri@1.18.10 is not vendored: the patch service lists no builds
  for it right now; run the scan again later.

A restore keeps its own ending ("; run this again later"). The words no
longer reach the line that wraps a detail as "kept the vendored patch
<old>: <detail> for patch <new>", which a sentence with a remedy did
not fit.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The in-memory engine grouped its reference requests by a root's whole
map of snapshots and awaited the groups one after another. Two roots
whose maps differed in one entry each asked again about every patch
they shared, and nothing between the groups let a cancel through.

The requests are now grouped by patch and presented snapshot: a patch
is asked about once for each snapshot of it that a root names, and once
for all the roots that name none. A request names a patch once, and all
of them are sent together, bounded like the chunks of one request were,
after a cancellation checkpoint. The round that follows a lock that
stays on its patch is one such call for every root, too.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The request handed to a host's provider was written by hand beside the
type the API client serializes for the same body. It is that type now,
so the two cannot drift. The body is unchanged, as
`the_provider_request_asks_for_gem_builds_and_presents_the_snapshots`
shows.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The only test of `read_build_records` went with the shortcut it
tested. This one pins the rule: each record is asked of the
authenticated API first, only a record the API refuses goes to the
public proxy, a paid record the API serves is read, and the fallback is
noted once.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
After a 401 the authenticated API refuses the credential itself, yet
every build record was still asked of it first, one wasted request per
record. The run's client now remembers a 401 to one of its JSON
requests (a flag its clones share), and the read of build records
starts on the public proxy when it is set. A 403 is about one patch, so
after one each record is still asked of the API first. Nothing is
recovered from the text of a note.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The comment in `gem_snapshots_presented` said the mirror gate needs a
candidate. A Bundler mirror of every source needs none: it drops the
pair there, so such a project presents no key, and no gem of it is
redirected whatever the answer. A mirror of one source is judged when
the rewriter's files are read.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
No test on the JavaScript side checked what a provider receives for a
gem. The smoke test now runs three roots on one gem patch (two locks on
different snapshots of its registry, one on the upstream registry) and
asserts that every call carries `gemBuilds: true`, names the patch
once, and presents the snapshot of one lock, or none.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
`vendor_prebuilt_platform_pending` listed "the reference carries no
list" with a wording the code no longer prints, and
`vendor_prebuilt_replaced` said a restore reports
`vendor_prebuilt_pending`, although a restore words every patch the
service does not serve as `vendor_prebuilt_required`. Both rows now
quote the lines as printed, the row of `vendor_prebuilt_pending` names
the gem case that is a skip of its own, and the list of gem warnings
points at the passage as it reads today. The engine's requests are
described as they are grouped now.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The sentence stood between the per-platform wording and "counts the
same way", which refers to that wording. It follows them now.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The lines of a gem whose fix lists no builds right now had lost "run
this again later" everywhere but for a gem that is not vendored, where
it said "run the scan again later" under `vendor` and `get` too. The
failure of a wired copy that is damaged ended "cannot be rebuilt until
then" with nothing for "then" to refer to.

Every such line now reads "<gem> <lead>: the patch service lists no
builds for it right now. Run this again later" and ends with what the
gem is left with, as the line of a platform with no patched build does.

Also in the vendored lines: a locked platform that the fix's list
leaves out was reported as "no patched build yet for <platform>", and
with other platforms patched the line offered hosted mode. The patch
service lists every platform gem upstream publishes, so such a platform
is one upstream does not publish: no build of it is on its way, and
hosted mode leaves the gem alone as well
(`redirect_gem_platform_unlisted`). The line now says that the registry
does not list the platform and what settles it, with the remedy `vex`
names for such a build:

  nokogiri@1.19.3 is not vendored: the patch registry does not list
  java. Vendored mode needs every locked platform, and a re-run does
  not change what the registry lists: this is settled once the lockfile
  no longer names java (`bundle lock --remove-platform java`), or the
  registry lists a gem for every locked platform.

The code and the exit status are unchanged
(`vendor_prebuilt_platform_pending`, exit 0).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The flag that says the authenticated API answered 401 was set by the
JSON reader alone, one of the places that classify an answer. A
download or a package reference that met the 401 left it unset. Every
path now classifies through one method of the client, which records the
401 of an authenticated request.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Starting on the public proxy after a 401 was a special case in the read
of build records. It is done where the run's client is handed out, so
the three reads of `vex` (patch records, gem lists, build records)
follow one rule and the special case is gone. A 403 is about one patch
and changes nothing.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Each root cloned every reference it selected to hand the planner a map
of its own, and worked out what it asks for on every pass. What a root
asks for is computed once, and the planner reads the answers where the
round put them: the two functions that read the map take any map of
borrowed or owned answers.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
- A platform the fix's list leaves out: the vendored row said "not
  listed yet" while the hosted row says upstream does not publish it.
  The vendored row quotes the new line and its remedy.
- `vex_gem_install_unpatched` said "partial failure" beside "exit code
  0". The envelope's `status` is `partialFailure` and the process exits
  0; the row says which is which.
- The paragraph on `vex_gem_build_unknown` stated the outcome twice and
  opened a sentence with "that" where nothing had been named.
- The vendored row of the native-extensions table did not mention the
  line of a fix that lists no builds, which names no platform, nor a
  platform the registry does not list.

The rows quote the no-builds lines as they print now.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
`refused_platform_gem_is_counted_as_left_to_patch` runs one fixture in
hosted and in vendored mode. It expected "the patch registry does not
list <platform>" from hosted mode and "no patched build yet for
<platform>" from vendored mode, which is the disagreement the previous
commit removed. Both modes are now held to the registry's wording.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The contract and the guide said nothing about older releases and a copy
vendored as platform gems. Released 5.1.0 was run on such a copy (every
locked platform a patched build): it has no platform-gem vendoring, its
`vendor --check` fails (`vendor_check_failed`, a patched file is
missing) and its `vex` leaves the gem out (`vendor_unwired`) and attests
nothing for it. Both texts say so, and say to check and attest such a
project with the release that vendored it or a later one. A test pins
the sentence in both.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…ith upstream's gem for the rest (#2342)

* Vendor a gem locked as platform gems once one locked platform has a patched build

A gem `Gemfile.lock` names as precompiled platform gems was vendored only
when every locked platform had a patched build. Bundler's default lock
names eight platforms, so such a gem stayed unpatched in vendored mode
until all eight had one.

It is now vendored when the fix's list names a patched build for at least
one locked platform. Each of the others gets the tree of the gem the patch
registry lists for it: upstream's own gem, unchanged. That gem is
downloaded from the patch server, checked against the sha256 the list
names, and its tree carries the gemspec the gem itself holds (its
`metadata.gz`, which Bundler reads like a Ruby gemspec). Hosted mode
installs the same gem for such a platform.

- The ledger records such a tree as a `gemBuilds` entry with no `uuid`
  and the sha256 of its gem. It records no files: the copy's file
  inventory vouches for every byte of the tree, as it does for the files
  of a patched tree that the patch does not name, and the digest is what
  a restore fetches the gem again by.
- A copy that is intact asks for the fix's list (one request) and is
  vendored again when the list names another build for a locked platform:
  a patched build that was published since, or upstream's gem where the
  patched build was withdrawn.
- A newer fix that has no patched build for a platform the vendored copy
  of an earlier patch holds one for is a skip: the earlier copy stays in
  force.
- Unchanged: a lock none of whose platforms has a patched build, a
  platform the registry does not list, and a build the list names whose
  patch is not served are the skips they were.

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

* Report a vendored tree of upstream's gem as hosted mode reports such a build

A gem vendored as platform gems is reported per tree. A tree of
upstream's own gem (a locked platform with no patched build) now gets
what hosted mode gives a locked build the patch registry serves as
upstream's gem:

- the advisory `skipped` event `gem_upstream_build_kept`, with no `uuid`,
  which `summary` does not count; `withdrawn: true` and the matching
  reason where the run put the tree in place of a patched build, and
  `newlyPatched: true` on a patched build the run put in place of
  upstream's gem;
- one line per such gem under the summary line, in hosted mode's words
  (`nokogiri 1.19.3: patched for arm64-darwin; upstream gem kept for
  x86_64-linux-gnu (no patched build yet)`). A gem whose every tree is a
  patched build prints no line, as before;
- in `vex`, the `affected` statement of that platform gem with what
  changes it, read from the ledger with no request. The patched trees are
  attested as before.

`vendor --check` fails every tree of a copy that does not verify, the one
of upstream's gem included, so a copy that holds upstream's gems alone
still fails its check. Telemetry takes such a tree as about no patch.

A dry run of `scan --mode vendored` asks the fix's list for a gem already
vendored as platform gems, as the wet run does, and reports the trees the
wet run would put in place when the list names other builds.

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

* Cover a gem vendored with upstream's gem for a platform at the CLI level

The stand-in patch service of the platform-gem tests now serves
upstream's own gem for a platform it lists with no patched build, from
the gem patch's registry and with the sha256 the list names.

- A lock with one patched platform and one that has none: vendored, the
  one line, the counted and the advisory event, the ledger, a later run
  in step (one request), `vendor --check` and a change to the upstream
  tree, an offline `vex` (the patched build attested, the other stated
  `affected`), and revert byte for byte.
- A later run that takes a published build and one that follows a
  withdrawal, each with its dry run first.
- Every dry run (`vendor`, `scan`, `get`) says what the wet run does.
- A takeover of a hosted gem with upstream's gem for a platform, by a
  scan and by an eject.
- The tests of a gem that is left alone or stays hosted because of one
  platform now use a build whose patch is still being built, and a lock
  none of whose platforms has a patched build keeps the one-line skip.

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

* Run a gem vendored with upstream's gem for a platform on real Bundler

The platform-gem capstone of the real-Bundler suite gains the mixed case:
two locked platforms with a patched build (this machine's among them) and
one the registry serves as upstream's own gem. The stand-in registry now
serves that gem's file.

The gem is vendored: two counted `applied` events and the advisory one,
upstream's gem downloaded from the patch server, its tree with the YAML
gemspec the gem carries. A fresh checkout installs frozen with no request
to the patch service, Ruby loads the patched build of the running
platform, `bundle install` and `bundle lock` regenerate the lock byte for
byte, `vendor --check` passes and revert restores both files.

A platform the list leaves out and a build whose patch is still being
built stay the skips they were. An in-sync re-run now makes one request,
and a newer patch that lacks a build the vendored copy holds is worded
as hosted mode words it.

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

* Document vendoring a platform-locked gem with upstream's gem for a platform

`CLI_CONTRACT.md`: the gem row of the vendored layouts (the tree of
upstream's gem, where it comes from, the gem's line, how a later run
follows the list, the ledger entry of such a tree, its events and its
`vex` statement, the dry runs), and the rows of
`vendor_prebuilt_platform_pending`, `vendor_prebuilt_replaced` and
`gem_upstream_build_kept`.

`docs/ecosystems.md`: the vendored row of the native-extensions table and
the support matrix cell.

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

* Vendor real nokogiri with upstream's gem for a platform in the e2e script

The vendored scenario of `tests/nokogiri/nokogiri_e2e.rb` no longer waits
for every platform. With `--pass-through` naming some of the locked
platforms, the scan vendors nokogiri with the patched build of the others
and upstream's own gem, served by the stand-in's registry, for those. The
script checks the events, the trees and their gemspecs, where upstream's
gem was asked for, the line of a later scan, the `vex` statements, and a
frozen install of a fresh checkout with the service unreachable: Ruby
loads the patched nokogiri where this machine's platform has a patched
build, and upstream's nokogiri from the committed tree where it has none
(`--pass-through own`). The next scan then takes the builds the stand-in
publishes. With no patched build at all nothing is vendored, as before.

The compatibility workflow runs the vendored scenario with the runner's
own platform passed through as well.

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

* Keep the gem's line in a helper module, and preview a wired lock by the list

The line that says which platform builds of a gem are patched is printed
by hosted mode and now by vendored mode. It moves, with the filter
vendored mode applies to it, into the helper module
`commands/gem_build_lines.rs`, so that `vendor` does not import `scan`
(the command modules' layering test).

The core test of the request-less preview covers a lock already wired to
the patch's copy: one request (the fix's list) while the copy holds what
the list names, the trees the wet run would put in place when the list
names another build, and no promise when a patched build it names is not
served.

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

* Never make an intact vendored gem worse when its fix's list moves

Review findings on the gem backend, with the rule that an intact
committed copy is never made worse and a run never fails because of
something it could have left alone.

- An intact copy whose list moved went through the rebuild of a missing
  or stale copy, where any failure but the pending skip ended the run.
  When the list cannot be followed (a request that fails, a build whose
  gem fails its digest or whose stub is not served, an upstream gem that
  does not unpack) the copy now stays in force: the run ends as it does
  for a copy in step, with one line (`vendor_gem_list_not_followed`). A
  build the list names that is not served yet keeps its skip. A dry run
  says the same. The advisory of a copy that did follow its list has a
  code of its own (`vendor_gem_list_followed`).
- A ledger entry that names no build of its trees says nothing of a
  moved list: no request is made for it and the copy stands.
- The package references of several patches can be asked for in one
  request and remembered by the client: a later read of one of them makes
  no request, and a request that brought no answer is not made again per
  patch. A run asks for the lists of the gems it finds vendored this way,
  and the fix's reference is read once whether or not the list moved.
- Upstream's own gem is downloaded with a client that follows no
  redirect: a redirect the registry answers is the gem not being served.
- The skips of `locked_build_sources` (a platform the list leaves out, no
  patched build at all, a newer fix with fewer builds) are judged before
  an upstream gem the list does not pin fails the gem.
- The download advisory names a copy of upstream's gems alone as such and
  says where it came from, the `.gitignore` advisory names the gems as
  they are, and the registry URL of an upstream gem is built in one place.
- The ledger's doc comment says what each older reader does with a tree
  of upstream's gem.

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

* Vendor a damaged gem copy from the list once the list moved, and count real skips

Review findings on the CLI side of a gem vendored as platform gems.

- The vendor loop restores a damaged copy before it reaches the backend
  and stopped at a restore error. A restore that is refused only because
  the list of the gem's fix names other builds now
  (`vendor_prebuilt_replaced`) goes on to the backend, which vendors the
  copy again from that list, as it does for an intact copy. `repair`
  still refuses and names the scan. A ledger edited to name another
  patch for a tree looks the same and is settled the same way: the list
  chooses what is unpacked.
- The lists of the gems already vendored as platform gems are asked for
  in one request before the loop, and by the dry-run preview of a scan.
- `VendorTally` no longer subtracts the uncounted advisory event of a
  tree of upstream's gem, so a package skipped beside such a gem is said.
- `vex`: a tree of upstream's gem under a purl the view already attests
  leaves that purl alone, as a hosted build does.
- The dry-run preview of a scan reports an in-step copy per tree, with
  the gem's line, as the real run does.
- The line of a copy that could not follow its list prints as a note.

Tests: a damaged copy after the list moved (either tree), an intact copy
whose rebuild fails with every file compared byte for byte (dry and wet),
the dry run of an in-step copy, the tally, the vex view, and the edited
ledger settled by the list.

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

* Document how a vendored gem follows its list without being made worse

`CLI_CONTRACT.md`: the one request for the lists of all the gems vendored
as platform gems, the download of upstream's gem that follows no
redirect, what a run does when the list cannot be read or cannot be
followed (`vendor_gem_list_not_followed`, a note, exit 0, the copy
untouched), the advisory of a copy that followed its list
(`vendor_gem_list_followed`), and that a vendor run whose exact restore
is refused because the list moved vendors the copy again from the list
while `repair` still refuses.

`docs/ecosystems.md`: the same in the vendored row of the
native-extensions table.

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

* Say in the nokogiri script that vendored mode follows no redirect

With `--pass-through-redirect` the stand-in registry answers the file of
upstream's gem with a redirect to its upstream stand-in. Vendored mode
takes that gem from the patch service alone, so the vendored scenario now
checks that the scan does not vendor the gem, asks nothing of the
upstream stand-in and writes nothing, and then goes on once the stand-in
publishes the builds.

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

* Say a vendored gem stays in force only when it still stands, and drop the client memo

Review findings on the gem backend and the API client.

- A run that could not vendor an intact copy again said the copy "stays
  in force as it is" without looking at it. Two failures happen after the
  copy was changed: the new trees are in place and the uuid dir's git
  metadata cannot be written, or the swap of the stage fails and cannot
  be undone. One function, `copy_in_force`, now answers whether the
  recorded copy stands with its metadata in place. The in-step path and
  every outcome that says the copy stays in force go through it
  (`wired_copy_failed`); a copy that no longer stands is the failure it
  is for any damaged copy. A copy left in force gets its `.gitignore`
  and `.gitattributes` put back, as a copy in step does.
- The client-wide memo of batched references is gone, and with it the
  remembered "no answer" that failed later reads of the same patch. The
  batch goes through the vendor prefetch plan: a planned download can be
  a position whose reference alone is read
  (`PlannedDownload::reference`), which shares the plan's one reference
  request and is never fetched ahead.
- The rebuild of a copy whose list moved takes the gems that list was
  read to name (`BuildsFrom::Listed`), so the fix's reference is asked
  for once with or without a plan.
- A redirect is "not found" only for the client that follows none. The
  client that follows redirects answers one it cannot follow as it did.
- `restore` returns a structured reason (`RestoreError::list_moved`),
  true only when the list of the gem's fix names another build than the
  entry records; a reference that does not pin upstream's gem is a miss.
  `restore_follows_list` asks the same without downloading, for a dry
  run.
- `follows_list` is the one rule for which copies follow a list.
- Failure points for the stage swap, its undo and the uuid dir's
  metadata, for the tests of the two failures above (debug builds only).

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

* Plan the lists of vendored gems with the download plan, and settle a restore by its reason

Review findings on the CLI side of a gem vendored as platform gems.

- The collect, sort, dedup and remember block is gone from the vendor
  loop and from the dry-run preview of a scan. One helper,
  `list_follower`, says which packages follow the list of their fix; the
  vendor loop plans each as a position whose reference alone is read (a
  dry run plans nothing else), and the preview attaches the same plan for
  the rows in step. The plan's one reference request serves them, under
  its own guard.
- The fall-through after a refused restore is decided by the restore's
  structured reason (`list_moved`), not by the prefix of a formatted
  error, so a reference that does not pin upstream's gem is the failure
  it is.
- The dry run of a damaged copy whose list moved no longer reports
  `wouldRedownload` and stops: it asks whether the restore would be
  refused for a moved list and, as the wet run does, goes on to preview
  the copy vendored from the list.
- `vex`: every tree of a vendored copy whose purl the view already
  attests is left to that record, as the hosted loop does, the patched
  ones included.

Tests: each of the two failures that change the copy (the uuid dir's
metadata after the trees are in place; a stage swap that cannot be
undone) forced with a failure point, with what is printed and the exit
code; the dry run of a damaged copy; the metadata put back by a run that
leaves the copy in force; the vex view for a patched tree.

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

* Document the plan's shared request, the in-force check and the dry run of a damaged copy

`CLI_CONTRACT.md`: the references of the gems vendored as platform gems
are positions of the run's download plan and share its one request; what
an unreachable service costs; a run says a copy stays in force only after
checking that it stands, with its git metadata put back; a rebuild that
fails after it changed the copy is a failure; the fall-through after a
refused restore is for a moved list alone, and its dry run previews the
copy vendored from the list.

`docs/ecosystems.md`: the same, briefly.

The planner shim the tests call is compiled for tests only.

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

* Answer the plan's reference-only positions from its batch, and write a wired gem's metadata before the swap

Third review round, the core side.

- The download plan: a position whose reference alone is read keeps the
  batch's answer, so a restore and the rebuild after it read the same
  list with one request; a batch request that failed is the answer of
  every such position it named, so a batch the service refuses is not
  asked again once per position; and a package fetch never waits on such
  a position, of which nothing is fetched. `ApiError` is `Clone`.
- A gem the lock names as platform gems is planned by its own backend as
  a reference-only position, and `in_step_reference` says which in-step
  packages still read one. Those positions no longer depend on what
  gates the downloads: where nothing is fetched ahead the plan holds
  them alone, and its task never runs.
- The uuid dir's git metadata of a wired copy is written before the new
  trees are moved in, so a write that fails leaves the copy as it was and
  the copy stays in force. The failure point for the state this removes
  is gone; the ones for the swap and its undo stay.
- The skip of a build that is not served yet says what there is to say
  of the metadata at the end of its line.
- `RestoreError` is an enum (`ListMoved` or `Failed`, each with its
  detail) with no `Deref` and no out-parameter.

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

* Plan reference positions by the backend's rule, and tally a replaced build as not in step

Third review round, the CLI side and the contract.

- `vex`: a tree of a vendored copy is left to an existing record only
  when that record is of another patch. A record of the tree's own patch
  is of the same build, which the committed tree attests. (End to end,
  the manifest record of a platform gem's own patch is set aside for the
  wired patch before this is reached, `vex_record_superseded`; the test
  of that scenario passed before the change and stays as a regression
  test.)
- The planner asks the backend which in-step packages still read a
  reference (`vendor::in_step_reference`); the CLI's own helper is gone.
  A run that fetches nothing ahead (a dry run, or an API in-flight cap of
  one) judges only the candidates whose ledger entry is such a package,
  and none when the ledger has no such entry.
- A dry run counts a copy as in step only when its trees are the builds
  the ledger records: a build replaced under another patch is one the
  wet run vendors again.
- `RestoreError` is matched as the enum it is, in the vendor loop and in
  `repair`.
- `CLI_CONTRACT.md`: the shared request no longer depends on the archive
  gates; a failed request is the answer for every gem it named; the
  metadata is written before the trees are moved in.

Tests: the dry-run tally of a damaged copy with a replaced build; the
planner with nothing to plan; a copy whose metadata cannot be written
stays in force (exit 0, nothing moved in); the swap that cannot be
undone, kept; the vex view for a record of the tree's own patch.

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

* Plan a single reference-only position too

A gem that follows the list of its fix may read that reference more than
once in a run: the restore of a damaged copy, then the rebuild or the
in-step check. With one such gem and nothing else planned there was no
plan, so the two reads were two requests that could see two lists. The
plan is now attached for one reference-only position as well; its task,
which only a download starts, never runs.

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

* Name what works in three texts of a platform-locked vendored gem

The `vendor_prebuilt_replaced` error and its contract row told the user
to roll the gem back and then run a vendored scan. A vendored scan alone
vendors the copy again from the list, so the message and the row name
that one command, once.

The skip of a build that is listed but not served yet, and the skip of a
platform the registry does not list, still said "Vendored mode needs
every locked platform". They say what is needed now: a gem, patched or
upstream's own, for every locked platform.

The contract and the guide state which releases read a copy with a tree
of upstream's gem: one with this support and the platform-gem vendoring
it builds on. 5.1.0 and earlier do not know such a tree and can attest
the gem as patched for every platform.

Tests pin the remedy sentence and that it names one command in the core
restore tests and the CLI repair test, the two skip lines at 80 columns,
and the contract row and the guide sentence.

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

* Leave a vendored tree whose purl the view attests to that record

The vendored loop of the vex view made an exception for a record of the
tree's own patch. By the account of the commit that added it, no run
reaches it: a manifest record of a platform gem's own patch is set aside
for the wired patch before the loop runs. The loop follows the hosted
loop's rule again, a purl the view already attests keeps its record, and
compares no uuid. What is left is always an insert, so it is one.

`repair` reads the detail of a refused restore through the one accessor.

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

* Ask for each vendored gem's list by its own request, and write the metadata after the swap

The fourth review's findings came from two things that are now gone.

The lists of the gems a run finds vendored as platform gems no longer
ride the download plan. `reference_only`, the single-position plan, the
kept answers, the replayed failure and the planner's reference pass are
removed, and the prefetch plan is what it is on the base branch. Each
such gem asks for the reference of its own fix, live, where it needs
it: one small request per vendored platform gem per run. A service that
does not answer is bounded by the client's circuit breaker, and a gem
whose reference cannot be read keeps its copy and says nothing.

A restore and the rebuild that follows it are decided by one answer
without a cache: the restore reads the fix's list once (`FixList`), and
a refusal over it (`RestoreError::ListMoved`) carries it to the backend,
which vendors the copy again from it. The dry run's question hands the
same list. `BuildsFrom::Listed` holds the list where it was already
read, and the request is made in one function.

The uuid directory's git metadata is written after the new trees are in
place again. It is not part of the copy, so a write that fails is the
warning every backend gives for ignore rules it could not vouch for, and
never a failure: the trees are in place, and the entry handed back
records them. A failed rebuild no longer leaves a uuid directory holding
the metadata alone, and unwritable metadata no longer stops a rebuild.
The "Also:" suffix of the pending skip, which nothing could produce, is
removed.

Tests: the request of a copy in step names its own fix alone; a refused
restore hands its list on and the fix's reference is asked for once, wet
and dry, at the core and CLI levels; unwritable metadata is a warning
with the new trees in place and recorded; a failed rebuild leaves no
uuid directory where there was none.

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

* Document the per-gem list request, the handed list and the metadata warning

The contract and the guide state the cost of following a list plainly:
one small request per vendored platform gem per run, not batched. A
refused restore hands the list it read to the rebuild; a damaged copy
whose list did not move is restored and then asked about once more. The
uuid directory's git metadata is written after the trees are in place,
and a failed write is `vendor_artifact_gitignore_unchecked`, whose row
now names the gem. The "Also:" suffix is gone from the contract.

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

* Say what released 5.1.0 does on a copy vendored as platform gems

The contract and the guide said that 5.1.0 and earlier could attest the
gem as patched for every platform. Run against a project vendored with
one patched platform and one platform on upstream's gem, 5.1.0 does
neither: it has no platform-gem vendoring, so `vendor --check` fails
(`vendor_check_failed`, a patched file is missing) and `vex` leaves the
gem out (`vendor_unwired`) and attests nothing for it. Both texts say
that, and the test that pins them follows.

The metadata test gains the first vendor: a uuid directory whose git
metadata cannot be written is vendored, wired and recorded all the same,
with the warning.

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

* Finish every copy of a platform-locked gem with one function, and ask about its list once, briefly

The fifth review found the uuid directory's git metadata handled five
ways. One function, `finish_platform_copy`, now ends every path that
puts the trees of a gem vendored as platform gems in place or says they
stay in force: a first vendor, a rebuild of a wired copy, a restore, a
copy found in step and one that stays in force.

- It writes the uuid directory's `.gitignore` and `.gitattributes`. A
  write that fails is the warning `vendor_gem_git_metadata_unwritten`,
  which names the two files and says to make them writable. No path
  treats it as an error any more (`restore` did), and none drops it: a
  skip that leaves the copy in force ends its line with it.
- Then it asks git whether it would commit the copy. Only a first vendor
  did; a rebuild of a wired copy with a project `*.so` rule and an
  unwritable `.gitignore` left the binaries out of the commit with a
  generic warning. The refusal names the unwritten files as its cause
  when that is why, with that remedy. A first vendor removes the copy
  it made; a copy the lock already names stays where it is, and git is
  asked with its index, since it keeps committing a file it tracks.

The question a copy in step asks of its fix's list is advisory: one
attempt of at most five seconds, never retried and outside the circuit
breaker (`fetch_vendor_reference_once`, on the client's existing single
POST). Two such reads that failed used to open the breaker and fail the
run's real vendoring unasked, after two retry ladders.

`restore_with_list` hands back the list a restore read when it restores
the copy too, and the backend judges the copy by it, so the two no
longer ask twice. `FixList` carries its fix's uuid, and a list of
another fix is ignored. `restore_list` takes the service and the name
and version it is given; the gems a list names are resolved once and
handed on as such.

The vendored `vex` loop is unchanged: a new end-to-end test with a
manifest record of a build's own patch beside the vendored entry shows
the build attested from the committed tree.

Tests: unwritable metadata on every path, at the core and CLI levels,
with and without a project rule that ignores the binaries, tracked and
not; the advisory read at the client (one request whatever the policy,
the breaker untouched, its own bound when nothing answers) and in the
backend; the list handed on by a restore that succeeds, and a list of
another fix.

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

* Document how a platform-locked copy is finished and that its list check is advisory

The contract describes the one step every path ends a copy with, the
new warning `vendor_gem_git_metadata_unwritten` in a row of its own, and
the refusal that names it as the cause. The row of
`vendor_artifact_gitignore_unchecked` is what it was: it never covered
a write failure. The list request of a copy in step is described as
what it is, one short attempt outside the circuit breaker, and a restore
as handing its list on whether it restores the copy or is refused.

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

* Ask git about a platform-locked copy only where trees are about to be placed, before the swap

The sixth review's findings came from asking git on every path that
finishes a copy. That was wrong for a copy that is already committed.

`finish_platform_copy` keeps its one write of the uuid directory's
`.gitignore` and `.gitattributes` (a failure is the warning, never an
error) and takes a mode in place of a flag:

- `CopyStep::Placing`: a first vendor, a rebuild of a wired copy, a
  restore, and a dry run's preview of one. Git is asked BEFORE the
  staged trees are moved in, as if nothing were tracked, which does not
  read the index. With the uuid directory's own rules in place no rule
  above them reaches a file of the copy, so the question is whether a
  rule excludes the directory; where they could not be written it is
  asked of every staged file, and the refusal names that as its cause.
  A refusal leaves what is on disk as it was: a first vendor writes
  nothing, an intact copy whose list moved stays in force through the
  note that already says so, with the refusal as the reason, and a
  restore reports its failure with the copy as it was. A dry run asks
  the same question and writes nothing.
- `CopyStep::Confirming`: a copy found in step or left in force. Git is
  asked nothing, as on the base branch.

Before, a rebuild was refused only after the new trees were swapped in,
which left an intact copy with trees the ledger did not record and exit
1, and made every later scan download the gems again. An in-step scan
ran `git check-ignore` against the index for every file of the copy on
every run, and could fail a copy in a project without a `.git` of its
own.

A run that did not place its trees leaves no uuid directory holding the
metadata alone.

Tests, at the core and CLI levels: a refusal on each path with the copy
compared before and after, dry and wet alike; a committed copy whose
list moves under a rule that excludes its directory stays byte for byte
with one note that names the rule; a copy in step starts git for the
run's own ledger check and nothing else, and a rebuild asks one
question without the index, the same in a dry run (counted with a
logging `git` on PATH); a copy in step in an ignored directory of an
outer repository stands.

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

* Document where git is asked about a platform-locked copy

The contract and the guide say that git is asked only where trees are
about to be placed, before they are moved in and without the index, in
a dry run too; that a refusal leaves what is on disk as it was, on each
path; and that a copy in step or left in force asks git nothing.

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

* Say a wired copy's pending skip in a scan's dry run too

A scan or get vendored dry run reported an intact platform-gem copy as
already vendored when the fix's list had moved to a patched build the
patch service does not serve yet. preview_locked_builds dropped that
refusal, so ask_platform_gems kept the in-sync verdict, while the wet run
skips the gem with vendor_prebuilt_platform_pending and says the copy
stays in force (wired_copy_failed).

The preview of a wired lock now returns the pending refusal, and the scan
preview turns it into the wet run's skip line for an intact copy. Any
other refusal still leaves the copy's verdict as it was.

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

* Expect the pending skip from a wired copy's preview in the no-record test

614513e made preview_locked_builds return the wet run's
vendor_prebuilt_platform_pending refusal for a wired lock whose list names
a patched build the service does not serve yet. The no-record preview test
still expected None for that case, so the coverage leg failed. Assert the
pending refusal instead, as the wired-copy test added in 614513e does.

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

---------

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants