Skip to content

Cut Go module downloads in CI and Go module codegen - #14450

Merged
sipsma merged 4 commits into
dagger:mainfrom
sipsma:ci-go-module-downloads
Oct 1, 2026
Merged

sipsma merged 4 commits into
dagger:mainfrom
sipsma:ci-go-module-downloads

Conversation

@sipsma

@sipsma sipsma commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

Why

Since mid-September, CI checks often fail while downloading Go modules:

stream error: stream ID N; INTERNAL_ERROR; received from peer

proxy.golang.org (Google's front end) resets an HTTP/2 stream part-way through a module download, and cmd/go doesn'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:

  1. Tests compile parts of this repo inside the dev engine (go test -c ./core/integration in 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.
  2. Go SDK module codegen runs go get dagger.io/dagger@<version> and go mod tidy for 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:

  1. 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 root go.sum as a file:// GOPROXY, with https://proxy.golang.org,direct as fallback. That's about 440 MB, copied into the dev engine once per run. It also covers the fake Cloud service in TestProvision/TestImageDriverEngineEventsNeedEnable, which recently failed on main after 12 resets downloading google.golang.org/protobuf.

  2. sdk/go: require the modules that generated module code imports. A //go:build tools package (sdk/go/internal/codegendeps) imports them, so go mod tidy records 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".

  3. 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:

    • the SDK's requirements, plus the replace directives codegen copies with them;
    • the SDK's go.sum;
    • blank imports of sdk/go/internal/codegendeps.

    It pins the dagger.io/dagger version the engine passes to codegen (goSDKLibVersion, parsed from core/sdk/go_sdk.go, so the release sed recipe is unchanged), runs go mod tidy, then go list -m all to 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> before go 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>, then go mod tidy, then a build of the generated packages. Network fetches counted with go -x:

network requests
before 272
with the SDK requirements (commit 2) 167
with the pre-filled cache too (commit 3) 21

The remaining 21:

  • 2 resolve the pinned SDK commit to a version (Go can't answer that from its cache);
  • about 18 are version queries go get makes for the modules it touches.

test-container shard, fresh local engine. Requests were counted by routing everything through a counting proxy on a scratch branch that isn't part of this PR:

before after
all requests ~5,100 ~1,430
module zips 1,083 218
go.mod files 1,175 233
checksum DB (lookups, tiles) ~1,050 9

Effects to be aware of

  • Library users of dagger.io/dagger get higher minimum versions. The SDK now requires github.com/dagger/otel-go v1.43.0 and go.opentelemetry.io/otel/sdk v1.43.0, and raises go.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.
  • Bigger Go SDK image. Its pre-filled module cache grows from about 45 MB to about 195 MB uncompressed, in exchange for far fewer downloads at runtime.
  • The pre-fill is a snapshot taken at image build time. Modules a user's code adds, and newer releases of anything unpinned, still download as before. Normal proxy and checksum settings apply: GOPROXY, GOPRIVATE, GONOSUMDB and the checksum database are untouched.
  • Not covered: downloads in the outer CI engine (loading checks' own modules, outer builds), nested engines building the engine from source, and Dockerfile builds of other repositories (nerdctl). The codegendeps import 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 tidy leaves no diff;
    • go build ./... and go build -tags tools ./... pass.
  • .dagger/modules/engine-dev: go build ./... passes.
  • Local engine runs, with dagger api call engine-dev test --pkg ./core/integration, plus the counting proxy where noted:
    • --run 'TestContainer|TestDockerfile' (the test-container shard): 549 passed;
    • --run 'TestProvision/TestImageDriverEngineEventsNeedEnable$': passed;
    • TestSystemGoProxy passed within the shard run above.
  • Local codegen reproduction: the generated packages build with both the old and the new SDK requirements, including the copied otel log replace directives.
  • Earlier iterations ran TestEngine/TestModuleVersionCompat and TestCachePersistence/TestDiskPersistenceAcrossRestart/engine-dev_container_build_survives_restart (passed), but not on this exact head.
  • Not yet run on this head: the other test-split shards and the SDK client suites. CI will cover them.

sipsma added 3 commits October 1, 2026 19:29
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]>
@sipsma
sipsma requested a review from a team as a code owner October 1, 2026 19:31
@sipsma
sipsma merged commit 1749094 into dagger:main Oct 1, 2026
90 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants