Skip to content

core: same-repo modules and module entrypoints share their caches - #14813

Merged
eunomie merged 2 commits into
dagger:mainfrom
eunomie:engine-cache-namespaces-origin-and-sdk-entrypoint
Oct 22, 2026
Merged

eunomie merged 2 commits into
dagger:mainfrom
eunomie:engine-cache-namespaces-origin-and-sdk-entrypoint

Conversation

@eunomie

@eunomie eunomie commented Oct 22, 2026 •

Copy link
Copy Markdown
Member

Two cache-namespace problems make a Go module that moved to the Go SDK entrypoint (#14714) much slower than the legacy runtime. On a Cloud engine warmed by main, cli/release-dry-run went from about 40s to 5m37s.

Same-repo clients get the module's path identity

A module that serves a sibling from its own tree (serveModule("/.dagger/modules/go")) loads it with Directory.asModuleSource. That gives a Dir-kind source. Cache volumes of a Dir-kind module are namespaced by its content digest, so the sibling's caches went to mod(goxxh3:<digest>). That namespace changes on every edit, and the same module loaded directly never uses it. The direct load, and every engine warmed by main, uses mod(gogithub.com/dagger/dagger/.dagger/modules/go).

The Dir source now keeps the identity of the caller's tree: the clone ref for a Git caller, the root of the local context for a local one. The sibling's cache volumes are namespaced by that root plus the sibling's subpath, built the way Git.Symbolic is, so they match the direct load. A served sibling that serves a further sibling passes the root on.

The source is still loaded as a directory, so nothing else about how it loads changes. Directory.asModuleSource without an origin keeps the digest namespace.

The origin is also added to the _implementationScoped digests of the module and of the module source. Otherwise two loads of the same files from different origins would share the execs that create those volumes.

Module entrypoint caches are shared across modules

The legacy Go runtime built every module with gomod/gobuild in the internal namespace, which all Go modules share. The Go SDK entrypoint's cacheVolume("go-sdk-v2-mod"/"-build") calls set no namespace, so they were namespaced per module and each module built the dispatcher from cold caches.

The nested client that evaluates a module entrypoint (sources, types, call) is now marked. When a cacheVolume call from that client sets no namespace, it gets sdkEntrypoint, a namespace shared by every module entrypoint on the engine. The mark is engine-internal, like UseRecipeIDsByDefault:

  • It is never read from client headers.
  • The client metadata snapshots carry it explicitly.
  • The processes the entrypoint starts don't inherit it, so module code keeps its own namespace.

No schema change.

Trust decision

Every module entrypoint on an engine shares the sdkEntrypoint cache namespace. The engine can't tell an SDK's generated entrypoint from one a module author wrote. The Go SDK generates its main.dang into each module (source = "./internal/dagger/entrypoint") and embeds the module's own type definitions in it, so neither the address nor the content identifies the SDK. Entrypoint authors are therefore trusted like the built-in SDK runtimes: any module entrypoint can read and write the volumes shared with the other entrypoints on that engine.

The namespace is not internal, so entrypoint code can't reach the gomod/gobuild volumes that every legacy module build mounts.

Closing this fully needs a go-sdk design change, out of scope here: reference the entrypoint by address and pin (dagger.io/sdk/go/...@<pin>) instead of vendoring it, so the engine sees a git-pinned identity it can namespace by.

Downsides:

  • There is no isolation per SDK or SDK version: every entrypoint shares one namespace.
  • Nothing is shared with main's legacy volumes: their keys (gomod/gobuild) differ from go-sdk-v2-mod/-build. The first entrypoint dispatcher build on each engine is still cold.

Known limits

  • A module loaded through a Git workspace (workspaceModuleSource) never gets Git.UnfilteredContextDir, so serveModule from such a caller fails with "the calling module's tree is not loaded". That is pre-existing and unchanged here. This change covers callers loaded through gitModuleSource, which is the path the Cloud trace took.
  • If the Git-workspace path is wired later, its clone ref is URL.String(), with scheme and user. The same repository would then get mod(gohttps://github.com/...) instead of mod(gogithub.com/...).

Why in the engine

dagger/go-sdk#79 works around the first problem on the SDK side: it loads a same-repo client as a Git module on a Git workspace. On Cloud that costs a second checkout, about 20.5s, where loading the client from the caller's directory takes about 1.1s. This change keeps the directory load and fixes only the namespace. It doesn't need a second checkout, and local workspaces are covered too.

Cloud has many engines and most of them are cold. The gain shows on engines that main has already warmed: a cold engine builds from cold caches either way.

Related: #14714 (the migration that exposed both problems), dagger/go-sdk#79 (the SDK-side workaround).

Verification

PR #14714 head 4af3454335, unmodified (without dagger/go-sdk#79), on a local dev engine built from this PR's head. The workspace is a git workspace served over HTTP, as on Cloud. The engine was first warmed by main (14c1942ee2, then a touched commit).

Run Wall go: downloading Go.binary ×7
PR head, first run after main 40.0s 0 3.0s–3.2s
PR head, touched commit 23.9s 0 3.1s–3.4s
before (v1.0.0-beta.20, same setup) 206.9s 1137 ~2m40s
  • The go module's volumes are in mod(go<repo>/.dagger/modules/go), the namespace main warmed.
  • The go-sdk-v2-mod/-build volumes are in sdkEntrypoint, shared across modules.
  • An earlier revision of this PR, which used internal for these volumes, measured 45.2s and 28.1s in the same setup.

The timings and the integration tests were run by the author on a local dev engine; Cloud runs of this PR don't exercise either fix, because no module here uses an entrypoint or serves a sibling.

Tests:

  • Unit:
    • namespaceFromModule with and without an origin, for Git and local roots.
    • ModuleSource.OriginSymbolic.
    • cacheVolumeCacheKey with and without the mark, including the legacy gomod key.
    • _implementationScoped digests by origin.
    • The client-metadata snapshot and nested-request copies keep the mark and don't accept it from headers.
  • Integration (TestServeModuleCallerTree): a sibling served by the caller shares the caches of the same module loaded directly. Three cases:
    • a Git caller
    • a local caller
    • a sibling served by a served sibling
  • Integration: TestModuleEntrypointCacheVolumes checks that the entrypoint's volumes are shared across modules and that a module process's volumes are not.
  • The new integration tests pass on a dev engine built from this PR and fail on v1.0.0-beta.20. On beta.20 the direct load doesn't see what the served sibling wrote, and the second entrypoint module doesn't see the first one's volume.

Explanation: https://htmlpreview.github.io/?https://gist.githubusercontent.com/eunomie/1716f5e959da83e57bce53122b9552c6/raw/explain-changes.html

@eunomie
eunomie force-pushed the engine-cache-namespaces-origin-and-sdk-entrypoint branch from df390b9 to a7cae96 Compare October 22, 2026 15:32
@eunomie
eunomie marked this pull request as ready for review October 22, 2026 16:15
A module that serves a sibling from its own tree (serveModule with a
local address) loads it with Directory.asModuleSource, which gives a
Dir-kind source. Cache volumes of a Dir-kind module are namespaced by
its content digest, so the sibling's caches land in a namespace that
changes with every edit of its files and that the same module, loaded
directly as a Git or local source, never uses.

Keep the identity of the caller's tree on the Dir source (the git clone
ref, or the root of a local context) and namespace the sibling's cache
volumes by that root and its subpath, as the direct load does. A
sibling that serves a further sibling passes the root on.
Directory.asModuleSource without an origin keeps the digest namespace.
The implementation-scoped module digests include the origin, so execs
of the same files served from two origins do not share a result.

Signed-off-by: Yves Brissaud <[email protected]>
The legacy Go runtime builds every Go module with the gomod and gobuild
cache volumes in the internal namespace, shared by all Go modules. A
module entrypoint, such as the one the Go SDK generates, creates its
cache volumes through the API without a namespace, so they are
namespaced by the module being built and every module rebuilds the
SDK's dispatcher from cold caches.

Mark the nested client that evaluates a module entrypoint and give its
cache volumes the sdkEntrypoint namespace, shared by every module
entrypoint on the engine. The engine cannot tell an SDK's generated
entrypoint from one a module author wrote, so entrypoint authors are
trusted like the built-in SDK runtimes; the namespace is not internal,
so entrypoint code cannot reach the volumes legacy module builds mount.

The mark is engine-internal, like UseRecipeIDsByDefault: it is never
read from client headers, the client metadata snapshots carry it
explicitly, and the processes the entrypoint starts do not inherit it,
so module code keeps its own namespace.

Signed-off-by: Yves Brissaud <[email protected]>
@eunomie
eunomie force-pushed the engine-cache-namespaces-origin-and-sdk-entrypoint branch from a7cae96 to 03b5377 Compare October 22, 2026 16:59
@eunomie eunomie changed the title core: same-repo modules and SDK entrypoints share their caches again core: same-repo modules and module entrypoints share their caches Oct 22, 2026
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