Skip to content

scan --mode agent fails on, and records, Go modules the project does not build: every module in the machine's module cache under a go.work, and the old version a go get upgrade leaves in go.sum; apply or apply --check then exits 1 in CI #2413

In progress

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 apply exit 1 on a fresh clone ("None of the 2 targeted manifest patches matched an installed package") and apply --check exit 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-run and scan --mode vendored --dry-run find 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 --check then exits 1 in every checkout and says "Run socket-patch apply to regenerate them". On a fresh clone apply exits 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 tidy a second scan still exits 1 ("Applied 0 of 2 patches: 1 already patched, 1 failed"). scan --prune drops the record only once go.sum no longer lists the version, and the refusal does not name it. socket-patch remove of the record exits 0 and takes the live v0.9.1 replace out of go.mod (remove and rollback of a Go patch delete the replace of 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.sum and of go.work.sum, and each member's requires. Those are the files the comment on go_sum_scope names. The walk stays for --global and --global-prefix.
  • Before the scan selects a crawled module it asks the question apply asks. A version the build does not select, or a module outside its graph, is a calm skip: no download, no record, no failure. get already 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

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

    @mikolalysenko
    CollaboratorAuthor

    [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.work in effect is scoped to the sum files go reads for it, as the plain module's crawl is. Confirmed again on main at 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

  4. mikolalysenko commented on Dec 2, 2026

    @mikolalysenko
    CollaboratorAuthor

    [agent] #2431 is ready for review. It is the workspace half of this issue, and a little more.

    In #2431: with a go.work in effect the crawl is scoped to what the workspace builds (each member's go.sum and 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 on main at 0a1709b with real Go 1.24.7, the scan of the one-member workspace finds 1 package where main finds 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:

    • in a module, the line a go get upgrade leaves in go.sum until go mod tidy (the second half of this issue as written);
    • in a workspace, two members that require different versions of one module.

    The fix is this issue's second planned point: the scan asks the question apply asks 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 case CLI_CONTRACT.md does not settle (the narrowing rule this issue cites is get's), so a maintainer may want it as a skipped event instead of silence. And it belongs in the scan's selection, in CLI commands/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 its go.sum zip line at the next go mod tidy. The next scan --sync then prints "GC: pruned 1 manifest entry" for a patch the build still links, and apply --check exits 1 over an orphan replace.

    Found on the way, not fixed: go names a workspace's sum file after the work file (GOWORK=/x/ci.work writes ci.work.sum; run with go 1.24.7). The workspace loader reads go.work.sum whatever the file is called (core vendor/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 a GOWORK.

    The claim on this issue covers #2431 only.


    Generated by Claude Code

  5. added 2 commits that reference this issue on Dec 2, 2026
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:p2

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions