Repository navigation
Conversation
eunomie
force-pushed
the
engine-cache-namespaces-origin-and-sdk-entrypoint
branch
from
October 22, 2026 15:32
df390b9 to
a7cae96
Compare
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
force-pushed
the
engine-cache-namespaces-origin-and-sdk-entrypoint
branch
from
October 22, 2026 16:59
a7cae96 to
03b5377
Compare
sipsma
approved these changes
Oct 22, 2026
This was referenced Oct 22, 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.
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-runwent 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 withDirectory.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 tomod(goxxh3:<digest>). That namespace changes on every edit, and the same module loaded directly never uses it. The direct load, and every engine warmed bymain, usesmod(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.Symbolicis, 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.asModuleSourcewithout an origin keeps the digest namespace.The origin is also added to the
_implementationScopeddigests 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/gobuildin theinternalnamespace, which all Go modules share. The Go SDK entrypoint'scacheVolume("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 acacheVolumecall from that client sets no namespace, it getssdkEntrypoint, a namespace shared by every module entrypoint on the engine. The mark is engine-internal, likeUseRecipeIDsByDefault:No schema change.
Trust decision
Every module entrypoint on an engine shares the
sdkEntrypointcache namespace. The engine can't tell an SDK's generated entrypoint from one a module author wrote. The Go SDK generates itsmain.danginto 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 thegomod/gobuildvolumes 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:
main's legacy volumes: their keys (gomod/gobuild) differ fromgo-sdk-v2-mod/-build. The first entrypoint dispatcher build on each engine is still cold.Known limits
workspaceModuleSource) never getsGit.UnfilteredContextDir, soserveModulefrom 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 throughgitModuleSource, which is the path the Cloud trace took.URL.String(), with scheme and user. The same repository would then getmod(gohttps://github.com/...)instead ofmod(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
mainhas 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 bymain(14c1942ee2, then a touched commit).go: downloadingGo.binary×7mod(go<repo>/.dagger/modules/go), the namespacemainwarmed.go-sdk-v2-mod/-buildvolumes are insdkEntrypoint, shared across modules.internalfor 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:
namespaceFromModulewith and without an origin, for Git and local roots.ModuleSource.OriginSymbolic.cacheVolumeCacheKeywith and without the mark, including the legacygomodkey._implementationScopeddigests by origin.TestServeModuleCallerTree): a sibling served by the caller shares the caches of the same module loaded directly. Three cases:TestModuleEntrypointCacheVolumeschecks that the entrypoint's volumes are shared across modules and that a module process's volumes are not.Explanation: https://htmlpreview.github.io/?https://gist.githubusercontent.com/eunomie/1716f5e959da83e57bce53122b9552c6/raw/explain-changes.html