Skip to content

core: order asSDK.modules leaf-first by dependencies - #13661

Closed
eunomie wants to merge 1 commit into
dagger:mainfrom
eunomie:assdk-leaf-first-ordering-bf696c99
Closed

eunomie wants to merge 1 commit into
dagger:mainfrom
eunomie:assdk-leaf-first-ordering-bf696c99

Conversation

@eunomie

@eunomie eunomie commented Jul 16, 2026

Copy link
Copy Markdown
Member

Makes the engine return currentModule.asSDK.modules in leaf-first dependency order — a workspace-managed module's locally-managed dependencies come before it — instead of raw dagger.toml declaration order.

Motivation: SDK code generation over a workspace with many modules (e.g. right after dagger setup) currently generates them in declaration order, which breaks when modules depend on each other. SDK generators (dagger/go-sdk's generateAll) just fold over this list in order, so the fix is engine-side only — zero SDK changes (verified against go-sdk.dang).

  • Ordering is computed once in currentModuleAsSDK (core/schema/module_as_sdk.go), reading each managed module's dagger-module.toml for its [[dependencies]]; currentModuleAsSDKModules stays a pass-through.
  • The graph algorithm is a pure, unit-tested OrderSDKModulesLeafFirst (core/workspace/sdkorder.go): depth-first post-order, dedup by canonical path, edges restricted to the managed set (git/registry, absolute, and out-of-set refs are external leaves).
  • A real dependency cycle errors naming the cycle rather than emitting an arbitrary order — the module loader rejects cycles anyway, so nothing that works today regresses.
  • An unreadable/unparseable managed config degrades to a leaf (no edges) rather than failing generation workspace-wide.
  • No new version gate: only the runtime ordering of an existing list field changes, not its type/shape; the asSDK surface is already View(AfterVersion("v1.0.0-0"))-gated.

Design note: hack/designs/assdk-leaf-first-ordering.md.

Verification

  • go build / go vet / gofmt + go test ./core/workspace/ ./core/schema/ green; staticcheck U1000 clean.
  • e2e (TestGenerators/TestSDKGeneratorModulesLeafFirst): a diamond a → {b, c} → d on the real Go SDK runtime returns exactly d, b, c, a.

No changelog entry: asSDK is unreleased v1-prerelease API, so a changie entry for an unshipped surface would be noise — happy to add one if a reviewer prefers.

SDK code generation over a workspace with many locally-managed modules
folds over currentModule.asSDK.modules in list order. Until now that list
was a pure pass-through of the [[modules.<sdk>.as-sdk.modules]] entries in
dagger.toml declaration order, with zero dependency awareness, so a module
could be regenerated before a locally-managed module it depends on.

Order the list leaf-first in currentModuleAsSDK: read each managed module's
dagger-module.toml, build a dependency graph over the managed set (local deps
only; git/registry and out-of-set refs are external leaves), and emit a
deduplicated topological order (a module's deps before it). A real dependency
cycle between managed modules errors with the cycle named, rather than
emitting an arbitrary order the module loader would reject anyway.

The ordering is engine-side only: SDK generators need no change (verified
against dagger/go-sdk's generateAll). Only the runtime ordering of an existing
list field changes, not its type or shape, so no new version gate is needed;
the asSDK surface is already gated to the v1 view.

Signed-off-by: Yves Brissaud <[email protected]>
@github-actions

Copy link
Copy Markdown
Contributor

This PR is stale because it has been open 14 days with no activity. Remove stale label or comment or this will be closed in 7 days.

@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

This PR was closed because it has been stalled for 7 days with no activity.

@github-actions github-actions Bot closed this Aug 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant