Repository navigation
Warn and fail --check when Go vendor/ or go.mod need a resync (#343, #618) - #1357
Mikola Lysenko (mikolalysenko) wants to merge 2 commits into
Conversation
Two Go build breakages were reported as success. #343: in a project with a committed vendor/ (go mod vendor), wiring a socket `replace` (apply, vendor, scan --mode hosted) or removing one (rollback) leaves vendor/modules.txt out of step with go.mod, so every default build fails with "inconsistent vendoring". #618: when a patch bumps or adds a requirement in the patched module's own go.mod, the consumer's go.mod/go.sum are not updated, so the default -mod=readonly build fails with "updates to go.mod needed". In both cases apply exited 0 and apply --check said in sync. A new vendor::go_consumer_sync::audit compares the replace directives with vendor/modules.txt (go mod vendor / go work vendor layouts) and with the patched copies' go.mod requirements. apply, vendor, rollback and hosted scan now emit go_vendor_modules_txt_out_of_sync / go_requirements_out_of_sync warnings that name the go command to run. apply --check and vendor --check report them as drift until it is run. Fixes #343 Fixes #618 Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
|
BugBot review |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
Bugbot Autofix is ON. A cloud agent has been kicked off to fix the reported issue.
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 32fb4f0. Configure here.
| let mut issues = vendor_modules_txt_issues(project_root, &replaces).await; | ||
| issues.extend(requirement_issues(project_root, &go_mod, &replaces, pristine_go_mods).await); | ||
| issues | ||
| } |
There was a problem hiding this comment.
Workspace replaces missed in modules.txt audit
Medium Severity
audit compares workspace-wide vendor/modules.txt to socket replaces from only the current go.mod. It never reads go.work or other members, so a valid replace that lives there looks stale. apply --check and vendor --check then fail on a tree that already builds, and go work vendor does not clear the drift.
Additional Locations (1)
Triggered by learned rule: Remediation advice must be convergent: following it must clear the triggering detection
Reviewed by Cursor Bugbot for commit 32fb4f0. Configure here.
command_module_layering forbids rollback and scan importing apply, and envelope_helper_copies forbids a private warning_codes reader; route every caller through go_consumer_sync::audit_warnings and the test through common::envelope. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
| }); | ||
| } | ||
| } | ||
| for rec in recorded.iter().filter(|r| r.socket_owned()) { |
There was a problem hiding this comment.
[agent] In workspace mode modules.txt is the workspace-wide one (go work vendor writes every use member's replaces plus go.work's), but replaces here comes from the current module's go.mod only (audit, :152). Scenario: go.work with use . and use ./tools, root module patched, go work vendor run; socket-patch apply --check from ./tools reports every root Socket replace as go_vendor_modules_txt_out_of_sync (stale) and exits 1, and re-running go work vendor can't clear it. (Inverse: a member replace overridden by a go.work replace is reported as not recorded.) Fix: when workspace is set, compare against the union of all members' replaces plus go.work replaces, or skip the stale direction.


LLM Description written by Claude Code:claude-opus-5-5
Fixes #343
Fixes #618
Summary
A Go
replacecan be wired correctly while the project still won't build, because two files go derives fromgo.modno longer match it. Every Go mode now warns about this with the exact command that fixes it, andapply --check/vendor --checktreat it as drift. Before, the run exited 0 with no warning and--checksaid in sync.go_vendor_modules_txt_out_of_sync(#343)vendor/whosemodules.txtdoesn't record a socketreplace, or still records one that rollback removedgo mod vendor(go work vendorfor a workspace)go_requirements_out_of_sync(#618)go.modrequires a dependency above the version the consumergo.modlists (and, at apply time, a requirement the patch added)go mod tidyRoot cause
The Go backends only edit the consumer
go.modreplace(go_mod_edit::ensure_replace_entry/drop_replace_entry). Nothing readvendor/modules.txtor the replacement'sgo.modrequirements, andverify_go_redirect_stateonly hashed the copy and checked the directive.Fix
vendor::go_consumer_sync::audit(project_root, pristine_go_mods). It is read-only and offline.vendor/modules.txt(the module's own, or thego.workroot's), parses its# M v => targetlines, and compares them with the socket-ownedreplacedirectives in both directions.go.modand compares itsrequires with the consumer's. A requirement the consumer lists at a lower version is always reported. One the consumer doesn't list is reported only when the pristinego.modshows the patch added or raised it, because upstreamgo.mods routinely require modules a pruned consumer graph never lists.applyas run warnings (JSONwarnings[]plus stderr), with the module-cachego.modpassed as the pristineapply --checkas drift; when only these drifts are present, the "Runsocket-patch apply" footer is suppressed because apply can't fix themvendoras warnings andvendor --checkas drift (per Go ledger entry)rollbackas warningsscan --mode hostedas warnings when it rewrote ago.modDesign decision: socket-patch doesn't run
go mod vendor/go mod tidyitself. Both need the go toolchain and the whole module graph (often network), and they rewrite files the user owns. That follows the v5 triage note on both issues: "synchronize … or give an actionable regeneration step". A maintainer could later make auto-running them opt-in.Known limits:
go.modisn't in the project.--check(no module cache) andvendor(no pristine) flag only the "listed lower" shape of Go apply and vendor wire in a patched module whose go.mod raises or adds a requirement without syncing the consumer go.mod/go.sum, so every defaultgo buildfails while apply, --check and VEX report success #618, which is the common security-bump case.Tests (red → green)
e2e_golang_build::committed_vendor_dir_needs_go_mod_vendor_after_apply_and_rollbackruns against real go. Flow:go mod vendor→ apply. It asserts apply emits the warning and thatgo buildreally fails with "inconsistent vendoring", then thatapply --checkexits 1 naminggo mod vendor. Aftergo mod vendor,go runprints PATCHED and check exits 0. After rollback, the stale warning appears and check exits 1. On main it fails at "apply must name the vendor/modules.txt regeneration".go buildfails while apply, --check and VEX report success #618:e2e_golang_build::patched_go_mod_requirement_bump_needs_go_mod_tidyruns against real go. The patch bumpsexample.com/depv1.0.0 → v1.1.0 in the upstreamgo.mod. It asserts the warning, that the default build fails, and that--checkexits 1 naminggo mod tidy. Aftergo mod tidy,go runprintsFIXED-PATCHEDand check exits 0. On main it fails at "apply must name the go.mod/go.sum refresh".go_consumer_sync::tests:Commands run
cargo test -p socket-patch-cli --lib --test e2e_golang_build --test e2e_vendor_golang_build --test e2e_golang_hosted_build --test e2e_golang_workspace_build --test e2e_golang_hosted_state --test e2e_golang --test spawn_env_hygiene(go 1.26.3): all greencargo test -p socket-patch-core --lib -- go_consumer_sync golang_local go_mod_edit go_sum_edit: 109 passedcargo clippy --workspace --all-features -- -D warnings: cleancargo fmt --check: the changed files are clean🤖 Generated with Claude Code
Note
Medium Risk
Changes Go apply/check/rollback/vendor behavior and CI drift semantics; logic is read-only but can cause new warnings and
--checkfailures where redirects previously looked healthy.Overview
Adds Go consumer-sync detection so socket
replacewiring is no longer treated as “done” when the project still cannot build.A new read-only
go_consumer_sync::auditcompares socket-ownedgo.modreplacedirectives against committedvendor/modules.txt(#343) and against requirements in patched local copies’go.mod(#618). It emits actionable warnings (go mod vendor/go work vendor, orgo mod tidy) with stable codesgo_vendor_modules_txt_out_of_syncandgo_requirements_out_of_sync.applyrecords pristine module-cachego.modpaths during local Go applies and surfaces warnings after a successful run;apply --checktreats these as drift and skips the generic “Runsocket-patch apply” hint when only consumer-sync issues remain. The same audit is wired intorollback,vendor/vendor --check, andscan --mode hostedwhengo.modwas rewritten. Docs inecosystems.mddocument the two failure modes; e2e tests exercise realgobuilds for vendor and requirement bumps.Reviewed by Cursor Bugbot for commit 32fb4f0. Configure here.