Skip to content

generate: stage local dependency closure before codegen - #12

Merged
TomChv merged 2 commits into
mainfrom
feat/aggregate-local-dep-in-worskpace-when-generating
Jul 28, 2026
Merged

TomChv merged 2 commits into
mainfrom
feat/aggregate-local-dep-in-worskpace-when-generating

Conversation

@TomChv

@TomChv TomChv commented Jul 23, 2026 •

Copy link
Copy Markdown
Member

Uses the new ModuleSource.generateLocalDependencies engine API. Before generating each managed module, generateAll (the @generate function) and Mod.generate stage the module's transitive local dependency closure onto the workspace via withChanges, then generate against the staged workspace — so the module's codegen sees up-to-date dependency bindings, including dependencies owned by other SDKs.

Depends on

PR chain

Both SDK PRs depend on the engine PR (#13715). The polyfill scoping fix is merged.

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
TomChv force-pushed the feat/aggregate-local-dep-in-worskpace-when-generating branch from fef8c1e to ec033e3 Compare July 27, 2026 14:53
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: Vasek - Tom C <[email protected]>
@TomChv
TomChv force-pushed the feat/aggregate-local-dep-in-worskpace-when-generating branch from 6199fae to 14fdae2 Compare July 27, 2026 16:52
@TomChv

TomChv commented Jul 27, 2026 •

Copy link
Copy Markdown
Member Author

Fix for the generateLocalDependencies failure on local dependency chains of 3+ (with a Go module)

14fdae2 fixes the failure reported in dagger/dagger#13715 (apply ours patch: … already exists, and doubly-prefixed b/.dagger/modules/a/… paths).

What changed — one expression in generate:

- ws.changes.withChangesets(changes)
+ pws.fork.changes.withChangesets(changes)

Everything else — the parallel .map and the changes.{{isEmpty}} force — is unchanged from #13.

Why ws.changes was wrong here. This PR makes generate stage each module's local dependency closure (generateLocalDependencies) before generating it. That closure is also consumed a second way: the engine's ModuleSource.generateLocalDependencies runs this very @generate once per local dependency, and the workspace it hands us already has the leaf closure staged. In that nested call, ws.changes is that staged closure. Assembling the result as ws.changes.withChangesets(changes) folded it back in, and then:

  1. the engine re-rooted the re-included closure under the dependent module → b/.dagger/modules/a/… (nesting), and
  2. go-sdk's own withChangesets octopus-merge collided it with the freshly generated, overlapping files → apply ours patch: … already exists.

Only surfaced for Go modules with a closure ≥3 (two consecutive non-empty accumulator iterations); the TypeScript SDK never reproduced it because its generateAll reduces over pws.fork and never folds ws.changes.

pws.fork.changes is an empty changeset (fork.before == fork.after), so folding onto it keeps only each module's own changes — nothing re-enters.

Relationship to #13 (@vito — flagging since this touches your #13 change). #13 deliberately moved generate from reduce(pws.fork){ fork.merge(…) } to .map + changes.{{isEmpty}} + ws.changes.withChangesets(…), to (a) parallelize generation and (b) fix a "no changes to apply" bug (via the {{isEmpty}} force). This fix keeps both of those: it retains the parallel map and the {{isEmpty}} force, and only swaps the fold base ws.changes → pws.fork.changes. So #13's parallelism and its "no changes" fix are preserved — verified below by the idempotent re-run.

I first tried reverting all the way to reduce(pws.fork){ fork.merge } (matching the TS SDK). It worked, but it would have dropped #13's parallel map/force, so I kept #13's structure and made the minimal change instead.

Validated (dev engine + this branch):

Chain Result
a←b←c←d (Go, Go→TS, TS — closure 3) ✅ 0 errors, 0 nested leaks; c/sdk/b.gen.ts, d/sdk/c.gen.ts, b/internal/dagger/a.gen.go all present
a←b←e←f (pure Go — closure 3) ✅ 0 errors, 0 nested leaks; leaf-first bindings correct

Real apply lands every file at the correct path with 0 nested-leak dirs; a second generate reports no changes to apply (idempotent — #13's fix intact).

@TomChv
TomChv marked this pull request as ready for review July 28, 2026 10:10
@TomChv
TomChv merged commit 80e1163 into main Jul 28, 2026
17 checks passed
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