Skip to content

On a vendored npm project, scan --mode agent says the vendored patches are "left to patch" while a bare scan of the same project says "Nothing left to patch" #2304

Backlog

Description

[agent] Found by the scheduled npm bug-hunt routine (ledger #302).

Summary

Regression since v5.1.0 (the closing totals are new on main; v5.1.0 prints none). On a vendored npm project, socket-patch scan --mode agent skips each vendored package as vendored and then ends with "1 vulnerability left to patch: 1 is in packages this run did not patch." The package is patched: its committed vendored tarball installs, and vex attests it. A bare scan on the same unchanged project says "Nothing left to patch." The two runs contradict each other.

The run also prints "No patches selected.", though the patch was selected. The vendored ledger kept it from being applied in place.

Impact

Someone trying agent mode on a vendored project (or a CI job pinned to --mode agent in a repo a teammate vendored) is told that patches are missing when they are in place. The only remedy the output suggests is "Read the run's output for that package" (docs/usage.md), and that output just says to run scan --mode vendored. Exit code is 0, so installs and CI aren't broken. This is a reporting bug, not a do-no-harm one.

Repro (npm 12.2.3, Node 22, Linux)

A local mock of the patch API serves one free patch for left-pad@1.3.0 (batch, by-package, view with inline blobContent, blob). $API is --api-url <mock> --org o --api-token fake.

mkdir va && cd va
echo '{"name":"va","version":"1.0.0","private":true,"dependencies":{"left-pad":"1.3.0"}}' > package.json
npm install
socket-patch scan --mode vendored --yes $API      # exit 0, Vendored 1 package
npm ci                                            # installs the patched bytes
socket-patch vex --product pkg:npm/va@1.0.0 $API -O v.json   # exit 0, attests it
socket-patch scan --mode agent --yes $API
socket-patch scan --yes $API                      # mode from state: vendored

Actual

$ socket-patch scan --mode agent --yes ...
Found 1 package (1 npm)
  [skip] pkg:npm/left-pad@1.3.0 (vendored; run `socket-patch scan --mode vendored` to update it)
No patches selected.

1 vulnerability left to patch: 1 is in packages this run did not patch.
(exit 0; --json: events [skipped/vendored], status success)

$ socket-patch scan --yes ...
Patched 1 package, fixing 1 vulnerability.
Saved about 2 hours of engineering time (1 package upgrade at ~2 hours).
Nothing left to patch.

Expected

The vendored package is a patch in place, like an already_patched skip, and like the vendored skip PR #2274 adds for gems ("The closing lines of scan count the skip as a patch in place, like already_vendored"). The closing lines should count it as patched ("Nothing left to patch."), matching the bare scan, vex and apply --check on the same project. CLI_CONTRACT.md ("Left to patch counts the advisories of every package a patch was offered for that this run did not fix") and the docs/usage.md reason table describe a package the run left unpatched, not one that already holds the patch.

The other mode switches I tried count correctly:

  • scan --mode agent on a hosted project: "Applied 0 of 1 patch: 1 already patched", then "Nothing left to patch."
  • scan --mode vendored on an agent project: "Nothing left to patch."

Versions

Build npm Result
main cfc870f 12.2.3 reproduces (twice, fresh dirs)
v5.1.0 12.2.3 no totals line at all (same [skip] + "No patches selected.")

First bad commit: the closing-totals report first appears in 412796fb (#2180), and 66fe4841 (#2220) reworked it. Not bisected further. Nothing here is specific to Linux or to the npm major. It should reproduce for any ecosystem whose agent apply returns the vendored-ownership skip.

Suspect code

  • crates/socket-patch-cli/src/commands/scan/mod.rs:811: patched_uuids counts only Applied and skips that skip_leaves_patched accepts.
  • crates/socket-patch-cli/src/json_envelope.rs:765: skip_leaves_patched admits already_patched and not_in_platform_build, not the vendored skip that crates/socket-patch-cli/src/commands/apply.rs:1263 emits for a ledger-owned package. (Treating it as patched should probably first check that the installed copy holds the vendored bytes, the way Fix vendored re-scan of a gem patched in another mode (#2269) #2274 does for gems.)

Generated by Claude Code

Activity

  1. added
    bug
    bughunt
    on Nov 27, 2026
  2. mikolalysenko commented on Nov 29, 2026

    @mikolalysenko
    CollaboratorAuthor

    [agent] From the scheduled pip / requirements.txt bug-hunt routine (ledger #309): the same miscount also shows up in PyPI hosted mode, not just npm agent mode, so the fix probably belongs in the shared closing totals and not in an npm path.

    Repro on main cfc870f (Linux, pip 26.3 / CPython 3.12, local mock of the patch API serving free patches for idna@3.7 and six@1.16.0). It reproduced on 2 of 2 runs, with and without --patch-mirror-url:

    printf -- '-r base.txt\nidna==3.7\n' > requirements.txt
    printf 'six==1.16.0\n' > base.txt
    socket-patch scan --mode vendored     # both vendored; six is wired in base.txt
    socket-patch scan --mode hosted       # idna moves to hosted; six stays vendored (redirect_requirements_takeover_unreachable, documented)
    Skipped pkg:pypi/six@1.16.0: hosted mode cannot pin it where vendored mode wired it, so it stays vendored (see the warning)
    Patched 1 package, fixing 1 vulnerability (1 high).
    1 vulnerability left to patch (50%): 1 is in packages this run did not patch.
    

    six is still patched: vendor --check reports "committed artifact and wiring verified", a fresh pip install -r requirements.txt installs the patched wheel, and vex attests both packages. So the totals count a package that stays vendored, and is patched, as "left to patch". The exit code is 0.


    Generated by Claude Code

  3. mikolalysenko commented on Nov 30, 2026

    @mikolalysenko
    CollaboratorAuthor

    [agent] From the scheduled npm bug-hunt routine (ledger #302). There's one more way to hit the same miscount: a scan --prune with no --mode on a vendored project. The contract says a mode-less --prune only reports (CLI_CONTRACT.md, --mode row), but its closing line counts the vendored package as unpatched.

    Repro on main cfc870f (Linux, npm 12.2.3, local mock of the patch API). Vendor left-pad@1.3.0 and is-number@7.0.0, then run npm uninstall is-number:

    $ socket-patch scan --prune --yes
    Found 1 package (1 npm)
      [skip] pkg:npm/left-pad@1.3.0 (vendored; run `socket-patch scan --mode vendored` to update it)
    No patches selected.
    GC: reverted 1 vendored entry; swept 0 orphan vendor dirs.
    
    1 vulnerability left to patch: 1 is in packages this run did not patch.
    $ socket-patch scan --yes          # same project, straight after
    ...
    Nothing left to patch.
    

    --prune --dry-run says "1 vulnerability would be left to patch". The GC itself is right: it reverts the is-number entry, removes its artifact and restores its lock entry. --json reports nothing as left to patch. Only the human closing totals are wrong, so fixing skip_leaves_patched for the vendored skip should cover this case too.


    Generated by Claude Code

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent:triagedbugbughuntpm:npmpriority:p1

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions