Skip to content

Fix Bun pins on the patch server under a patch mirror (#2279) - #2282

Open
Mikola Lysenko (mikolalysenko) wants to merge 5 commits into
mainfrom
agent/fix-bun-mirror-prior-patch-server-pin
Open

Mikola Lysenko (mikolalysenko) wants to merge 5 commits into
mainfrom
agent/fix-bun-mirror-prior-patch-server-pin

Conversation

@mikolalysenko

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

Copy link
Copy Markdown
Collaborator

LLM Description written by Claude Code:claude-fable-5-2

Fixes #2279

Summary

A Bun project that an earlier hosted run pinned directly on the patch server, in a run with --patch-mirror-url:

  • Before: both lock formats got redirect_bun_non_registry_entry_skipped ("installs … from a URL or local tarball … stays UNPATCHED; depend on the registry release"), which is false: that copy is the patched one. A binary bun.lockb got no redirect_mirror_pin_not_moved at all, so the only guidance was the false warning.
  • After: the false warning is gone for a pin on a patch server of the run, and redirect_mirror_pin_not_moved names the file, the host and the mirror for bun.lock and bun.lockb alike. For bun.lockb, whose pin rollback refuses, the remedy is to restore the lock as it was before the pin, not rollback <purl>.

Nothing new is written to a lockfile: the pin is left as it is, as before. Only warnings change.

Root cause

The Bun rewriters own an earlier hosted pin only on the host they are writing (the mirror), so a patch-server pin fell through to the branch for a user's URL / file: tarball. And the redirect_mirror_pin_not_moved lookup searched the project's text files, where a binary bun.lockb is not.

The change

  • patch/redirect/mod.rs, patch/redirect/bun_binary.rs: the rewriters behave as before (the entry is left, the warning is raised, the patch is kept out of the in-run VEX's assumptions), and additionally record an entry whose URL is in the patch server's path shape for the uuid of the patch being pinned (RewriteResult::bun_patch_shaped_pins). They know no host but the one they write, so they cannot vouch for the URL's host themselves.
  • commands/scan/hosted.rs (mirror_pins_not_moved): the scan knows the run's patch servers. For a recorded pin on one of them it retracts the user-tarball warning and gives redirect_mirror_pin_not_moved in its place, also when the run pinned another copy of the package on the mirror (the lock still fetches the first copy from the patch server). A recorded pin on any other host stays a user's tarball, exactly as on main.
  • CLI_CONTRACT.md: the patch mirror section and the two warning rows.

The in-memory engine has no mirror setting and is unchanged: it never retracts.

Evidence

Test Covers
patch_mirror::a_bun_pin_on_the_patch_server_is_named_and_not_called_unpatched #2279 for bun.lock and bun.lockb, through the binary against two loopback servers: skipped / redirect_unconfirmed, the mirror warning with the right remedy per file, no UNPATCHED warning, lock bytes unchanged
patch_mirror::a_bun_pin_left_beside_a_copy_moved_to_the_mirror_is_named the earlier pin is still named when a registry copy is pinned on the mirror
patch_mirror::a_bun_pin_on_a_host_the_run_does_not_know_stays_a_user_tarball a pin on a host that is no patch server of the run keeps the user-tarball warning and gets no mirror warning
redirect::tests::bun_lock_pin_of_the_same_patch_on_another_host_is_recorded, redirect::bun_binary::tests::a_pin_of_the_same_patch_on_another_host_is_recorded what the rewriters record, and that another patch's URL or a plain user tarball is not recorded

The first commit adds the tests failing on main (the CLI test at the UNPATCHED assertion); the later commits turn them green.

Run locally (Linux, Bun 1.4.4):

  • cargo test -p socket-patch-core --lib: 8643 passed.
  • cargo test -p socket-patch-cli --lib: 1076 passed.
  • cargo test -p socket-patch-cli --test patch_mirror (8), e2e_bun_lockb (16), e2e_redirect_bun_build (8), mode_migration_bun (5), hosted_memory_parity (47): all passed.
  • cargo test -p socket-patch-cli --test in_process_redirect: 135 passed, 3 failed (partial_lockfile_write_failure_exits_1_and_writes_no_ledger, redirect_json_mode_write_failures_emit_error_envelope, vlt::scan_redirect_vlt_heal_invalidation_failure_warns). They make a directory read-only and expect a write to fail; the sandbox runs as root, where it doesn't. They fail the same way without this change.
  • cargo clippy --locked --workspace --all-features -- -D warnings (CI's command): clean. With --all-targets the pinned toolchain reports lints in test code this PR does not touch.

Not run: a real bun install against a mirror. No install behaviour changes; the lock bytes are asserted unchanged.

Review findings not fixed here

/code-review high ran twice. Its first pass found that recognising the pin inside the rewriters trusted any host and hid a pin left beside a moved copy; the design above is the answer to both. Left as they are, each narrower than this issue:

  • A patch republished since the pin (new uuid). The pin is matched by the uuid of the patch being pinned, as the existing text lookup matches it, so a pin of the superseded uuid keeps the user-tarball warning. Matching by package and version on a vetted host would be a wider rule than this fix needs.
  • A package the rewriters skip before they read its entries (bun patch, a default-trusted package, a grant without sha512) in a bun.lockb: nothing is recorded, so the mirror warning is not given. The run's warning for that skip says why the package was not handled. A text bun.lock still gets the mirror warning through the text lookup.
  • Default trust under a mirror: a patch-server pin does not count as "already pinned" for a default-trusted package, so a new registry copy beside it is not wired. Same before this PR.
  • In-run --vex in the mixed case: when the run pins one copy on the mirror and leaves the earlier pin, the package is not assumed patched and is checked against the installed copy. Conservative on purpose; the contract now says so.
  • Vetted hosts are the origins the run's grants name plus Socket's patch server, as the existing lookup has it. A --patch-server-url origin the grants do not name is not among them.

Follow-ups

  • The unconfigured-host guard (redirect_pin_on_unconfigured_host) reads text files only, so it does not see a pin in bun.lockb either. Not part of this report.

https://claude.ai/code/session_011f9aeP58fnWA8aUQYCinka


Generated by Claude Code

Refs #2279.

Assisted-by: Claude Code:claude-fable-5-2
A Bun project pinned on the patch server, then a hosted run with a
patch mirror: the pin is called a user tarball that stays UNPATCHED,
and for bun.lockb no redirect_mirror_pin_not_moved warning is given.

Refs #2279.

Assisted-by: Claude Code:claude-fable-5-2
A hosted run that writes a patch mirror met the pin an earlier run
wrote on the patch server as a URL it does not own. Both Bun rewriters
took it for a user's tarball: they warned that the copy stays
UNPATCHED and kept the patch out of the in-run VEX. They now leave a
URL in the patch server's path shape that names the patch's own uuid
alone without that warning.

The redirect_mirror_pin_not_moved lookup read the project's text
files only, so it never saw a pin in a binary bun.lockb. The rewrite
now reports the URLs the lock's records resolved from, and the warning
reads them. rollback refuses a bun.lockb pin, so the remedy named for
that file is the lock as it was before the pin.

Fixes #2279.

Assisted-by: Claude Code:claude-fable-5-2
Review of the first fix: recognising a patch-server pin inside the
rewriters trusted any host, since they know no host but the one they
write, and it hid a pin left beside a copy the run moved to the mirror.

The rewriters now treat such an entry as before (a user's tarball,
kept out of the in-run VEX) and record it. The scan, which knows the
run's patch servers, retracts the user-tarball warning for a recorded
pin on one of them and gives redirect_mirror_pin_not_moved in its
place, also when another copy of the package was pinned on the mirror.
A pin on a host the run does not know stays a user's tarball.

Refs #2279.

Assisted-by: Claude Code:claude-fable-5-2
The contract's table row said the patch is always skipped. For Bun the
warning is also given when another copy was pinned on the mirror, and
the run's own VEX then checks the installed copy.

Refs #2279.

Assisted-by: Claude Code:claude-fable-5-2
@mikolalysenko
Mikola Lysenko (mikolalysenko) marked this pull request as ready for review November 26, 2026 14:23
@mikolalysenko

Copy link
Copy Markdown
Collaborator Author

[agent] bugbot run


Generated by Claude Code

@cursor

cursor Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

PR Summary

Low Risk
Warning-only change for hosted scan with patch mirror; no lockfile rewrite behavior change beyond retracting incorrect Bun warnings.

Overview
Fixes #2279: when a hosted scan uses --patch-mirror-url and a Bun lock (bun.lock or bun.lockb) still points at the patch server, the run no longer mislabels that entry as an unpatched user tarball.

Bun rewriters now record patch-shaped URL entries in RewriteResult::bun_patch_shaped_pins. Hosted mirror logic in mirror_pins_not_moved retracts redirect_bun_non_registry_entry_skipped for pins on patch servers the run knows about, and emits redirect_mirror_pin_not_moved instead—including for binary bun.lockb, with a VCS restore remedy where rollback does not apply. Pins on unknown hosts keep the old user-tarball warning. CLI contract and integration tests document and lock this behavior; lock bytes are unchanged.

Reviewed by Cursor Bugbot for commit 58de703. Configure here.

@mikolalysenko

Copy link
Copy Markdown
Collaborator Author

bugbot run


Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Hosted Bun run with --patch-mirror-url gives no redirect_mirror_pin_not_moved for a bun.lockb pin and says an earlier patch-server pin "stays UNPATCHED"

2 participants