Repository navigation
Scope a Go workspace's scan to the modules it builds, not the machine's module cache - #2431
Conversation
Refs #2413. Assisted-by: Claude Code
With a go.work in effect the project crawl walked the whole module cache, so a scan reported every module any project on the machine had downloaded, sent them to the patch API by name and offered each a patch. The ones the workspace does not build failed at apply time, the scan exited 1, and their records stayed in the manifest. The crawl of a workspace is now scoped as a module's is: to the zip lines of the sum files go reads for it (each use member's go.sum and go.work.sum) and the requires of each member, read through the workspace loader hosted and vendored modes use. The walk stays for --global and --global-prefix, and where go refuses the workspace or one of its files cannot be read. Refs #2413. Assisted-by: Claude Code
go records no zip line for a version a replace takes over, and keeps no member's go.mod tidy in a workspace. A patched module that only a dependency requires was therefore in the scoped crawl only until go.work.sum was written again: the next scan no longer saw it, and a pruning scan dropped the record of a patch the build still links. The scope now adds each version a Socket replace of go.work or of a member names, while the workspace's module graph selects that version or cannot say, which is the answer apply goes by. A module the build dropped or moved past is left out, so its record is pruned as before. Refs #2413. Assisted-by: Claude Code
Runs the binary over a module with real go: on its own, as the one member of a workspace, and under a go.work above it, with another project's module in the same module cache. Each scan names the one module the build links to the patch API. Refs #2413. Assisted-by: Claude Code
Review of the workspace scope found two. go names a workspace's sum file after the work file, so under GOWORK=/x/ci.work it reads and writes ci.work.sum. The scope read go.work.sum in that directory whatever the file was called, and so missed the modules only that file records. The rule that keeps a Socket-replaced module in the crawl ran for a workspace alone. A module with an unpruned go.mod (go 1.16 or older) has the same gap, and had it before this branch: go mod tidy drops the zip line of a replaced module that only a dependency requires, the next scan no longer sees it, and a pruning scan drops the record of a patch the build still links. Both modes now ask the question apply asks of each version a Socket replace names. Refs #2413. Assisted-by: Claude Code
A second review pass found the scope still short in one state and still walking in another. A workspace with no sum file (go writes it at the first build that needs it, and git often ignores it) can link a version a dependency raised past every member's require. No member's go.sum lists that version, so the scoped crawl missed it. The scope now adds the versions the workspace's module graph selects, and keeps the walk when a go.mod the graph needs is not in the module cache. A module under a go.work that does not use it still walked the whole cache. go refuses to build it there; it is now scoped to its own go.mod and go.sum, which are what GOWORK=off builds. The workspace's graph is read once for both this and the replaced modules, and the module-mode answer is the half of project_selection that module mode already used, under its own name. Refs #2413. Assisted-by: Claude Code
A third review pass found two more states where the scope fell short. A sum file that is there but behind (written before a dependency raised a module) was trusted as the whole record, so the raised version was missed. The versions the workspace's module graph selects are now added whether or not the sum file is there; the walk is kept only when there is no sum file and the graph is not whole. Members that require each other read as a graph with a hole: go builds the required member from its directory and never downloads its go.mod, so the lookup in the module cache failed, and a workspace with no sum file kept walking. A requirement on a use member now counts as read. The sum file's lines join the scope before the replaced modules are looked for, and an unreadable sum file returns before the graph is read. Refs #2413. Assisted-by: Claude Code
A fourth review pass ran the last change against real go and found it wrong. go 1.24.7 does look up the go.mod of the version one member requires of another, and that go.mod takes part in version selection: the build fails when it is not there. So a requirement on a use member is no longer counted as read. With the directory replace go needs for an unpublished member, the graph reads the member's own go.mod and is whole without any exemption; the test now models that layout. A use member is left out of the scope: go builds it from its directory, so a copy of it in the cache (a GOWORK=off build's) is not this build's, and a patch offered for it would be refused. A go.work that uses no module keeps the walk, as every other workspace go refuses does. It scoped the crawl to nothing, and a pruning scan would have dropped every Go record. Refs #2413. Assisted-by: Claude Code
A fifth review pass found three things. A Socket-replaced version stayed in the scope only when the build selected it or the answer was unknown. An unpruned go.mod with a leftover zip line and a module graph the cache cannot complete gives a third answer, that nothing shows which version is built. The module was dropped there, and a pruning scan would have dropped its record. It now stays: only a definite answer that it is not built drops it. With a sum file the graph added every module any loaded go.mod requires, a dependency's test-only requirements among them. A sum file lists what the build links, so the graph now only corrects the version of a module the files name. With no sum file the build list is still the bound. The members' module paths are read once to leave them out of the scope, where each entry parsed every member's go.mod. Refs #2413. Assisted-by: Claude Code
PR SummaryMedium Risk Overview Module-only behavior is tightened in the same path: Supporting API: An e2e agent scan test asserts three layouts (plain module, Reviewed by Cursor Bugbot for commit 789ebfb. Configure here. |
|
bugbot run Generated by Claude Code |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 789ebfb. Configure here.
Bugbot's finding. A workspace member with no go.sum and an unpruned go.mod that has requires made the whole scope give up and walk the cache, before the workspace's sum file or its module graph were read. What such a member's requires need in turn is named by the graph, so the workspace is now treated as one with no sum file: every version the graph selects is added, and the walk is kept only when a go.mod the graph needs is not in the module cache. Refs #2413. Assisted-by: Claude Code
L136 to verify; L137 fixed in the PR. Three routine PRs are open.
|
[agent] PR shepherd: review brief for the approver What it does Risk: medium. The change only narrows what a project scan offers; Look here
Verified
Changes I made: none. Open questions
Generated by Claude Code |

LLM Description written by Claude Code
Part of #2413: the workspace half. The issue stays open for the other half (see "Left out").
Problem
A scan of a Go project offers a patch for every module version its crawl finds. A plain module's crawl is scoped to the modules its
go.sumrecords and itsgo.modrequires (#1207, #2169). With ago.workin effect the crawl still walked the whole module cache, and the cache belongs to the machine: every module of every project built there was reported, named to the patch API and offered a patch.For a developer with a workspace this means:
apply --checkexits 1 on them in every checkout.Evidence on
main(0a1709b)Real Go 1.24.7. A workspace of one member that requires
github.com/pkg/errorsv0.9.1, on a machine whose module cache other projects filled witherrorsv0.8.1,zerolog,logrusandx/sys. A stand-in patch API serves one patch for four of them and logs each request.The same module copied out of the workspace finds 1 package on both.
Two tests, red on
mainand green here:The second lists what each scan asked the API: the module alone, then with a
go.workbeside it, then with one above it.The class was fixed twice for the plain module (
git log -S'fn go_sum_scope': c52bb9b, #1207; d990d0b, #2169). Both left the workspace on the walk, because the workspace reader did not exist yet.The fix
One scope for both modes, in core
crawlers/go_crawler.rs.go_sum_scopereads the workspace through the loader hosted and vendored modes use (go_workspace::load) and collects, for eachusemember, whatmodule_scopealready collected for a module: the zip lines of itsgo.sumand its requires. To that it adds:go.sumlists (run: a build with a member'sgo.sumdeleted writes the lines togo.work.sum). The file is named after the work file:GOWORK=/x/ci.workwritesci.work.sum(run).replacenames, unless the build definitely does not select itgo.moddoes not require a module only a dependency needs. Without this a pruning scan dropped the record of a patch the build still links.A
usemember is left out (go builds it from its directory). A module under ago.workthat does not use it is scoped to its own files.The walk stays for
--globaland--global-prefix, and where the files are not the build's or cannot be read:-modfile, a workspace go refuses (invalidGOWORK, an unparseable or empty work file), a member whosego.modcannot be read or lies outside the repository, an unreadable sum file, and a workspace whose sum files do not list what it links (no sum file, or a member with an unprunedgo.modand nogo.sum) when the module cache cannot complete its graph.A defect of
mainthis also removesThe third row is not only for workspaces. On
main, in a go 1.16 module (real Go): patch a module only a dependency requires, rungo mod tidy, and the nextscan --syncprints "GC: pruned 1 manifest entry and removed 2 orphan files" for a patch the build still links;apply --checkthen exits 1 over an orphanreplace. Here the scan says "1 already patched" andapply --checkpasses.Deleted
workspace_in_effect(the crawler's own test for a workspace) and the hand-builtModuleGraphingo_workspace::module_graph, which now asksGoWorkspace::module_graph.go_build_list::module_selectionis the module-mode half ofproject_selectionunder its own name;project_selectioncalls it.Behavior change
scan --pruneand--syncin a workspace drop the records of modules it does not build, as in a module. Run on the treemainleft with four records: one pruning scan reports the three failures once more, prunes them and keeps the livereplace;apply --checkthen passes.go.modstill drops it.CLI_CONTRACT.mdanddocs/do not describe the crawl's scope, so neither is touched.Risk
The scope could miss a module the build links in a state not modelled here. The scan would then not offer its patch, and a pruning scan would drop its record. Against that: four sources are unioned, every unreadable state falls back to the walk, and the cases below ran with real Go.
maingo.work.sum; from the root and from the membergo.work.sumgo.work.sumdeleted and rewritten by a build; thenscan --sync,apply --checkGOWORKnamesci.work(sums inci.work.sum)go.workthat does not use itgo mod tidy--checkexit 1Review
/code-review highran five times; each finding was run before it was acted on.Fixed, each with a test: the sum file's name under
GOWORK; a missing and an out-of-date sum file; the replaced-module rule in module mode and for an answer of "nothing shows which version is built"; a module the workspace does not use; a work file with nouse; workspace members in the scope; one graph read for a workspace instead of one per replace.One fix was taken back: pass three asked that a requirement on a
usemember count as read, and pass four showed with real Go that go does look thatgo.modup (the build fails without it). The test now models the layout that builds, with a directoryreplace.No sixth pass ran: the last pass's three findings and Bugbot's one are fixed and unit-tested, but not reviewed again.
Left out
go getupgrade leaves ingo.sum). This is the other half ofscan --mode agentfails on, and records, Go modules the project does not build: every module in the machine's module cache under ago.work, and the old version ago getupgrade leaves in go.sum;applyorapply --checkthen exits 1 in CI #2413. Not offering it turns an exit 1 into an exit 0 that the contract does not settle, and belongs in the scan's selection, in a file an open agent PR edits.replacewhose target no sum file lists yet is not added. No mode can patch a replacement target (go does not chain replaces), so only its refusal is lost, and only until the next build writes the line.go_workspace::load_filereadsgo.work.sumwhatever the work file is called. The crawler reads the right file itself; the loader's other readers are not changed here.cfgcode changed), and Go releases other than 1.24.7.Verification
CI: 54 checks pass on the head (3cce1b9). Bugbot reviewed 789ebfb and found one issue, fixed in the head: a member with no
go.sumand an unprunedgo.modthat has requires ended the scope and kept the walk; it is now bounded by the module graph, as a workspace with no sum file is. Its thread is answered and resolved. Bugbot has not reviewed the head.Local, with real Go 1.24.7 and
SOCKET_PATCH_GO_E2E_REQUIRED=1:cargo clippy --locked --workspace --all-features -- -D warningsis clean. Core's Go unit tests (crawler, workspace, build list): 88 passed. Eight CLI suites, 382 passed and 0 failed:e2e_golang,e2e_golang_build,e2e_golang_workspace_build,e2e_golang_hosted_build,e2e_golang_hosted_state,e2e_vendor_golang_build,scanandin_process_scan. The table above ran again on it.go_crawler.rsalone): core's 8,809 unit tests passed, and twelve CLI suites (those eight,apply,cli,e2e_vex_lockfileandecosystem_dispatch_e2e) passed 1,098.git diff --stat: 4 files, +745 −88. Production +268 −64 (go_crawler.rs+245 −59,go_build_list.rs+11,go_workspace.rs+12 −5). Tests +477 −24.Generated by Claude Code