Skip to content

fix: scope module generation to the module path - #5

Merged
TomChv merged 1 commit into
mainfrom
fix/module-generate-scope-to-path
Jul 24, 2026
Merged

TomChv merged 1 commit into
mainfrom
fix/module-generate-scope-to-path

Conversation

@TomChv

@TomChv TomChv commented Jul 23, 2026 •

Copy link
Copy Markdown
Member

PolyfillModuleSource.generate rooted the generated context and the fork at the caller cwd. In a module subdirectory that's fine (the cwd is the module). But at the workspace root (cwd = ".") it 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 running the Go and TypeScript SDK generators), the staged dependency codegen leaks across modules:

  • a dependency's codegen appears in another module's before snapshot and cancels out (goes missing from the output), or
  • the octopus merge unions those polluted befores and then conflicts on apply (.dagger/modules/b/... already exists).

Fix

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. Behavior is unchanged for a subdir cwd (there path == cwd).

This unblocks ModuleSource.generateLocalDependencies (dagger/dagger#13706) for the multi-module / workspace-root case.

PR chain

The two SDK PRs depend on both the engine PR and the polyfill PR. The engine and polyfill PRs are independent of each other.

TomChv added a commit to dagger/typescript-sdk that referenced this pull request Jul 23, 2026
Temporary: point the polyfill dependency at
fix/module-generate-scope-to-path (dagger/polyfill#5) so multi-module /
workspace-root generate works. Revert to @main once that PR merges.

Signed-off-by: Vasek - Tom C <[email protected]>
TomChv added a commit to dagger/go-sdk that referenced this pull request Jul 23, 2026
Temporary: point the polyfill dependency at
fix/module-generate-scope-to-path (dagger/polyfill#5) so multi-module /
workspace-root generate works. Revert to @main once that PR merges.

Signed-off-by: Vasek - Tom C <[email protected]>
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 <[email protected]>
@TomChv
TomChv force-pushed the fix/module-generate-scope-to-path branch from c2a9322 to 4357bc1 Compare July 23, 2026 14:21
@TomChv
TomChv merged commit 1662706 into main Jul 24, 2026
17 checks passed
TomChv added a commit to dagger/typescript-sdk that referenced this pull request Jul 24, 2026
dagger/polyfill#5 merged; point the polyfill dependency back at @main.

Signed-off-by: Vasek - Tom C <[email protected]>
TomChv added a commit to dagger/go-sdk that referenced this pull request Jul 24, 2026
dagger/polyfill#5 merged; refresh the polyfill @main pin to include it.

Signed-off-by: Vasek - Tom C <[email protected]>
TomChv added a commit to dagger/go-sdk that referenced this pull request Jul 24, 2026
dagger/polyfill#5 merged; point the polyfill dependency at @main.

Signed-off-by: Vasek - Tom C <[email protected]>
TomChv added a commit to dagger/go-sdk that referenced this pull request Jul 27, 2026
Temporary: point the polyfill dependency at
fix/module-generate-scope-to-path (dagger/polyfill#5) so multi-module /
workspace-root generate works. Revert to @main once that PR merges.

Signed-off-by: Vasek - Tom C <[email protected]>
TomChv added a commit to dagger/go-sdk that referenced this pull request Jul 27, 2026
dagger/polyfill#5 merged; point the polyfill dependency at @main.

Signed-off-by: Vasek - Tom C <[email protected]>
TomChv added a commit to dagger/typescript-sdk that referenced this pull request Jul 27, 2026
Temporary: point the polyfill dependency at
fix/module-generate-scope-to-path (dagger/polyfill#5) so multi-module /
workspace-root generate works. Revert to @main once that PR merges.

Signed-off-by: Vasek - Tom C <[email protected]>
TomChv added a commit to dagger/typescript-sdk that referenced this pull request Jul 27, 2026
dagger/polyfill#5 merged; point the polyfill dependency back at @main.

Signed-off-by: Vasek - Tom C <[email protected]>
TomChv added a commit to dagger/go-sdk that referenced this pull request Jul 27, 2026
dagger/polyfill#5 (scope module generate to path) is merged, so pick it
up from @main.

Signed-off-by: Tom Chauveau <[email protected]>
TomChv added a commit to dagger/typescript-sdk that referenced this pull request Jul 27, 2026
Before generating each managed module, stage its transitive local
dependency closure via ModuleSource.generateLocalDependencies and overlay
it onto the workspace, so the module's codegen sees up-to-date dependency
bindings — including dependencies owned by other SDKs. The staged
dependency codegen is ephemeral: it appears in both the fork's before and
after, so it cancels in the merge, leaving only each module's own changes.

Bumps the polyfill pin to pick up dagger/polyfill#5, which scopes module
generation to the module path.

Signed-off-by: Tom Chauveau <[email protected]>
TomChv added a commit to dagger/go-sdk that referenced this pull request Jul 27, 2026
Before generating each managed module, stage its transitive local
dependency closure via ModuleSource.generateLocalDependencies and overlay
it onto the workspace, so the module's codegen sees up-to-date dependency
bindings — including dependencies owned by other SDKs. The staged
dependency codegen is ephemeral: each changeset is taken against the
staged workspace, so it cancels out, leaving only each module's own
changes.

Bumps the polyfill pin to pick up dagger/polyfill#5 (scope module
generate to path) from @main.

Signed-off-by: Tom Chauveau <[email protected]>
TomChv added a commit to dagger/go-sdk that referenced this pull request Jul 28, 2026
Before generating each managed module, stage its transitive local
dependency closure via ModuleSource.generateLocalDependencies and overlay
it onto the workspace, so the module's codegen sees up-to-date dependency
bindings — including dependencies owned by other SDKs. The staged
dependency codegen is ephemeral: each changeset is taken against the
staged workspace, so it cancels out, leaving only each module's own
changes.

Bumps the polyfill pin to pick up dagger/polyfill#5 (scope module
generate to path) from @main.

When @generate runs nested under the engine's ModuleSource.generateLocalDependencies
(the SDK generator invoked per local dependency), the workspace it receives already
has the leaf dependency closure staged. #13 assembles the result as
ws.changes.withChangesets(changes); in that nested context ws.changes re-included the
staged closure, which then (a) got re-rooted under the dependent's path by the engine
(b/.dagger/modules/a/...) and (b) octopus-merged against the freshly generated,
overlapping files (apply ours patch: ... already exists) — for Go modules with a
local-dependency closure of 3+.

Fold onto pws.fork.changes (an empty changeset) instead, keeping #13's parallel
map + {{isEmpty}} force. Only each module's own changes remain, so nothing re-enters
the result. Matches the TypeScript SDK, which never reproduced this.


Signed-off-by: Tom Chauveau <[email protected]>
TomChv added a commit to dagger/typescript-sdk that referenced this pull request Jul 28, 2026
Before generating each managed module, stage its transitive local
dependency closure via ModuleSource.generateLocalDependencies and overlay
it onto the workspace, so the module's codegen sees up-to-date dependency
bindings — including dependencies owned by other SDKs. The staged
dependency codegen is ephemeral: it appears in both the fork's before and
after, so it cancels in the merge, leaving only each module's own changes.

Bumps the polyfill pin to pick up dagger/polyfill#5, which scopes module
generation to the module path.

Signed-off-by: Tom Chauveau <[email protected]>
vito added a commit that referenced this pull request Jul 28, 2026
The generate docstring still described paths as workspace-root-relative,
which stopped being true when the changeset was re-rooted onto the caller
cwd. It also never said why the module-path scoping from #5 is gone: the
engine diffs the generated context against the same base it generated
from, so the changeset only ever carries this module's own generated
files — staged dependency codegen appears on both sides and cancels out
before it can leak. State both, since the old fork pipeline's leak is
exactly what a reader of #5 will worry about here.

Signed-off-by: Alex Suraci <[email protected]>
vito added a commit that referenced this pull request Jul 28, 2026
The generate checks covered a single module with no dependencies, so
they said nothing about the multi-module merge that #5 was about, and
their membership-only assertions would pass over leaked extra paths. Add
a fixture with two sibling modules sharing a local dependency, generate
all three, and assert each changeset stays inside its own subtree and
that the octopus merge is the exact union of the parts — the two ways
dependency leakage would show up (conflict, or cancellation dropping
paths from the union). Also address the subdir check's module the way a
caller standing in it does — a cwd-relative ref, exercising
moduleSourcePath's cwd-joining branch — and assert no path carries the
workspace-root prefix, the signature of the doubled-path bug.

Signed-off-by: Alex Suraci <[email protected]>
vito added a commit that referenced this pull request Jul 29, 2026
The generate docstring still described paths as workspace-root-relative,
which stopped being true when the changeset was re-rooted onto the caller
cwd. It also never said why the module-path scoping from #5 is gone: the
engine diffs the generated context against the same base it generated
from, so the changeset only ever carries this module's own generated
files — staged dependency codegen appears on both sides and cancels out
before it can leak. State both, since the old fork pipeline's leak is
exactly what a reader of #5 will worry about here.

Signed-off-by: Alex Suraci <[email protected]>
vito added a commit that referenced this pull request Jul 29, 2026
The generate checks covered a single module with no dependencies, so
they said nothing about the multi-module merge that #5 was about, and
their membership-only assertions would pass over leaked extra paths. Add
a fixture with two sibling modules sharing a local dependency, generate
all three, and assert each changeset stays inside its own subtree and
that the octopus merge is the exact union of the parts — the two ways
dependency leakage would show up (conflict, or cancellation dropping
paths from the union). Also address the subdir check's module the way a
caller standing in it does — a cwd-relative ref, exercising
moduleSourcePath's cwd-joining branch — and assert no path carries the
workspace-root prefix, the signature of the doubled-path bug.

Signed-off-by: Alex Suraci <[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.

2 participants