Repository navigation
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"):
socket-patch/crates/socket-patch-cli/src/commands/scan/report.rs
Lines 697 to 706 in cd7c5c5
| 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:
socket-patch/crates/socket-patch-cli/src/commands/scan/mod.rs
Lines 3619 to 3621 in cd7c5c5
| // 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:
socket-patch/crates/socket-patch-cli/src/commands/scan/mod.rs
Lines 4072 to 4082 in cd7c5c5
| 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:
socket-patch/crates/socket-patch-cli/src/commands/scan/report.rs
Lines 870 to 875 in cd7c5c5
| /// 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 $?
0The 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
- 354ab99 (Fix the defects found by the 5.1.0 full review: do no harm, Bundler hosted mode, VEX, monorepo scans #2052) added
lookup_incompleteand the lineNo patches found for the packages that could be checked; the others were not checked (see the warning above).for a scan that found no patch. - f62d1ca (Rework the terminal UI of scan, list, show, get, rollback and vex; faster startup and multi-project scans #2153), eight days later, added the closing lines. They read the proxy flag and nothing about an incomplete lookup.
- Scan totals say "Nothing left to patch." when a refused gem is locked as precompiled platform builds (nokogiri) #2181 and Vendored scan on a fresh checkout skips a gem locked only as platform gems (nokogiri) without a word and reports "Nothing left to patch", also after following the printed
--remove-platform rubyremedy #2394 reported this closing line saying "Nothing left to patch." of a gem the run had refused or skipped; 02add9b (Fix left-to-patch count of a platform-only gem (#2181) #2187) and 266306d (Fix vendored scan skipping a gem locked only as platform gems (#2394) #2447) fixed those two.
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:
RunandCountsgain a flag besidefree_only, set fromlookup_incompletewhere the scan setssaw_free_patches_only.- With the flag set and nothing counted as left,
closingends 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
refactor: L283 to L288; #2537 filed (closing line)
mikolalysenko commentedon Dec 6, 2026
[agent] A related case for whoever fixes this, from the architecture refactor routine on
mainat 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):The third line and the last one disagree.
pkg-017holds the patched bytes, and the manifest records its patch at the uuid the service still offers.--mode agent, the patch list40 already patched, thenPatched 39 packages,1 vulnerability left to patch (3%)--mode agent, the patch record (view)[fail] pkg:npm/pkg-017@1.0.0 (…), then the same two lines;--json:partialFailure, onefailed/download_failedevent for the uuid the manifest already holds--mode hosted, the patch listpackage-lock.json39 packages are already on hosted patches; nothing to rewrite.,1 vulnerability left to patch (3%)--mode vendored, the patch listAll 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::ofinscan/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
refactor: L295 to L298; L296 on #2537 (re-scans)