Repository navigation
Description
[agent] Found by the architecture refactor routine on main at 1b3f422, with real Go 1.24.7.
The problem
An agent-mode scan of a Go project offers a patch for every module version its crawl finds in the module cache, and the cache belongs to the machine, not the project. Only when it applies each patch does it ask whether the build selects that version. A version the build does not select is then a failed patch: the scan exits 1, and the patch is recorded in .socket/manifest.json all the same. Two everyday projects get there.
A Go workspace. With a go.work in effect the crawl walks the whole module cache (go_sum_scope, core crawlers/go_crawler.rs, lines 295 to 298). On a developer's machine that is every module of every project built there. For a workspace whose one member requires github.com/pkg/errors v0.9.1, on a machine whose cache also holds errors v0.8.1 and github.com/rs/zerolog v1.26.1:
- The scan says "Found 3 packages" and sends all three to the patch API, the two other projects' modules by name.
- It patches v0.9.1, fails the other two, prints "Applied 1 of 3 patches: 2 failed" and "2 vulnerabilities left to patch (67%)", and exits 1.
- The manifest holds three records. Committed, as the scan's summary invites, they make
socket-patch applyexit 1 on a fresh clone ("None of the 2 targeted manifest patches matched an installed package") andapply --checkexit 1. - Every later scan there exits 1 again, with or without
--prune: the crawl still finds the two modules, so the prune keeps their records. scan --mode hosted --dry-runandscan --mode vendored --dry-runfind the same three ("Would download and vendor 3 patches").
The same module with no go.work beside it: "Found 1 package", exit 0, one record, one purl sent.
A go get upgrade before go mod tidy. In module mode the crawl goes by the zip lines of go.sum, and go get github.com/pkg/errors@v0.9.1 leaves v0.8.1's line there until the next go mod tidy. The developer's cache still holds v0.8.1, so:
- The scan says "Found 2 packages", patches v0.9.1, fails v0.8.1 ("the build selects github.com/pkg/errors v0.9.1, not the patched v0.8.1 […] (get a patch for v0.9.1, or require v0.8.1)") and exits 1, with both recorded.
apply --checkthen exits 1 in every checkout and says "Runsocket-patch applyto regenerate them". On a fresh cloneapplyexits 0 with "1 manifest patch targets a package not installed on this host […] skipped", so the two commands disagree and the advice changes nothing.- The record outlives the cause: after
go mod tidya second scan still exits 1 ("Applied 0 of 2 patches: 1 already patched, 1 failed").scan --prunedrops the record only oncego.sumno longer lists the version, and the refusal does not name it.socket-patch removeof the record exits 0 and takes the live v0.9.1replaceout ofgo.mod(removeandrollbackof a Go patch delete thereplaceof the same module at another version: after an upgrade, removing the old record exits 0 and the build links the unpatched module #2414).
The scan has the answer before it downloads anything. The question it asks at apply time (selection_refusal, core patch/redirect/golang_local.rs, line 855) reads go.mod, go.sum, go.work and the module cache, and its two refusals here are exactly "the build selects another version" and "not in this project's build graph".
The same class was fixed for the plain module in c52bb9b (#1207, "Scope the project-mode Go crawl to the modules go.sum records"), whose issue names the harm: "scan reports (and sends to the API, and agent apply sees) every module version any project on the machine downloaded". That change kept the walk for workspaces, "their build list spans other modules' go.sum and go.work.sum". The workspace's module graph reader came 19 days later (68d2a49, #1751), and the crawl was not moved onto it.
Evidence
A stand-in patch API serves one patch each for errors v0.8.1, errors v0.9.1 and zerolog v1.26.1, and logs each request. The patched errors.New("x").Error() returns PATCHED-<version> x. The binary is built from main. The developer's module cache holds the three modules; "CI" is a fresh clone with a module cache of its own.
The workspace
$ cat go.work
go 1.22
use ./app
$ grep require app/go.mod
require github.com/pkg/errors v0.9.1
$ socket-patch scan --mode agent --yes -e golang # exit 1
Found 3 packages (3 go)
Error: Failed to patch pkg:golang/github.com/pkg/errors@v0.8.1: the build selects github.com/pkg/errors v0.9.1, not the patched v0.8.1: a replace pinned to v0.8.1 would be ignored and the build would link the unpatched module; nothing written (get a patch for v0.9.1, or require v0.8.1)
Error: Failed to patch pkg:golang/github.com/rs/zerolog@v1.26.1: github.com/rs/zerolog v1.26.1 is not in this project's build graph (no go.mod of the build requires it and no go.sum has a zip line for it): its replace would be ignored; nothing written
Applied 1 of 3 patches: 2 failed.
Error: Some patches could not be applied.
HIGH github.com/pkg/errors@v0.9.1 CVE-2026-1002
Patched 1 package, fixing 1 vulnerability (1 high).
2 vulnerabilities left to patch (67%): 2 are in packages this run did not patch.
The request the stand-in logged for that run:
POST /patch/batch {"components":[{"purl":"pkg:golang/github.com/rs/zerolog@v1.26.1"},{"purl":"pkg:golang/github.com/pkg/errors@v0.8.1"},{"purl":"pkg:golang/github.com/pkg/errors@v0.9.1"}]}
The manifest then holds errors@v0.8.1, errors@v0.9.1 and zerolog@v1.26.1. The same run from app/ gives the same output. After a commit of .socket/ and go.work, in CI:
$ socket-patch apply # exit 1
Error: None of the 2 targeted manifest patches matched an installed package:
- pkg:golang/github.com/pkg/errors@v0.8.1
- pkg:golang/github.com/rs/zerolog@v1.26.1
Check that the packages are installed and --cwd points to the right directory.
[…]
Summary: 0 of 3 targeted patches applied, 1 already patched, 2 not found on disk
$ socket-patch apply --check # exit 1
Error: Patches are OUT OF SYNC:
[…]
missing go.mod `replace` for pkg:golang/github.com/rs/zerolog@v1.26.1
missing patched copy for pkg:golang/github.com/rs/zerolog@v1.26.1
Run `socket-patch apply` to regenerate them.
$ (cd app && go run .)
PATCHED-v0.9.1 x
The control, app/ copied out of the workspace, on the same machine:
$ socket-patch scan --mode agent --yes -e golang # exit 0
Found 1 package (1 go)
Applied 1 patch.
It sends one purl and records one patch.
The upgrade
$ go get github.com/pkg/errors@v0.9.1
go: upgraded github.com/pkg/errors v0.8.1 => v0.9.1
$ grep -c 'errors v0.8.1 h1:' go.sum
1
$ socket-patch scan --mode agent --yes -e golang # exit 1
Found 2 packages (2 go)
Error: Failed to patch pkg:golang/github.com/pkg/errors@v0.8.1: the build selects github.com/pkg/errors v0.9.1, not the patched v0.8.1: […]
Applied 1 of 2 patches: 1 failed.
Error: Some patches could not be applied.
| Where | Command | Outcome |
|---|---|---|
| the developer's machine | apply --check |
exit 1, "Run socket-patch apply to regenerate them" |
| the same | scan --mode agent --yes --prune, twice |
exit 1 both times; both records stay |
the same, after go mod tidy |
scan --mode agent --yes |
exit 1, "Applied 0 of 2 patches: 1 already patched, 1 failed"; both records stay |
| CI | apply |
exit 0, "1 manifest patch targets a package not installed on this host […] skipped" |
| CI | apply --check |
exit 1, the same three lines about v0.8.1 |
| CI | vex |
exit 0, one statement, v0.8.1 omitted as not installed |
The control: go mod tidy before the first scan. "Found 1 package", exit 0.
Planned fix
One rule: a scan offers a Go module only where the build list holds it.
- The workspace crawl is scoped as the module one is: the zip lines of each member's
go.sumand ofgo.work.sum, and each member's requires. Those are the files the comment ongo_sum_scopenames. The walk stays for--globaland--global-prefix. - Before the scan selects a crawled module it asks the question
applyasks. A version the build does not select, or a module outside its graph, is a calm skip: no download, no record, no failure.getalready has this rule for the versions of an advisory ("Installed-version narrowing",CLI_CONTRACT.md, line 539: "never an error exit"). A patch named by purl or uuid, and one already in the manifest, keep today's refusal. - A recorded patch that the build no longer selects gets a remedy that works. Today's text, "get a patch for v0.9.1, or require v0.8.1", is printed by the run that has just applied the v0.9.1 patch.
The second point turns the exit code of such a scan from 1 to 0. The narrowing rule and #1207's first acceptance criterion ("A project with a go.sum crawls only the modules it records") both point that way; a maintainer who wants the refusal kept visible can have it as a skipped event.
Related: #2414 (the undo of such a record), #2412 (the same question answered wrongly under an exclude), #595 and #1207.
Not run: a wet hosted or vendored scan in the workspace (the stand-in serves no artifact; the dry runs above list the three modules), GOFLAGS=-modfile, where an earlier run of this routine saw the whole cache read as well, Go releases other than 1.24.7, and Windows.
Generated by Claude Code
Activity
refactor: #2412, #2413 and #2414 filed; Go ran
mikolalysenko commentedon Dec 2, 2026
[agent] Claiming this for the architecture refactor routine. Branch: arch-refactor/2413-go-workspace-crawl-scope.
The first slice is the workspace half: the crawl of a project with a
go.workin effect is scoped to the sum files go reads for it, as the plain module's crawl is. Confirmed again onmainat 0a1709b with real Go 1.24.7: the scan of a one-member workspace says "Found 3 packages" and sends two other projects' modules to the patch API, and the same module outside the workspace says "Found 1 package".Generated by Claude Code
Scope a Go workspace's crawl to its sum files
Keep a Socket-replaced module in the crawl
Test what a workspace scan asks the patch API
Fix two inputs the scoped Go crawl misjudged
Ask the module graph where the sum files end
Read the module graph for every workspace
Take back the member exemption; three small rules
Keep a replaced module the files cannot place
mikolalysenko commentedon Dec 2, 2026
[agent] #2431 is ready for review. It is the workspace half of this issue, and a little more.
In #2431: with a
go.workin effect the crawl is scoped to what the workspace builds (each member'sgo.sumand requires, the workspace's sum file, and the versions its module graph selects), as a plain module's is. On the layouts above, run again onmainat 0a1709b with real Go 1.24.7, the scan of the one-member workspace finds 1 package wheremainfinds the whole cache, names no other project's module to the patch API, and exits 0.Still open here: a version the build does not select is offered, then refused. Both spellings fail on that branch as they do on
main:go getupgrade leaves ingo.sumuntilgo mod tidy(the second half of this issue as written);The fix is this issue's second planned point: the scan asks the question
applyasks before it selects a crawled module. I left it out of #2431 for two reasons. It turns an exit 1 into an exit 0 for a caseCLI_CONTRACT.mddoes not settle (the narrowing rule this issue cites isget's), so a maintainer may want it as askippedevent instead of silence. And it belongs in the scan's selection, in CLIcommands/scan/mod.rs, which an open agent PR edits.Found on the way, for
main, and fixed in #2431: in a go 1.16 module, a patched module that only a dependency requires loses itsgo.sumzip line at the nextgo mod tidy. The nextscan --syncthen prints "GC: pruned 1 manifest entry" for a patch the build still links, andapply --checkexits 1 over an orphanreplace.Found on the way, not fixed: go names a workspace's sum file after the work file (
GOWORK=/x/ci.workwritesci.work.sum; run with go 1.24.7). The workspace loader readsgo.work.sumwhatever the file is called (corevendor/go_workspace.rs,load_file). #2431 reads the right file in the crawler only; I have not run what the loader's other readers do under such aGOWORK.The claim on this issue covers #2431 only.
Generated by Claude Code
Bound an unlisted member by the module graph
refactor: #2431 opened for #2413's first point, ready with CI green