dagger/dagger · error

stage module generated context: %w

Error message

stage module generated context: %w

What it means

This error wraps a failure from workspaceWithDirectoryOverlay, which merges the module's generated context (the new dagger-module.toml diff) into the staged workspace rootfs via Directory.withDirectory. It runs immediately after the config-file staging step in initModuleChanges; failure here means the engine could not overlay the module config diff directory onto the workspace tree.

Source

Thrown at core/schema/workspace_module_init.go:198

	moduleDiff, err := s.workspaceModuleInitConfigDiff(ctx, baseDir, args, relPath, runtimeRef)
	if err != nil {
		return res, scope, err
	}
	configRelPath := staged.ConfigFile

	dag, err := core.CurrentDagqlServer(ctx)
	if err != nil {
		return res, scope, fmt.Errorf("dagql server: %w", err)
	}

	updatedDir := baseDir
	updatedDir, err = workspaceWithFile(ctx, dag, updatedDir, configRelPath, newConfigBytes)
	if err != nil {
		return res, scope, fmt.Errorf("stage workspace config update: %w", err)
	}
	updatedDir, err = workspaceWithDirectoryOverlay(ctx, dag, updatedDir, moduleDiff)
	if err != nil {
		return res, scope, fmt.Errorf("stage module generated context: %w", err)
	}

	engineChanges, err := workspaceMigrationChanges(ctx, updatedDir, baseDir)
	if err != nil {
		return res, scope, err
	}

	sdkArgs, err := coresdk.DecodeInitArgs(args.Args)
	if err != nil {
		return res, scope, err
	}
	moduleInitializer, ok := loadedSDK.AsModuleInitializer()
	if !ok {
		return res, scope, fmt.Errorf("%q does not support module init", args.SDK)
	}
	sdkWorkspace, err := rootAnchoredWorkspace(ctx, parent)
	if err != nil {
		return res, scope, err

View on GitHub (pinned to 82ba2681db)

Solutions

  1. Read the wrapped inner error — 'source directory id: ...' points at ID computation on the diff; retry module init first.
  2. Restart the dagger engine session to clear missing/unresolvable cache blobs, then retry.
  3. Ensure the dagger SDK/CLI versions match the engine (`dagger version`); upgrade both if skewed.
  4. If reproducible on a minimal workspace, file a dagger issue with the wrapped error — this stage is fully engine-internal.
Defensive patterns

Strategy: retry

Validate before calling

// Confirm no module config already exists at the target path
for _, f := range []string{"dagger-module.toml", "dagger.json"} {
    if _, err := ws.Directory().File(filepath.Join(path, f)).Contents(ctx); err == nil {
        return fmt.Errorf("module config already exists at %s", path)
    }
}

Try / catch

if _, err := ws.InitModule(ctx, args); err != nil {
    if strings.Contains(err.Error(), "stage module generated context") {
        // restart engine session and retry from a fresh workspace
        return retryAfterEngineRestart(args)
    }
    return err
}

Prevention

When it happens

Trigger: Calling Workspace.initModule when the dagql withDirectory overlay fails: the source diff Directory ID cannot be computed (src.ID() failure), the module diff object is invalid, or the dagql query itself errors.

Common situations: The module config diff failed to build cleanly upstream (e.g. a marshal problem surfacing as an unusable Directory); content-addressed blob for the diff missing on the engine; dagql version skew between SDK and engine.

Related errors


AI-assisted analysis of dagger/dagger@82ba2681db (2026-09-05). Data as JSON: /api/errors/7f446924a655ad90. Report an issue: GitHub.