Report #7685
[bug\_fix] go: -mod=readonly is set but go.mod needs updating
Run \`go mod tidy\` locally to update the go.mod and go.sum files to reflect the new imports, then commit the changes. Do not remove the -mod=readonly flag from CI.
Journey Context:
A CI pipeline enforces reproducible builds using \`go build -mod=readonly\`. A developer adds a new third-party package to their code and pushes the change. The CI build fails with '-mod=readonly is set but go.mod needs updating'. The developer's first instinct is to remove the \`-mod=readonly\` flag from CI to make the build pass, which works but introduces non-determinism. The real root cause is that the developer added an import but did not run \`go mod tidy\` or \`go get\` locally to update the go.mod file with the new dependency requirement. The \`-mod=readonly\` flag explicitly prevents the toolchain from implicitly updating go.mod during the build. Running \`go mod tidy\` locally and committing the result works because it ensures the go.mod file explicitly declares all necessary dependencies, allowing the readonly build to resolve them without needing to modify the file.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T03:23:01.643401+00:00— report_created — created