Skip to content

Workspaces - #11812

Closed
shykes wants to merge 247 commits into
mainfrom
workspace
Closed

shykes wants to merge 247 commits into
mainfrom
workspace

Conversation

@shykes

@shykes shykes commented Feb 6, 2026 •

Copy link
Copy Markdown
Contributor

Introduce workspaces: project-level configuration separate from module definitions.

Dagger currently conflates project configuration and module definitions in a single dagger.json. This PR separates them: .dagger/config.toml for project configuration (which modules to use, how to configure them), dagger.json for module definitions (functions, types, dependencies). The result is a clearer model for both module users and module developers.


Configure your project with .dagger/config.toml:

[modules.ci]
source = "modules/ci"
entrypoint = true

[modules.go]
source = "github.com/dagger/[email protected]"
config.goVersion = "1.22"
dagger call build              # entrypoint module — functions at the top level
dagger call go lint            # namespaced module
dagger -W github.com/acme/project@main call build   # remote workspace

Modules interact with the project through a first-class API:

func New(ws dagger.Workspace) *Ci {
    goModFiles := ws.Directory(".").Glob("**/go.mod")
    // dynamically discover and build Go modules in the workspace
}

Existing projects work without changes — the engine infers a compatibility workspace from legacy dagger.json and nudges users to migrate:

WARNING: this project uses a legacy dagger.json format.
Run 'dagger migrate' to update your project.

When ready, migration is automated and previewed before applying:

$ dagger migrate
MIGRATION legacy-dagger-json
Convert legacy dagger.json to .dagger/config.toml

[changeset preview]

Apply changes? [y/N]

Full design doc

