Skip to content

Read the sum file go reads under a GOWORK that names another work file - #2458

Open
Mikola Lysenko (mikolalysenko) wants to merge 4 commits into
mainfrom
arch-refactor/2439-gowork-sum-file
Open

Mikola Lysenko (mikolalysenko) wants to merge 4 commits into
mainfrom
arch-refactor/2439-gowork-sum-file

Conversation

@mikolalysenko

@mikolalysenko Mikola Lysenko (mikolalysenko) commented Dec 2, 2026 •

Copy link
Copy Markdown
Collaborator

LLM Description written by Claude Code

Fixes #2439.

Problem

go keeps a workspace's checksums in the work file's name with .sum appended: go.work.sum for go.work, ci.work.sum under GOWORK=/repo/ci.work. The workspace loader read go.work.sum beside the work file whatever the file was called, and vex takes a workspace's sums from the loader. The crawler had its own copy of the rule, added in #2431, and that copy follows go. So two readers of one rule disagreed.

Under a GOWORK that names another file, vex judged a hosted Go pin by a file go does not read, and never read the one go does:

  • it refused to attest a patched build go accepts (exit 1, no document), because of a go.work.sum go ignores, or because the zip pin sits in ci.work.sum, where go wrote it;
  • it attested from a zip line in go.work.sum, which binds nothing: go never checks a download against that file.

Who it hurts: a repository that keeps a second work file for CI (GOWORK=/repo/ci.work), beside or instead of go.work.

Evidence on main (7beca2f)

What go does (go 1.24.7, modules served from a file proxy, one member a, GOWORK=/repo/ci.work throughout):

/repo/a$ go run .                        # no sum file anywhere yet
upstream v0.9.1
/repo/a$ ls ..
a  ci.work  ci.work.sum  go.work         # go wrote ci.work.sum
/repo/a$ printf 'github.com/x/y v1.0.0\n' > ../go.work.sum
/repo/a$ go run .                        # a go.work.sum go cannot parse: not read
upstream v0.9.1
/repo/a$ rm ../go.work.sum; printf 'github.com/x/y v1.0.0\n' >> ../ci.work.sum
/repo/a$ go run .
malformed go.sum:
/repo/ci.work.sum:3: wrong number of fields 2

And the pin itself, with a stand-in for the Socket module (replace example.com/dep v0.9.1 => example.com/patched v0.9.2, the module cache emptied before each run):

/repo/a$ cat go.sum ../ci.work.sum       # the /go.mod line in go.sum, the zip line in ci.work.sum
example.com/patched v0.9.2/go.mod h1:+QWJ4Ta…
example.com/patched v0.9.2 h1:/YiW6V+…
/repo/a$ GOFLAGS=-mod=readonly go run .
patched v0.9.2
/repo/a$ printf 'example.com/patched v0.9.2 h1:AAAA…=\n' > ../ci.work.sum    # other bytes
/repo/a$ go run .
verifying example.com/patched@v0.9.2: checksum mismatch
SECURITY ERROR
/repo/a$ rm ../ci.work.sum; printf 'example.com/patched v0.9.2 h1:AAAA…=\n' > ../go.work.sum
/repo/a$ go run .                        # the same line in go.work.sum: not read
patched v0.9.2
/repo/a$ cat ../ci.work.sum              # go recorded what the proxy served
example.com/patched v0.9.2 h1:/YiW6V+…

What vex does. Two tests over the same table, each with the work file in the project root and one directory above it. Both are red on main and green here.

The unit test (core vex/discover/golang.rs), on main:

test vex::discover::golang::tests::a_named_gowork_reads_its_own_sum_file ... FAILED
[
    "a go.work.sum go cannot parse, GOWORK=ci.work: pinned false, go says true",
    "a go.work.sum go cannot parse, GOWORK=../ci.work: pinned false, go says true",
    "a ci.work.sum go cannot parse, GOWORK=ci.work: pinned true, go says false",
    "a ci.work.sum go cannot parse, GOWORK=../ci.work: pinned true, go says false",
    "the zip line in ci.work.sum, GOWORK=ci.work: pinned false, go says true",
    "the zip line in ci.work.sum, GOWORK=../ci.work: pinned false, go says true",
    "the zip line in go.work.sum, GOWORK=ci.work: pinned true, go says false",
    "the zip line in go.work.sum, GOWORK=../ci.work: pinned true, go says false",
]

The CLI test (e2e_vex_lockfile, vex --offline over a hosted replace with its record in the ledger), with the loader of main:

test golang::golang_named_gowork_reads_its_own_sum_file ... FAILED
[
    "a go.work.sum go cannot parse, GOWORK=ci.work: attested false, want true",
    "a go.work.sum go cannot parse, GOWORK=../ci.work: attested false, want true",
    "a ci.work.sum go cannot parse, GOWORK=ci.work: attested true, want false",
    "a ci.work.sum go cannot parse, GOWORK=../ci.work: attested true, want false",
    "the zip line in ci.work.sum, GOWORK=ci.work: attested false, want true",
    "the zip line in ci.work.sum, GOWORK=../ci.work: attested false, want true",
    "the zip line in go.work.sum, GOWORK=ci.work: attested true, want false",
    "the zip line in go.work.sum, GOWORK=../ci.work: attested true, want false",
]

(That run printed "go builds the pin" where the head prints "want"; the rows are the same.) Where vex does not attest it exits 1 with package_not_found for the module and writes no document.

The fix

One rule, go's: vendor::go_workspace::sum_file(work_file) is the work file's name with .sum appended. Its three readers go by it:

  • the workspace loader (load_file), which vex and hosted mode read the workspace through;
  • the crawler's scope (go_sum_scope), which had the rule inline;
  • the hosted engine's list of files it read outside the view, which named go.work.sum beside the work file.

The contract already says it: "The sum files are the ones go reads".

Tests

  • vex::discover::golang::tests::a_named_gowork_reads_its_own_sum_file (unit): five rows by two places for the work file.
  • golang::golang_named_gowork_reads_its_own_sum_file (CLI, e2e_vex_lockfile): the same ten cells through the binary. A row that goes the right way is held to its whole shape (the statement, or the skip and its code).

What the review found

An independent review by a subagent given the diff and the issue, not my conclusions: /code-review high, then its own probes and mutants in a worktree of its own, with go 1.24.7.

Finding Outcome
No defect in the production change. Every reader of the workspace's sum file is right with GOWORK naming ci.work, naming a go.work elsewhere, and unset; no reader was missed. —
The helper against go, run: .. segments are kept as go keeps them; a symlinked work file's sum file is the one beside the link, as for go; a trailing separator is refused by go and makes the workspace invalid here; a non-UTF-8 name keeps its bytes. —
Both tests fail with the fix removed, and each row of the unit test fails under at least one mutant. The CLI test stopped at its first wrong row. Fixed: it names every wrong row.
No test covers the hosted engine's line: with it reverted, or removed, every test passes. The reviewer could not build a wrong outcome from it; the line only tells a tracked snapshot which file was read. Not changed.
That same list never declares the work file an absolute GOWORK names (the vex side does). Read, not run. Not in this PR: it is older than this change and I have not shown a wrong outcome. Recorded as a lead for the routine.
Two sentences still said "the governing go.work.sum": a doc in the discovery, and the contract. The doc is fixed. The contract: see below.

Deleted

The crawler's inline copy of the rule, and the loader's wrong one.

Behavior change

Only under a GOWORK that names a work file not called go.work:

  • vex reads <file>.sum and no longer reads a go.work.sum beside it. A hosted Go pin whose zip line go wrote to <file>.sum attests (it was skipped, exit 1); a go.work.sum go ignores no longer decides anything; a <file>.sum go cannot parse stops the attestation (it was attested).
  • Nothing else reads the loader's sum text. scan's crawl already read <file>.sum.

For a work file named go.work, wherever it is, the file read is the same as before. No JSON shape, flag, code or exit-code meaning is new.

Risk

Small. The changed path is one file name, and it differs from main only for a work file not named go.work. A project that keeps go.work.sum beside a ci.work and relied on vex reading it gets the answer go gives.

Not in this PR

  • The contract sentence. CLI_CONTRACT.md says "with a go.work, its go.work.sum and each use member's go.sum". It should say "its sum file (go.work.sum, or <file>.sum for a GOWORK naming another file)". Fix agent mode reading gemrc gem directories Ruby does not load (#2317) #2459, an open agent/ PR, changes that file, and the routine does not edit a file another agent's open PR holds, so the sentence waits for it.
  • rollback and remove look for the Socket module's sum lines in go.sum and go.work.sum. Lines go appended to a ci.work.sum stay (read, not run); go tolerates them.
  • The loader reads a sum file it cannot read as absent. Unchanged.

Verification

Local, on 014ef71 (go 1.24.7):

  • cargo clippy --locked --workspace --all-features -- -D warnings: clean (run on 53b6aa3; only a doc comment and test text changed since).
  • Core: 8,998 unit tests passed, 0 failed, 1 ignored. It took two runs: the full run stalled on four tests of patch::redirect::upstream while the reviewer's builds ran beside it, so 8,946 passed with those three modules skipped, and their 52 passed on their own afterwards.
  • CLI, fourteen suites, 1,033 passed, 0 failed: e2e_vex_lockfile (360), vex, e2e_vex, e2e_golang, e2e_golang_build, e2e_golang_hosted_build, e2e_golang_hosted_state, e2e_golang_workspace_build, e2e_vendor_golang_build, hosted_memory_engine, hosted_memory_parity, scan, in_process_scan and cli. The Go build suites ran with the real toolchain.

Windows and macOS were not run. No cfg(windows) or cfg(unix) code changed.

CI on 014ef71 at 19:20Z: 55 checks pass, 71 are skipped (by a run the push started while the PR was a draft, and by path), none failed. Five jobs failed on the first attempt without reaching a test result (go / bazel (9.3.2, e9), pypi / bazel (8.8.2, e9), pypi / bazel (9.3.2, e9), coverage (1) and e2e-build (ubuntu-latest)): each ended ten minutes to the second after it started with "The self-hosted runner lost communication with the server" and no failed step. I re-ran the failed jobs of the three workflow runs once, and all five passed.

Cursor Bugbot reviewed 014ef71 and found no issues.

git diff --stat: 5 files, +204 −19. Production +16 −10 (vendor/go_workspace.rs, crawlers/go_crawler.rs, hosted/engine.rs), of which the helper and its doc are 10 lines; docs in vex/discover/golang.rs +11 −8. Tests +177 −1.


Generated by Claude Code

Assisted-by: Claude Code
@mikolalysenko Mikola Lysenko (mikolalysenko) added arch-refactor PR opened by the scheduled architecture refactor routine refactor Structural change: duplicated code or logic, missing abstraction, layering, dead code labels Dec 2, 2026
go keeps a workspace's checksums in the work file's name with `.sum`
appended: `go.work.sum` for `go.work`, `ci.work.sum` under
`GOWORK=/repo/ci.work`. The workspace loader read `go.work.sum` beside
the work file whatever the file was called, and `vex` took a
workspace's sums from it. So under a `GOWORK` that names another file
`vex` judged a hosted Go pin by a file go does not read and never read
the one go does: a `go.work.sum` go ignores could refuse a pin go
builds, and a zip line in it could stand as the pin with none in a
file go reads.

The crawler had its own copy of the rule, which followed go. There is
one now, `go_workspace::sum_file`, and the loader, the crawler and the
hosted engine's list of files read all go by it.

Nothing changes for a work file named `go.work`.

Fixes #2439.

Assisted-by: Claude Code
The CLI test stopped at the first row that went the wrong way. It now
collects each row whose outcome (attested or not) differs from go's,
and fails once with all of them; a row that goes the right way is
still held to its whole shape. Against the loader that read
`go.work.sum` it names eight of the ten rows.

Refs #2439.

Assisted-by: Claude Code
- The doc of the discovery's `outside_sums` still said "the governing
  `go.work.sum`"; it names the work file's sum file now.
- The CLI test's row for a zip line in `go.work.sum` alone said go
  does not build the pin. go builds: it takes what the proxy serves
  and records it in `ci.work.sum` (run with go 1.24.7 and a stand-in
  replacement module). The row's point is that no file go reads pins
  the zip, and the message and the doc say so.

No production code changes.

Refs #2439.

Assisted-by: Claude Code
@mikolalysenko
Mikola Lysenko (mikolalysenko) marked this pull request as ready for review December 2, 2026 18:49
@mikolalysenko

Copy link
Copy Markdown
Collaborator Author

bugbot run


Generated by Claude Code

@cursor

cursor Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

PR Summary

Medium Risk
Changes which sum file drives Go workspace pin attestation and crawl scope; only diverges from main when the active work file is not named go.work, but wrong attestation is security-relevant for patched builds.

Overview
Fixes #2439: when GOWORK points at a work file other than go.work (e.g. ci.work), Go stores checksums in ci.work.sum, not a sibling go.work.sum. The workspace loader had hard-coded go.work.sum, so vex could refuse valid pins or attest from sums Go ignores.

This PR introduces go_workspace::sum_file, which appends .sum to the work file’s basename (matching Go), and routes all readers through it: workspace load, Go crawl scope, and the hosted engine’s touched-file list. Discovery docs are updated accordingly.

Unit and CLI e2e tests (a_named_gowork_reads_its_own_sum_file) cover ten cases (sum file placement, broken go.work.sum vs ci.work.sum, zip-line location) with an e2e helper that sets GOWORK on vex runs. Behavior for a normal root go.work is unchanged.

Reviewed by Cursor Bugbot for commit 014ef71. Configure here.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 014ef71. Configure here.

@mikolalysenko

Mikola Lysenko (mikolalysenko) commented Dec 2, 2026 •

Copy link
Copy Markdown
Collaborator Author

[agent] Five jobs on 014ef71 failed, and none of them reached a test result: go / bazel (9.3.2, e9), pypi / bazel (8.8.2, e9), pypi / bazel (9.3.2, e9), coverage (1) and e2e-build (ubuntu-latest). ci-ok is red only because of the last two.

  • Each ended ten minutes to the second after it started (18:52:36Z to 19:02:36Z for the Bazel jobs, 18:52:52Z to 19:02:52Z for the other two), on five different runners.
  • Each job's only annotation is "The self-hosted runner lost communication with the server", and no step is recorded as failed.
  • On the same head, go / bazel (8.8.2, e9), go / bazel (7.7.2, e7) and coverage (2) passed.

So the runners were lost, not the tests. I re-ran the failed jobs of the three workflow runs once (19:03Z and 19:06Z). If a re-run fails with a test result, that is this PR's to fix; the outcome goes in the description's Verification section.


Generated by Claude Code

Mikola Lysenko (mikolalysenko) pushed a commit that referenced this pull request Dec 2, 2026
@mikolalysenko

Copy link
Copy Markdown
Collaborator Author

[agent] PR shepherd: review brief for the approver

What it does. go names a workspace's sum file after the work file (ci.work.sum under GOWORK=/repo/ci.work), but the workspace loader always read go.work.sum, so vex judged Go pins by a file go ignores. This adds one helper, go_workspace::sum_file, and makes the loader, the crawler and the hosted engine's touched-file list all use it.

Risk: low. Production change is +16 −10 and only changes behavior when GOWORK names a work file not called go.work; for go.work the path is byte-identical to before. No JSON shape, flag or exit code changes.

Look here

  • go_workspace.rs:293: the helper (appends .sum to the OsString, so non-UTF-8 and Windows paths keep their bytes).
  • go_workspace.rs:338: the loader, the actual fix.
  • go_crawler.rs:372 and engine.rs:1502: the other two readers moved onto the helper.
  • golang.rs:3052 and [e2e_vex_lockfile/golang.rs:1118](https://github.com/SocketDev/socket-patch/blob/014ef719d2b35c70f25600d34e8ddc6a495e17a3/crates/socket-patch-cli/tests/e2e_vex_lockfile/golang.rs#L1118): 5 cases × 2 work-file locations, unit and CLI.

Verified. Read the whole diff. Checked that rooted_at is false for any work file not named go.work, so a ci.work.sum in the project root goes through outside_sums and is not shadowed by the view's go.work.sum entry. Tests compare against go's behavior; the description shows both red on main. CHANGELOG.md untouched, no debug leftovers, no cfg-specific code. I did not run anything locally. CI on 014ef71: ci-ok and clippy green; the five lost-runner jobs passed on re-run. Bugbot: no issues. No open review threads.

Changes I made. None.

Open questions. None that block. Follow-ups listed in the description: the CLI_CONTRACT.md sentence (waits for #2459), and rollback/remove not cleaning ci.work.sum.


Generated by Claude Code

@mikolalysenko Mikola Lysenko (mikolalysenko) added the Ready for review Agent-verified: mergeable, CI green, Bugbot clean — awaiting human review label Dec 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arch-refactor PR opened by the scheduled architecture refactor routine Ready for review Agent-verified: mergeable, CI green, Bugbot clean — awaiting human review refactor Structural change: duplicated code or logic, missing abstraction, layering, dead code

Projects

None yet

2 participants