Skip to content

scan closes with "Nothing left to patch." after a batch of the lookup failed: 5 of 40 packages were never checked, exit 0, and the next run patches all five #2537

Backlog

Description

[agent] Found by the architecture refactor routine on main at cd7c5c5, with a stand-in patch API on loopback.

Problem

scan asks the patch service about the project's packages in batches (--batch-size: 500 by default, 100 without a token). When one batch fails and the others are answered, the run goes on with the answered ones, prints Warning: API batch <n> of <total> failed: … on stderr and exits 0. That part is what CLI_CONTRACT.md describes.

The run then closes with Nothing left to patch. The packages of the failed batch were never checked, so the run does not know that. In the run below, 5 of 40 packages were in the failed batch, each has a patch, and the next run against a healthy service patches all five.

The same line closes a token-less run whose per-package lookups left some packages unanswered (No free patches left to apply., exit 1), and a --dry-run (Nothing left to patch. under Would patch …).

Who it hurts: anyone who reads the last line of a scan, in a terminal or a CI log. The warning is one stderr line above the list of patched packages; the summary under the list contradicts it. It takes a project large enough for two batches and one request that fails: a throttled request that used up its retries, a dropped connection, a 5xx.

--json is not affected: it has no such line, and it carries the api_batch_failed warning.

Where

The closing lines already weaken this sentence for one kind of partial knowledge, a lookup on the public proxy, and say why ("the line claims no more than the lookup saw"):

if left == 0 {
// The public proxy answers for free patches only: what a paid
// plan would fix is unknown there, so the line claims no more than
// the lookup saw.
let nothing = if counts.free_only {
"No free patches left to apply."
} else {
"Nothing left to patch."
};
lines.push(plain(nothing.to_string()));

The scan knows the lookup was incomplete:

// A package the lookup missed could have been NEW, like one in a
// failed batch.
let lookup_incomplete = batch_error_count > 0 || !unanswered.is_empty();

It applies the rule to the result line of a scan that found no patch at all:

if all_packages_with_patches.is_empty() {
if !silent {
// Only a lookup the service answered in full may say it of
// every installed package.
if lookup_incomplete {
println!("{}", render::NO_PATCHES_AMONG_CHECKED);
} else {
println!("No patches available for installed packages.");
}
}
return finish_human(0).await;

The report is told about the proxy (saw_free_patches_only) and is never told about an incomplete lookup, so closing cannot apply the rule:

/// A project directory's lookup ran on the public proxy, which answers
/// for free patches only: the closing lines then say "no free patches
/// left", never "nothing left".
pub(crate) fn saw_free_patches_only(&mut self) {
self.free_only = true;
}

CLI_CONTRACT.md states the rule under "No patches" needs an answer: "scan and get report that there is nothing to patch only when the patch service said so".

What the scan says

A project with 40 installed npm packages, each with one patch in the stand-in's catalog. --batch-size 5 makes eight batches; the stand-in answers one of them with a 500. The rows of patched packages are left out.

$ socket-patch scan --mode agent --yes --batch-size 5
Found 40 packages (40 npm)
Warning: API batch 7 of 8 failed: API request failed with status 500: stand-in failure
Applied 35 patches.
…
Patched 35 packages, fixing 35 vulnerabilities (35 high).
Saved about 70 hours of engineering time (35 package upgrades at ~2 hours each).
Nothing left to patch.
$ echo $?
0

The same command again, with the service healthy:

Patched 40 packages, fixing 40 vulnerabilities (40 high).
Saved about 80 hours of engineering time (40 package upgrades at ~2 hours each).
Nothing left to patch.
Run Exit Packages patched Closing line
scan --mode agent, one batch of eight fails 0 35 of 40 Nothing left to patch.
scan --mode hosted, the same 0 35 of 40 Nothing left to patch.
scan --mode vendored, the same 0 35 of 40 Nothing left to patch.
scan --mode agent --dry-run, the same 0 none (Would patch 35 packages) Nothing left to patch.
no token, one batch of eight fails 0 35 of 40 No free patches left to apply.
no token, a proxy without the batch route, one per-package lookup fails (Warning: 1 of 40 packages could not be checked for patches (pkg:npm/pkg-017@1.0.0): …) 1 39 of 40 No free patches left to apply.

The failed batch gives the same line for a 500, a 429 that outlasts its retries, a dropped connection and a response that is not the service's.

The failing test

Added beside batch_failure_warnings_print_in_chunk_order in crates/socket-patch-cli/tests/scan/scan_ordered_concurrency_e2e.rs, which already serves six one-package batches and fails two of them:

/// Two of six batches were never answered. The closing line may speak
/// only for the packages the service answered for.
#[tokio::test]
async fn probe_a_failed_batch_does_not_close_with_nothing_left() {
    let tmp = tempfile::tempdir().unwrap();
    write_project(tmp.path(), &NAMES);
    let order = crawl_order(tmp.path()).await;

    let auth = MockServer::start().await;
    for (pos, &idx) in order.iter().enumerate() {
        let status = if pos == 2 || pos == 4 { 500 } else { 200 };
        mount_batch_for(&auth, &auth_batch_route(), idx, AUTH, status, Duration::ZERO).await;
    }
    let all: Vec<usize> = (0..NAMES.len()).collect();
    mount_details(&auth, &all, &[], |_| Duration::ZERO).await;

    let (code, stdout, stderr) = run_scan(
        tmp.path(),
        &auth.uri(),
        &auth.uri(),
        &["--batch-size", "1", "--mode", "agent", "--dry-run"],
    );
    assert_eq!(code, 0, "stdout={stdout} stderr={stderr}");
    assert_eq!(stderr.matches("Warning: API batch").count(), 2, "{stderr}");
    assert!(
        !stdout.lines().any(|line| line == "Nothing left to patch."),
        "2 of 6 packages were never checked for patches, and the run closes with \
         \"Nothing left to patch.\":\n{stdout}"
    );
}

cargo test -p socket-patch-cli --test scan probe_a_failed_batch on main:

test scan_ordered_concurrency_e2e::probe_a_failed_batch_does_not_close_with_nothing_left ... FAILED

2 of 6 packages were never checked for patches, and the run closes with "Nothing left to patch.":
[dry-run] Would download and apply 4 patches. No changes made.
  HIGH  conc-alpha@1.0.0
  HIGH  conc-delta@1.0.0
  HIGH  conc-echo@1.0.0
  HIGH  conc-foxtrot@1.0.0

Would patch 4 packages.
Would save about 8 hours of engineering time (4 package upgrades at ~2 hours each).
Nothing left to patch.

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 276 filtered out

History

Planned fix

Tell the report, as the proxy case does. Tried on a build, about 30 lines in scan/report.rs and 3 in scan/mod.rs:

  • Run and Counts gain a flag beside free_only, set from lookup_incomplete where the scan sets saw_free_patches_only.
  • With the flag set and nothing counted as left, closing ends the sentence the way the no-patch line does: Nothing left to patch in the packages that could be checked; the others were not checked (see the warning above). (No free patches left to apply in the packages … on the proxy).

With that change the test above passes, the other 276 tests of the scan suite pass, and the six runs in the table close with the longer line; a run whose every lookup was answered reads as before.

The change is one human line. Exit codes, --json and files stay as they are. CLI_CONTRACT.md names the two closing sentences under "Human output conventions" and would gain the longer form.

This waits for a free slot: three of this routine's PRs are open.

Not run

  • A scan of several project directories where only one directory's lookup is incomplete. The flag in the trial is per run, like free_only.
  • get, which has no closing totals.
  • The line 18 vulnerabilities left to patch (32%): … after an incomplete lookup. It counts what the run knows, and the share is of the advisories it was told about; I left it alone.

Generated by Claude Code

Activity

  1. added
    bug
    arch-audit
    on Dec 6, 2026
  2. added a commit that references this issue on Dec 6, 2026
  3. mikolalysenko commented on Dec 6, 2026

    @mikolalysenko
    CollaboratorAuthor

    [agent] A related case for whoever fixes this, from the architecture refactor routine on main at cd7c5c5. The same closing lines also say too little: on a second scan they count a patch that is already in place as a vulnerability left to patch, when the request for that package's patch list or patch record fails. This is the safe direction, so I am not filing it separately. It reads the same lookup state as this issue, so one fix could word both.

    A project of 40 packages, all 40 patched by an earlier scan, scanned again with one patch-list request answered 500 (same stand-in as above, SOCKET_API_MAX_RETRIES=1):

    $ socket-patch scan --mode agent --yes --batch-size 5
    Found 40 packages (40 npm)
    Warning: could not fetch details for pkg:npm/pkg-017@1.0.0: API request failed with status 500: stand-in failure
    Applied 0 of 40 patches: 40 already patched.
    
    Patched 39 packages, fixing 39 vulnerabilities (39 high).
    Saved about 78 hours of engineering time (39 package upgrades at ~2 hours each).
    1 vulnerability left to patch (3%): 1 is in packages this run did not patch.
    $ echo $?
    0

    The third line and the last one disagree. pkg-017 holds the patched bytes, and the manifest records its patch at the uuid the service still offers.

    Second scan, one request failing for an already patched package Exit What is in place The run says
    --mode agent, the patch list 0 40 files patched, 40 records 40 already patched, then Patched 39 packages, 1 vulnerability left to patch (3%)
    --mode agent, the patch record (view) 1 the same [fail] pkg:npm/pkg-017@1.0.0 (…), then the same two lines; --json: partialFailure, one failed / download_failed event for the uuid the manifest already holds
    --mode hosted, the patch list 0 40 pins in package-lock.json 39 packages are already on hosted patches; nothing to rewrite., 1 vulnerability left to patch (3%)
    --mode vendored, the patch list 0 40 vendored copies All 39 packages are already vendored; nothing to do., 1 vulnerability left to patch (3%)

    Nothing is lost in any of these runs: every patched file, record, pin and vendored copy stays (95 such second scans across the three modes, with a batch, a patch list, a patch record, a package reference or an artifact failing).

    The count comes from Counts::of in scan/report.rs: a package the batch lookup offered a patch for counts whole as left ("in a package the run did not patch") unless a patch this run selected for it landed or was found in place. When the package's patch list or record could not be fetched, the run has no selected patch for it, so it is counted as left whatever is on disk.


    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:triagedarch-auditbugpriority:p3

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions