Repository navigation
Description
[agent] Found by the architecture refactor routine beside #2327, on main at cfc870f with the binary built from it. Low priority: what is left behind is unused. The registry route is on main and not in a release yet.
Problem
CLI_CONTRACT.md (line 344, Which commands clean up, and when) says an unused entry of hosted mode's pnpm registry route "is removed by (1) every scan --mode hosted, with no extra flag, as part of its rewrite, also when the scan selects no patch or crawls no package at all", and that "Human mode prints Removed N pnpm registry entries that no lockfile uses any more: (Would remove … on a dry run) and one line per entry."
A hosted scan that finds no patch does that only under --json. Without --json the same scan over the same project removes nothing and prints nothing about the entries. With --prune it prints a warning that says a hosted scan "already removes the pnpm registry entries no lockfile uses any more on every run", and then leaves them.
So what a hosted scan writes depends on its output mode. The harm is small: the entries are unused, and repair removes them.
Evidence
A pnpm project with no hosted pin and one leftover of a route in pnpm-workspace.yaml (a package that left the lock), and a patch API that offers nothing. The project's files are project/ of the several case of crates/socket-patch-core/tests/fixtures/pnpm-registry-overrides/. SOCKET_PATCH_SERVER_URL=https://patch.test is set.
$ cat pnpm-workspace.yaml
packages:
- 'apps/*'
namedRegistries:
socket-55555555: https://patch.test/patch/npm/gone/1.0.0/22222222-2222-4222-8222-222222222222/55555555-5555-4555-8555-555555555555/
overrides:
'gone@1.0.0': 'socket-55555555:1.0.0'
$ socket-patch scan --mode hosted # exit 0; pnpm-workspace.yaml unchanged
Found 5 packages (5 npm)
No patches available for installed packages.
$ socket-patch scan --mode hosted --prune # exit 0; pnpm-workspace.yaml unchanged
Warning: --prune sweeps no `.socket/` state with --mode hosted (run `scan --mode agent --prune` or `scan --mode vendored --prune` to garbage-collect that); a hosted scan keeps its state in the lockfiles and already removes the pnpm registry entries no lockfile uses any more on every run
Found 5 packages (5 npm)
No patches available for installed packages.
$ socket-patch scan --mode hosted --json # exit 0; pnpm-workspace.yaml is now "packages:\n - 'apps/*'\n"
{"action": "removed", "errorCode": "registry_entry_unused", "details": {"mode": "hosted", "file": "pnpm-workspace.yaml", "entry": "registry", "key": "socket-55555555"}}
{"action": "removed", "errorCode": "registry_entry_unused", "details": {"mode": "hosted", "file": "pnpm-workspace.yaml", "entry": "override", "key": "gone@1.0.0", "value": "socket-55555555:1.0.0"}}
Each run starts from the same files. The human runs show stderr and stdout together; the JSON lines are the two registry_entry_unused events of the envelope, with the fields this is about. The dry runs differ the same way: scan --mode hosted --dry-run prints only No patches available for installed packages., and scan --mode hosted --dry-run --json holds the two events as verified. --silent behaves as human mode does: nothing is removed. repair removes both entries in either output mode.
The cause is an early return of the human path (CLI commands/scan/mod.rs, lines 3949 to 3961, "Every mode stops on an empty discovery"): it prints the line and returns before the hosted rewrite. The JSON path goes on into commands/scan/hosted.rs, whose comment at lines 1639 to 1642 states the rule ("a pnpm project an earlier run routed through the patch server's named registries is tidied even when this run selects no patch") and whose code at line 1652 does it (route_cleanup = candidates.is_empty() && route_present).
Not checked: a scan that crawls no package at all in human mode, and the Maven .mvn/maven.config respelling, which the same block of hosted.rs does for a run that redirects nothing and which the same early return would skip.
Planned fix
The human path's empty-discovery exit runs the same tidying the JSON path runs for a hosted scan (the route cleanup, under the apply lock when it can be had), and prints the contract's Removed N pnpm registry entries … lines. One CLI test runs the scan both ways over a project with a leftover entry and compares the files.
The contract settles the behavior, so this is not a decision issue. The routine has three PRs open and awaiting review, so no PR is opened for this yet.
Generated by Claude Code
Activity
refactor: #2327 and #2328 filed; the addon, env spellings and the pnp…