From 4357bc1ccd2a4621c20a2e4c037c4835632003a6 Mon Sep 17 00:00:00 2001 From: Vasek - Tom C Date: Thu, 23 Jul 2026 16:02:42 +0200 Subject: [PATCH] fix: scope module generation to the module path MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PolyfillModuleSource.generate rooted the generated context and fork at the caller cwd. At the workspace root (cwd '.') that captured the whole workspace — including any staged dependency codegen — in the changeset's before/after snapshots. When several modules are generated and their changesets merged (e.g. a root 'dagger generate'), the staged dependencies leak across modules: they cancel out (a dependency's codegen goes missing) or conflict on apply ('already exists'). Root the generated context at the module's own path and stage it on an empty fork base, so each module's changeset contains only its own files. Unchanged for a subdir cwd, where path already equals the cwd. Signed-off-by: Vasek - Tom C --- module-source.dang | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/module-source.dang b/module-source.dang index 54a5f09..c045521 100644 --- a/module-source.dang +++ b/module-source.dang @@ -76,16 +76,26 @@ type PolyfillModuleSource { Generate files for this module source, and return staged workspace changes. """ pub generate: PolyfillWorkspaceFork! { - let fork = PolyfillWorkspace(ws: ws, cwd: cwd).fork + # Scope the generated context to this module's path (not the caller cwd) and + # stage it on an empty fork base, so the returned changeset contains only this + # module's files. This keeps changesets disjoint when several modules are + # generated and merged (e.g. `dagger generate` at the workspace root) instead + # of leaking each module's staged dependency codegen into the others' before + # snapshots, which otherwise cancels them out or conflicts on merge. let generated = PolyfillGeneration.workspaceModuleGeneratedContext( wsID, path, cwd: ".", local: true, - root: fork.cwd, + root: path, ) - fork.withDirectoryDiff(fork.cwd, generated.before, generated.after) + PolyfillWorkspaceFork( + ws: ws, + cwd: cwd, + before: directory, + after: directory, + ).withDirectoryDiff(path, generated.before, generated.after) } """