Task list

  • Simplify workspace location model: git root is workspace root; config directory is selected from workspace cwd
  • Review docs site redirects (we're breaking a lot of links)
  • Migration warning should be more visible
  • Migrated workspace config should have main module at the top
  • In migration doc, explain clearly what is legacy-default-path and what to do with it
  • Migration no longer has auto-population of module settings in file -> bring that back (checked)
  • CWD module autoload is only a fallback when no .dagger/config.toml exists; configured workspaces own module loading
  • github.com/dagger/dagger fails to load after migration
  • dagger uninstall doesn't work (dagger uninstall dagger-dev in dagger/[email protected] checkout)
  • Settings: ignore Workspace arguments (special case)
  • Some workspace config edits don't preserve byte order (checked)
  • Get rid of the TUI message "userdefault found..." (checked)
  • Env / settings edits make really weird formatting decisions on the toml (checked)
  • dagger migrate shows the "run `dagger migrate` soon" message

@shykes
shykes force-pushed the workspace branch 2 times, most recently from b31eedb to 5c9ebff Compare February 10, 2026 17:26
@shykes

This comment was marked as resolved.

@shykes

shykes commented Feb 10, 2026

Copy link
Copy Markdown
Contributor Author

Issue 1: Workspace detection fails over TCP connections (BLOCKER)

loadWorkspace() calls bk.AbsPath(ctx, ".") which requires the buildkit caller session. The session isn't registered when connecting over TCP because the session attachables handshake hasn't completed. The code silently skips workspace detection.

This is the same timing issue that extra modules (-m) already solved. The client-engine connection has three phases:

  1. Client init — initializeDaggerClient() runs, holds stateMu lock
  2. Session attachables — separate HTTP request, hijacks connection to gRPC, registers the buildkit caller session (filesystem access)
  3. Queries — serveQuery() runs, session is available

Extra modules were already moved from phase 1 to phase 3 (via pendingExtraModules + ensureExtraModulesLoaded in serveQuery) because the implementer hit this exact deadlock. But workspace module loading was left in phase 1, where bk.AbsPath() fails because the caller session doesn't exist yet.

The comment at session.go:1408-1411 attributes this to "nested dagger execution inside a container" but it happens for any connection — the caller session is always registered in phase 2, after phase 1 completes.

Fix: Defer workspace detection and module loading to phase 3 (serveQuery), same pattern as extra modules.

@shykes
shykes force-pushed the workspace branch 3 times, most recently from 1a6fdbb to 5d83b6a Compare February 12, 2026 14:31
@shykes shykes changed the title Workspaces Workspaces, modules v2 Feb 13, 2026
@shykes

shykes commented Feb 13, 2026

Copy link
Copy Markdown
Contributor Author

Workspace config defaults now bypass EnvFile entirely. WorkspaceConfig map[string]any stored directly on Module; UserDefault() bifurcates to check it before the .env pipeline (constructor args only). No lossy string round-trip.

@shykes

shykes commented Feb 13, 2026

Copy link
Copy Markdown
Contributor Author

Convert dagger check and dagger generate to workspace loading

Both commands now use Workspace.checks() / Workspace.generators() instead of manually loading a module from CWD. This aggregates across all served workspace modules and eliminates "module name must be set" errors in workspaces with no local dagger.json. The -m flag still works by setting Params.Module for single-module targeting.

@gregoryboue

Copy link
Copy Markdown

Hi @shykes

These new features look great, Do you have an approximate idea of a release date ?

@shykes shykes mentioned this pull request Feb 26, 2026
shykes added a commit that referenced this pull request Mar 17, 2026
The workspace-foundation ledger now records the cleanup that follows from rereading PR #11812 and PR #11995:

- the retained explicit -m engine fix is the related-module serving in engine/server/session.go
- the removed CLI layer was the local focused-Query projection and constructor-argv rewrite added later on workspace-plumbing
- those local shims are now classified as a design divergence, not behavior to preserve during rebase

The entry is intentionally explicit about commit lineage and retained-vs-removed behavior so it can be used later when cleaning workspace itself:
- it names the local repair commits that should not be resurrected
- it explains why wrapper-app related modules still need the engine-side load fix
- it records the new behavior consequence for explicit -m command shape
- it notes the upstream-owned temporary workarounds that still exist separately from this local cleanup
- it captures validation honestly: Linux cmd/dagger compile passed, while the direct engine-dev integration surface remained opaque after entering EngineDev.test(...)

This keeps the branch handoffable from the filesystem alone and makes the intended rebase behavior explicit.
vito pushed a commit that referenced this pull request Mar 17, 2026
The workspace-foundation ledger now records the cleanup that follows from rereading PR #11812 and PR #11995:

- the retained explicit -m engine fix is the related-module serving in engine/server/session.go
- the removed CLI layer was the local focused-Query projection and constructor-argv rewrite added later on workspace-plumbing
- those local shims are now classified as a design divergence, not behavior to preserve during rebase

The entry is intentionally explicit about commit lineage and retained-vs-removed behavior so it can be used later when cleaning workspace itself:
- it names the local repair commits that should not be resurrected
- it explains why wrapper-app related modules still need the engine-side load fix
- it records the new behavior consequence for explicit -m command shape
- it notes the upstream-owned temporary workarounds that still exist separately from this local cleanup
- it captures validation honestly: Linux cmd/dagger compile passed, while the direct engine-dev integration surface remained opaque after entering EngineDev.test(...)

This keeps the branch handoffable from the filesystem alone and makes the intended rebase behavior explicit.
vito pushed a commit that referenced this pull request Mar 20, 2026
The workspace-foundation ledger now records the cleanup that follows from rereading PR #11812 and PR #11995:

- the retained explicit -m engine fix is the related-module serving in engine/server/session.go
- the removed CLI layer was the local focused-Query projection and constructor-argv rewrite added later on workspace-plumbing
- those local shims are now classified as a design divergence, not behavior to preserve during rebase

The entry is intentionally explicit about commit lineage and retained-vs-removed behavior so it can be used later when cleaning workspace itself:
- it names the local repair commits that should not be resurrected
- it explains why wrapper-app related modules still need the engine-side load fix
- it records the new behavior consequence for explicit -m command shape
- it notes the upstream-owned temporary workarounds that still exist separately from this local cleanup
- it captures validation honestly: Linux cmd/dagger compile passed, while the direct engine-dev integration surface remained opaque after entering EngineDev.test(...)

This keeps the branch handoffable from the filesystem alone and makes the intended rebase behavior explicit.
@shykes
shykes changed the base branch from main to lockfile March 25, 2026 08:58
@shykes
shykes marked this pull request as ready for review March 25, 2026 08:58
@shykes
shykes requested a review from a team as a code owner March 25, 2026 08:58
@shykes
shykes requested review from a team as code owners March 25, 2026 22:59
vito and others added 26 commits June 1, 2026 11:01
Move the legacy LoadFromID SDK compat modules into testdata fixtures so the
tests no longer depend on dagger init. This matches the current SDK fixture
pattern and keeps the Go, Python, and TypeScript cases consistent.

Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Yves Brissaud <[email protected]>
* dagger mod subcommands for workspace and module development

Workspace modules (.dagger/config.toml):
- dagger mod install / uninstall / list, dagger mod search (registry fetched
  at runtime from GitHub with an embedded fallback), plus a top-level
  dagger uninstall and the Workspace.uninstall resolver.

Module development (dagger.json):
- dagger mod deps add / rm / list (ModuleSource dependency APIs)
- dagger mod engine required / require / require-current (ModuleSource engine version)

Generated SDK clients and docs are produced by a follow-up regenerate.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Signed-off-by: kpenfound <[email protected]>

* generate

Signed-off-by: kpenfound <[email protected]>

* use new updatedConfigDirectory api to update dagger.json without module loading

Signed-off-by: kpenfound <[email protected]>

* move deps add/rm to updatedConfigDirectory api

Signed-off-by: kpenfound <[email protected]>

* roll back deps and engine. Only use embedded modules.json

Signed-off-by: kpenfound <[email protected]>

---------

Signed-off-by: kpenfound <[email protected]>
Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
Signed-off-by: Yves Brissaud <[email protected]>
Signed-off-by: Kyle Penfound <[email protected]>
* test: cover module runtime directory export

Signed-off-by: Solomon Hykes <[email protected]>

* test: document module export coverage

Signed-off-by: Solomon Hykes <[email protected]>

---------

Signed-off-by: Solomon Hykes <[email protected]>
Signed-off-by: Yves Brissaud <[email protected]>
Signed-off-by: Solomon Hykes <[email protected]>
Signed-off-by: Yves Brissaud <[email protected]>
Signed-off-by: Solomon Hykes <[email protected]>
Signed-off-by: Yves Brissaud <[email protected]>
* recommend modules with dagger mod recommended

Signed-off-by: kpenfound <[email protected]>

* rename recommended to recommend

Signed-off-by: kpenfound <[email protected]>

* allow remote workspace ref for recommend, list, search

Signed-off-by: kpenfound <[email protected]>

---------

Signed-off-by: kpenfound <[email protected]>
Signed-off-by: Yves Brissaud <[email protected]>
Signed-off-by: Kyle Penfound <[email protected]>
Signed-off-by: Tibor Vass <[email protected]>
Signed-off-by: Yves Brissaud <[email protected]>
Signed-off-by: Solomon Hykes <[email protected]>
Signed-off-by: Yves Brissaud <[email protected]>
Signed-off-by: Solomon Hykes <[email protected]>
Signed-off-by: Yves Brissaud <[email protected]>
Signed-off-by: Solomon Hykes <[email protected]>
Signed-off-by: Yves Brissaud <[email protected]>
Signed-off-by: Solomon Hykes <[email protected]>
Signed-off-by: Yves Brissaud <[email protected]>
Signed-off-by: Solomon Hykes <[email protected]>
Signed-off-by: Yves Brissaud <[email protected]>
…attern

Commit ddc4c45 (PR #13243) added a TypeScript persistence subtest in
engine_persistence_test.go that calls modInit with inline source. The
dynamic module init helpers it relied on were already removed in
29f2782 (workspace branch is moving away from 'dagger module init'),
so the integration test package fails to compile, which fails go:lint
and every test-split target.

Switch the subtest to moduleFixture with typescript/runtime-cache-control,
which already defines the same testAlwaysCache() function with identical
crypto.randomBytes semantics. Use daggerCallAt(".", ...) to match the
fixture-based pattern used by the sibling go subtest.

Signed-off-by: Yves Brissaud <[email protected]>
The workspace branch fails go:lint with three pre-existing findings in
cmd/dagger that block the lint check (and cascade into ci:bootstrap):

  cmd/dagger/workspace.go:402:3      nilerr      error is not nil (line 400) but it returns nil
  cmd/dagger/workspace.go:900:34     staticcheck ST1005: error strings should not be capitalized
  cmd/dagger/cloud_checks.go:145:53  staticcheck ST1005: error strings should not be capitalized

- currentWorkspaceRemoteAddress intentionally treats inference failures as
  'no remote workspace selected' (returning empty/false/nil). Tag the line
  with //nolint:nilerr and a brief comment so future readers see the intent
  and the linter is satisfied.
- Lowercase the two capitalized error strings ("Cloud source ..." and
  "Cloud checks are ...") to match staticcheck's ST1005.

Signed-off-by: Yves Brissaud <[email protected]>
The helm e2e test invokes `dag.DaggerCli().Binary()` which runs the
cli-dev module against the test's workspace. cli-dev's source defaults
to '/' with `!**.graphql` and `!core/prompts/*.md` exclusion exceptions,
but those patterns can only re-include files that already exist in the
mounted workspace. The test's own workspace:include list narrows what
ends up in /ws, and currently omits the directories that hold the
embedded files cmd/dagger imports transitively:

  cmd/codegen/introspection/introspection.go //go:embed introspection.graphql
  core/prompts/fs.go                          //go:embed *.md

go build then fails inside the helm test with:

  cmd/codegen/introspection/introspection.go:11:12: pattern introspection.graphql: no matching files found
  core/prompts/fs.go:5:12: pattern *.md: no matching files found

Add both directories to the workspace:include list so the nested cli
build can find the embedded files.

Signed-off-by: Yves Brissaud <[email protected]>
util/layercopy/filter.go has no build tag and calls cleanRel(), but
cleanRel is defined in dest_linux.go which only builds on linux. As a
result, cross-compiling cmd/dagger to darwin or windows (e.g. from
cli:release-dry-run) fails:

  util/layercopy/filter.go:33:25: undefined: cleanRel
  util/layercopy/filter.go:36:31: undefined: cleanRel
  util/layercopy/filter.go:69:25: undefined: cleanRel
  util/layercopy/filter.go:77:25: undefined: cleanRel

cleanRel is purely a path-normalization helper with no OS-specific
behavior. Move it to types.go (no build tag) so non-linux builds can
find it. dest_linux.go and source_linux.go keep using it unchanged.

Signed-off-by: Yves Brissaud <[email protected]>
#13228 added a 'list with generate only includes generators' subtest that
asserts the `dagger check -l --generate` output contains a "Generators"
section header. The workspace branch renders checks and generators as a
unified flat table with a Type column instead, and its sibling
'list includes generator checks inline' subtest explicitly asserts
NotContains "Generators". Adapt the merged-in test to the workspace
format: assert the generators appear as generate-type rows, matching the
existing inline-list subtest, rather than expecting a "Generators" header.

Signed-off-by: Yves Brissaud <[email protected]>
Run `dagger generate -y` after rebasing onto the .dagger-removal +
onlyGenerate main. Brings all generated assets in line with the
generators: php reference docs (Workspace/WorkspaceMigration/Step/Module
+ onlyGenerate on Workspace.checks), GraphQL doc references, SDK client
libraries, and the per-module/toolchain runtime bindings (which trim the
unused Workspace* types). Also applies markdown-lint:fix.

Signed-off-by: Yves Brissaud <[email protected]>
cmd/dagger/workspace.go imported the heavy `core` package only for a handful of
git-ref helpers (GitRefString, FastModuleSourceKindCheck, ParseGitRefString,
ModuleSourceKind). Because `core` also contains Linux-only engine files
(changeset.go, git_remote.go, executor_spec.go, cacerts, filesync), the CLI
inherited them and failed to cross-compile for darwin/windows, breaking
cli:release-dry-run.

Extract the pure, dependency-light ref-parsing logic into a new leaf package
`core/gitref` (kind classification, scheme detection, git repo-root resolution).
`core` keeps its public API unchanged by delegating: ParsedGitRefString now
embeds gitref.Parsed and keeps its dagql-aware GitRef() method, the
ModuleSourceKind dagql enum stays in core, and FastModuleSourceKindCheck /
GitRefString / ParseGitRefString become thin wrappers. workspace.go imports only
gitref, so cmd/dagger no longer pulls in core and cross-compiles cleanly
(verified GOOS=darwin and GOOS=windows builds of ./cmd/dagger).

No schema change (no dagql-exposed type moved). The exhaustive git ref parsing
matrix moves to core/gitref alongside the code; core keeps a focused
ParseRefString wrapper test.

Signed-off-by: Yves Brissaud <[email protected]>
Signed-off-by: Solomon Hykes <[email protected]>
Signed-off-by: Yves Brissaud <[email protected]>
Signed-off-by: Yves Brissaud <[email protected]>
Signed-off-by: Yves Brissaud <[email protected]>
Allow prerelease version tags in the Git latest-version assertion and replace removed dagger init --sdk setup with explicit module config in the secret provider cache test.

Signed-off-by: Guillaume de Rouville <[email protected]>
Lower-case Cloud-only error strings that staticcheck flags.

Signed-off-by: Guillaume de Rouville <[email protected]>
Remote workspace selection stores git workspaces on Workspace.Rootfs(). The session loader already uses that tree to find .dagger/config.toml and load workspace modules, but later schema reads of the same config still went through readConfigBytes. That helper only knew how to read from the caller host path.

The result was a read-only remote workspace failure. A command such as dagger -W <git-ref> check -l could select the remote workspace successfully, load its modules, and then fail when checks re-read workspace config for check.skip rules with "workspace has no host path".

Keep local behavior unchanged by reading local workspace config through the host path. For remote workspaces, read the selected config file from Rootfs() instead. Mutation paths are intentionally unchanged: config writes, install, init, migration, and lock updates still require a host path because they mutate the caller filesystem.

Add focused integration coverage for a remote selected workspace with check.skip rules in .dagger/config.toml. The test serves a workspace through git, runs dagger check -l with -W, and verifies that the remote config is applied without requiring a host path.

Manual verification also covered the production-style repro from an empty directory: /home/dagger/dagger/hack/dev dagger -W github.com/dagger/vitest@codex/migrate-1.0 check -l now succeeds, while a remote configWrite still fails with "workspace has no host path".

Signed-off-by: Guillaume de Rouville <[email protected]>
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.