Repository navigation
Cut Go module downloads in CI and Go module codegen - #14450
Merged
Merged
Conversation
Tests that compile parts of this repo inside the dev engine (goCache, TestCrossCompile, two services tests) used a module cache that lives in the dev engine, which starts empty on every test run. So each run downloaded most of the repo's dependency graph again, although the test runner already has it: it just compiled the tests. Mount the runner's copies of the modules in go.sum as a file:// module proxy, with the network as fallback for anything else. Signed-off-by: Erik Sipsma <[email protected]>
Code generated for Go modules imports github.com/dagger/otel-go and go.opentelemetry.io/otel/sdk, but this SDK didn't require them. Module codegen copies the SDK's requirements into each generated module's go.mod, so `go mod tidy` there had to look up which module provides each of those imports over the network, and then picked whatever version was newest at the time. Require them through a tools-tagged package, so codegen pins them like the SDK's other dependencies. The tag keeps them out of builds. Signed-off-by: Erik Sipsma <[email protected]>
The Go SDK image pre-fills its module cache with `go list -deps` on the SDK's root package: 16 modules. Module codegen pins dagger.io/dagger with `go get` and runs `go mod tidy`, which need the whole module graph of a generated module, including tests of dependencies. So every fresh engine downloaded the rest again, about 250 requests per generated module. Also run codegen's commands in a module shaped like a generated one: the SDK's requirements and the replace directives codegen copies with them, its go.sum, and generated code's imports. Pin the dagger.io/dagger version the engine passes to codegen, tidy, and list all modules so their version info is cached too. The image's module cache grows from about 45 MB to about 195 MB, uncompressed. TestSystemGoProxy named three modules it expected to be downloaded because the engine did not pre-cache them; they are pre-cached now. It now checks that downloads went through its proxy without naming modules. Signed-off-by: Erik Sipsma <[email protected]>
Signed-off-by: Erik Sipsma <[email protected]>
vito
approved these changes
Oct 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Since mid-September, CI checks often fail while downloading Go modules:
proxy.golang.org (Google's front end) resets an HTTP/2 stream part-way through a module download, and
cmd/godoesn't retry. Over Sep 15–30 this failed at least 51 check outcomes on main across 30 commits, plus one checksum-database (sum.golang.org) failure. After timeouts, it's the most common red on main. We don't know what triggers the resets, but we control how often we roll the dice, and it turns out we roll them a lot.I measured one test-split shard (
test-container: TestContainer and TestDockerfile, 549 tests) on a fresh engine. It made about 5,100 requests to the Go module proxy and checksum database, including 1,083 module zips for only 525 distinct modules. Almost all of these re-download modules CI already has, into caches that start empty:go test -c ./core/integrationin TestSystemGoProxy, telemetry helpers,cmd/codegen). Their module cache lives in the dev engine, which starts empty every run, so each run re-downloads much of the repo's dependency graph. The test runner just compiled that same graph.go get dagger.io/dagger@<version>andgo mod tidyfor every generated module. On a fresh engine that's about 270 requests per module, even though the SDK image ships a pre-filled module cache. That cache only covers the SDK root package's own imports (go list -deps ., 16 modules), while tidy needs the generated module's whole graph, including tests of dependencies. Generated code also imports two modules the SDK doesn't require (github.com/dagger/otel-go,go.opentelemetry.io/otel/sdk), so tidy looks them up over the network and takes whatever version is newest.The modules that fail in CI match exactly:
docker/docker,x/sys,x/net,x/text,vito/midterm,protobuf, and so on.What this changes
Three commits:
core/integration: tests reuse the runner's modules when compiling the repo (test-only).goCache(and TestCrossCompile and two services tests) mount the test runner's copies of the modules in the rootgo.sumas afile://GOPROXY, withhttps://proxy.golang.org,directas fallback. That's about 440 MB, copied into the dev engine once per run. It also covers the fake Cloud service inTestProvision/TestImageDriverEngineEventsNeedEnable, which recently failed on main after 12 resets downloadinggoogle.golang.org/protobuf.sdk/go: require the modules that generated module code imports. A//go:build toolspackage (sdk/go/internal/codegendeps) imports them, sogo mod tidyrecords them in the SDK's go.mod. Codegen already copies the SDK's requirements into each generated module's go.mod, so tidy there no longer resolves them over the network, and their versions are pinned instead of "newest at the time".engine-dev: pre-cache what Go module codegen downloads. The SDK image build also runs codegen's commands in a module shaped like a generated one:sdk/go/internal/codegendeps.It pins the
dagger.io/daggerversion the engine passes to codegen (goSDKLibVersion, parsed fromcore/sdk/go_sdk.go, so the releasesedrecipe is unchanged), runsgo mod tidy, thengo list -m allto cache version info too. TestSystemGoProxy asserted that three specific modules weren't pre-cached; they are now. It now checks that downloads went through its proxy without naming modules.Codegen itself is unchanged. It still runs
go get dagger.io/dagger@<version>beforego mod tidy, so version selection and pinning behave exactly as before. Everything above changes only what's already in the cache, and what the SDK requires.Results
One Go module codegen. I reproduced codegen's commands locally against a fresh module cache: a generated module with no dependencies of its own,
go get dagger.io/dagger@<goSDKLibVersion>, thengo mod tidy, then a build of the generated packages. Network fetches counted withgo -x:The remaining 21:
go getmakes for the modules it touches.test-containershard, fresh local engine. Requests were counted by routing everything through a counting proxy on a scratch branch that isn't part of this PR:Effects to be aware of
dagger.io/daggerget higher minimum versions. The SDK now requiresgithub.com/dagger/otel-gov1.43.0 andgo.opentelemetry.io/otel/sdkv1.43.0, and raisesgo.opentelemetry.io/otel(and trace and metric) from v1.41.0 to v1.43.0. This expands its module graph. The tools tag keeps them out of builds: a consumer built against the new SDK compiles no otel-go packages, and builds against both the old and new SDK. But the requirements still raise minimum versions in its module graph through MVS. Generated modules already ended up at these versions, because tidy picked otel-go's newest release.codegendepsimport list must be kept in sync with the codegen templates. If they drift, codegen just downloads the missing modules again.Validation
go test ./cmd/codegen/...passes.sdk/go:go mod tidyleaves no diff;go build ./...andgo build -tags tools ./...pass..dagger/modules/engine-dev:go build ./...passes.dagger api call engine-dev test --pkg ./core/integration, plus the counting proxy where noted:--run 'TestContainer|TestDockerfile'(thetest-containershard): 549 passed;--run 'TestProvision/TestImageDriverEngineEventsNeedEnable$': passed;TestEngine/TestModuleVersionCompatandTestCachePersistence/TestDiskPersistenceAcrossRestart/engine-dev_container_build_survives_restart(passed), but not on this exact head.