Repository navigation
Description
What is the issue?
dagger module init <sdk> <name> fails when the selected dagger.toml lives in a subdirectory of the git repo rather than at the git root:
Error: sdk module init: failed to call sdk module initModule: workspace path .dagger/modules/hello is outside changeset root common
This breaks the common monorepo layout where several project workspaces live in subdirectories under a single git root (e.g. project-1/dagger.toml, common/dagger.toml). Running dagger module init from any of those subdirectories fails.
Reproduction
mkdir repo && cd repo
git init
mkdir common
touch common/dagger.toml
cd common
dagger sdk install go
dagger module init go hello -yThe last command fails with the error above. (Reproduced deterministically on v1.0.0-beta.9.)
Actual vs. expected
- Actual:
withInitModuleerrors with... is outside changeset root common; no module is created. - Expected: a
hellomodule scaffolded undercommon/(e.g.common/.dagger/modules/hello/), the same way it works when the config is at the git root.
Root cause
A cwd-vs-root mismatch across the engine ↔ SDK boundary:
-
The workspace root is the git root —
core/workspace/detect.gowalks up to.git; adagger.tomldoes not define the root. So withcommon/dagger.toml, root = git root and cwd =common. -
The engine computes the default module path workspace-root-relative:
.dagger/modules/<name>, independent of cwd (core/schema/workspace_module_init.go,relPath = filepath.Join(".dagger", "modules", args.Name)), and passes it to the SDK'sinitModule(path:). -
The Go SDK's
initModulestages files throughpolyfill.workspace(ws).fork.withDirectory(path, ...). The polyfill (github.com/dagger/polyfill,workspace-fork.dang→clientPath) is cwd-scoped: it converts a root-relative path into cwd-local coordinates and raises when the path is not under cwd:let relative = workspacePath.trimPrefix(cwd + "/") if (relative == workspacePath) { raise "workspace path " + workspacePath + " is outside changeset root " + cwd }
.dagger/modules/hello does not start with common/, so it raises. When the config is at the git root, cwd == "." and clientPath passes paths through unchanged — which is why it only fails from a subdirectory.
Trace (plain progress) showing the boundary:
Workspace.withInitModule(name: "hello", sdk: "go")
├─ Workspace.cwd → "common"
├─ GoSdk.initModule(path: ".dagger/modules/hello")
│ └─ PolyfillWorkspaceFork.withDirectory(path: ".dagger/modules/hello") ERROR
│ ! workspace path .dagger/modules/hello is outside changeset root common
Workarounds (all tested on v1.0.0-beta.9)
| Approach | Result |
|---|---|
dagger.toml at the git root, run from root |
✅ works |
Give the subdir its own .git (subdir becomes the workspace root) |
✅ works |
--path common/hello (path under cwd) |
common/hello/dagger-module.toml while the SDK's main.go lands at hello/main.go — a split, non-loadable module |
-W common from the git root |
❌ same error (root stays at the git root) |
--here |
❌ not a valid flag for module init |
The --path-under-cwd case is arguably the more serious half: it avoids the error but silently produces a broken module, because the engine's config changeset is applied workspace-root-relative while the SDK's source changeset has the cwd prefix stripped.
Suggested fix
Reconcile the two path conventions: the engine emits workspace-root-relative module paths, while the polyfill fork applies caller-cwd-relative ones. Either the engine derives the default path relative to a location the cwd-scoped fork can reach, or engine-driven initModule changesets are applied workspace-root-relative. The polyfill notes it is coding around "today's clients apply returned changesets relative to the caller cwd", so the reconciliation likely belongs on the engine side.
Dagger version
dagger v1.0.0-beta.9
engine v1.0.0-beta.9+1c6e07b1
go-sdk: github.com/dagger/go-sdk
polyfill: github.com/dagger/polyfill@ec3ea84a2351b4beb06ecece951f2e5ef66509ff
Activity
feat(checks): cover workspace configs in a git subdirectory
feat(checks): cover workspace configs in a git subdirectory
feat(checks): cover workspace configs in a git subdirectory (#17)
chore: update sdk-sdk to 3344489