Skip to content

Dependencies between generate functions #13662

Closed

Description

@kpenfound

Generators do not have enough power to resolve their dependency graph that require more generation. For example, a module with a local dependency, which may be using a different SDK

Brief description of the issue, but more thorough recount of discussions below in sipsma's comment:

  • Module codegen responsibility has shifted from the runtime to the SDK module. Codegen is exposed as a normal generator
  • To complete codegen, a module's dependencies must have up to date codegen
  • If you are developing a module with a local dependency which you have made changes to such that both module's codegen are out of date, the dependent module's codegen must be run first so that the module that depends on it can codegen
  • Generators have no concept of ordering or layering, they're all run concurrently and independently
  • The SDK module has no mechanism to request the codegen of a dependency

See also

Activity

  1. added this to the v1.0.0 milestone on Jul 16, 2026
  2. sipsma commented on Jul 16, 2026

    @sipsma
    Contributor

    I was trying to get more concrete details on this, summary below. Disclaimer that it's AI generated from spelunking github+discord but was useful to me.

    Details The core problem is not merely “the list is in the wrong order.” Dagger currently has no dependency model for generate functions:
    • @generate/+generate is only a boolean marker on a module function.
    • dagger generate flattens all selected generators into one group and runs them concurrently.
    • Each generator returns a Changeset; Dagger merges and applies those changes only after every generator has finished.
    • Module dependencies live in a separate graph. The generator scheduler does not connect that graph to generator functions or arrange for one generator’s output to become another’s input.

    This is particularly visible after dagger-module.toml disabled runtime codegen: a dependent module may need its dependency’s committed generated bindings before it can even load. Ordering alone is insufficient unless the earlier changes are also staged into the workspace seen by the later generator.

    Yves’s draft #13661 addresses one narrow part—leaf-first ordering inside one SDK’s managed-module list—but does not yet solve cross-SDK dependencies or establish staged output visibility.

    What “generate functions” means here

    The discussion is about ordinary module functions annotated @generate or +generate, especially SDK modules’ functions such as go-sdk:generate-all, python-sdk:generate-all, and typescript-sdk:generate-all.

    Those generator functions subsequently invoke module codegen and produce generated bindings. This is not primarily the generated-client feature or the engine’s CodeGenerator.Codegen interface, though both are downstream parts of the execution path. The distinction matches the repository’s codegen architecture documentation.

    Current technical model

    1. A generated API/schema marks a function as a generator by setting Function.IsGenerator. There is no dependency, predecessor, module path, or ordering metadata. Function.WithGenerator takes no arguments, and the GraphQL schema describes it only as a flag in core/schema/module.go.

    2. Workspace.generators best-effort loads modules, discovers their annotated functions, and concatenates them into a flat allGenerators slice. core/schema/workspace.go

    3. GeneratorGroup.Run creates one parallel job per generator. There is no topological sort or edge between jobs. core/generators.go

    4. Only after all jobs succeed does the CLI request the combined changes and apply them. internal/cmd/dagger/generators.go and Changeset.WithChangesets

    5. Generating one module’s context loads all of its dependencies as actual modules before invoking SDK codegen. runCodegen and loadDependencyModules

    6. For dagger-module.toml, a dependency runtime cannot repair missing bindings while loading: it must build from committed generated files. That rule is explicit in core/sdk/utils.go and its focused missing-generated-files test.

    The DagQL/cache graph cannot infer the missing generator edge. It only records dependencies when one call consumes another call’s result or ID. Both generators currently consume the original workspace; neither consumes the other’s returned Changeset. Merging patches afterward is output composition, not an execution dependency.

    Minimal concrete example

    Consider two local modules owned by different SDKs:

    # lib-go/dagger-module.toml
    name = "lib-go"
    
    [runtime]
    source = "go"
    # app-py/dagger-module.toml
    name = "app-py"
    
    [runtime]
    source = "python"
    
    [[dependencies]]
    name = "lib-go"
    source = "../lib-go"

    The workspace registers lib-go under the Go SDK’s as-sdk.modules and app-py under the Python SDK’s list.

    The important artifacts are:

    • lib-go/dagger.gen.go and lib-go/internal/dagger/*.gen.go, which are missing or stale.
    • app-py’s generated Python bindings, whose schema must incorporate the lib-go dependency.

    The required execution is:

    module graph:
    app-py ──depends on──> lib-go
    
    required generation:
    go-sdk.generate(lib-go, W0)
      → Δlib
      → W1 = W0.withChanges(Δlib)
      → python-sdk.generate(app-py, W1)
      → Δapp
    

    What happens today:

    1. Bare dagger generate discovers go-sdk:generate-all and python-sdk:generate-all.
    2. GeneratorGroup.Run starts both in parallel against W0.
    3. Go codegen can produce Δlib.
    4. Python codegen for app-py calls loadDependencyModules and tries to load lib-go as a module.
    5. lib-go is still being loaded from W0, where its committed generated Go files are missing. Because it is TOML-configured, runtime codegen cannot repair them, so the Python generator fails.
    6. Even if the Go generator happens to finish first, Δlib is only a returned value. It is not applied until after the Python generator has also succeeded.

    If the Go files are stale but buildable, the more dangerous outcome is that Python generation may succeed against a stale dependency schema. A retry-on-failure scheme would not detect that.

    Leaf-first ordering of CurrentModule.asSDK.modules cannot solve this mixed-SDK example: the Go SDK sees a one-element list containing lib-go, while the Python SDK sees a separate one-element list containing app-py. Neither list contains the cross-SDK edge.

    That is why this cannot be expressed today.

    Why the obvious workarounds are insufficient

    • Manually run SDK generators in separate CLI invocations: This can work if each invocation applies its changes before the next, but the operator must discover and maintain the order. It is not represented or enforced by dagger generate. Yves also hit the prerequisite problem that targeted api call/functions loaded the whole broken workspace; open #13574 addresses that escape hatch.

    • Call one generator from another: A bespoke orchestrator could hard-code calls and use a changed Workspace value, but there is no standard per-module SDK generation operation. Meanwhile the top-level scheduler will still independently run every annotated generator unless those annotations are removed. That loses generic discovery and creates ownership/duplication questions.

    • Return/chaining Changesets: Returning A’s patch does not make it B’s workspace. B must explicitly receive something like W0.withChanges(ΔA), and the current scheduler never constructs that data edge.

    • Constructors: Constructors configure a call or module instance; they do not add scheduler metadata and may themselves require the module to load.

    • Hidden filesystem side effects: Generators are modeled as immutable computations returning Changesets. Host application happens afterward, so side-effect ordering would fight both cache correctness and Dagger’s current execution model.

    • SDK-local generateAll: Current Go, Python, and TypeScript SDKs iterate their own currentModule.asSDK.modules list. For example, Go’s generateAll maps every module from the same ws and merges their generated forks. It has no global view of modules owned by other SDKs.

    Recent chronology

    • June 19–20: Yves opened and merged #13522, adding the minimal CurrentModule.asSDK API so SDK generators could discover the modules they own. Its module entries contain only a path; there is no dependency or generator handle. The corresponding Go SDK PR #4 switched generateAll from filesystem scanning to that API.

    • July 9–13: #13598 established that TOML modules do not perform runtime codegen. Generated files must be committed and repaired through dagger generate, making generation order materially important.

    • July 10: Solomon opened #13605, a related but distinct self-bootstrap cycle: Go codegen imports the generated Go SDK that it is trying to regenerate. A module topological sort cannot fix that; the proposed remedies are a minimal bootstrap client or prebuilt codegen binary.

    • July 13–16: #13620 migrated transitive local modules and registered each under its runtime SDK; #13653 fixed the resulting SDK installs. This exposed real multi-module and potentially mixed-SDK generation graphs.

    • July 15: #13575 made bare generation tolerate modules that cannot yet load. That lets SDK generators attempt repairs, but does not order those repairs.

    • July 16, Discord: In #maintainers, Yves said the flat list is actually a tree and that leaf-first ordering inside one SDK still does not solve a Go → Python → TypeScript chain. He asked whether artifacts or collections could model it. Message 1527197113111543859

    • Minutes later, Yves described being unable to manually generate modules because targeted API calls loaded the entire not-yet-generated workspace. Message 1527198914455928843

    • In #random, Yves characterized one-SDK ordering as tractable but multi-SDK orchestration as unknown. Message 1527304835450405007

    • Solomon proposed walking the workspace dependency DAG, finding the owning SDK for each local module, and recursively invoking that SDK. Message 1527305273046335498

    • After Yves asked who should orchestrate that traversal, Solomon proposed a standard SDK operation such as generateModule(path), alongside initModule and initClient. Message 1527307928250351829 Yves noted that this resembles older, tighter SDK contracts and might be viable. Message 1527308353049727077

    • July 16, GitHub: Yves opened draft #13661, followed shortly by this issue. In the #1.0 sync channel Yves also recalled an earlier declarative form resembling +generate("some/path"). Message 1527353855619240066

    Active options and tradeoffs

    Option What it addresses Main limitation
    Draft #13661: leaf-first asSDK.modules Dependency order among modules owned by one SDK Does not order different SDK generator functions or define staged visibility; its current integration test asserts path order rather than dependent codegen
    Global workspace dependency-DAG traversal Correct cross-SDK module order Engine/CLI must map each module to an SDK-specific action and carry workspace state forward
    Standard generateModule(path) SDK contract Gives a central orchestrator a per-module primitive Tightens the SDK contract; requires versioning, custom-SDK adoption, and a decision about arbitrary generators
    Generatable module tree / artifacts / collections Could represent the graph as typed data Only speculative in Discord; no concrete scheduling or application semantics yet
    Manual targeted generation Useful recovery/debug path Not automatic, declarative, or cache-enforced
    Retry failed generators after dependencies May make missing-file cases eventually pass Nondeterministic, inefficient, and cannot detect stale-but-loadable schemas
    Bootstrap client/prebuilt codegen binary Solves #13605’s self-generation cycle Separate problem; does not solve workspace generator dependencies

    A likely necessary execution primitive is to feed each successful changeset into an immutable workspace overlay before generating its dependents. No concrete design in the discussion has committed to that model yet.

  3. kpenfound commented on Jul 17, 2026

    @kpenfound
    ContributorAuthor

    @shykes discussed live at the 1.0 sync today. In theory today you should only get stuck if you make changes to multiple inter-dependent local modules at the same time without doing codegen in between. Here's the path forward:

    • SDK modules will be CWD aware so that I can cd .dagger/modules/modA && dagger generate and it will only do codegen for that module. Generally this means that rather than searching for modules from / we search from .. This will at least let you get unstuck if you have layers of outdated codegen because you can codegen one by one in the correct order.
    • In the future, this feeds into the Collections feature because I can call generate on a specified path regardless of CWD
    • In the later future, maybe I can request a Directory from the Workspace with generators applied
  4. shykes commented on Jul 18, 2026

    @shykes
    Contributor
    • SDK modules will be CWD aware so that I can cd .dagger/modules/modA && dagger generate and it will only do codegen for that module. Generally this means that rather than searching for modules from / we search from .. This will at least let you get unstuck if you have layers of outdated codegen because you can codegen one by one in the correct order.

    Correct - I'm preparing an issue now to track this here's the issue

    • In the future, this feeds into the Collections feature because I can call generate on a specified path regardless of CWD

    Correct (we think - need to ship Collections to be sure)

    • In the later future, maybe I can request a Directory from the Workspace with generators applied

    To clarify, my thinking is that we would do this sooner than collections, because we have all the required plumbing already - it's likely easier and safer to ship. But of course I would love to ship Collections fast enough that this isn't needed.

    EDIT: also, even with Collections support, there is the question of whether we always want to unilaterally pre-generate any workspace directory as it is accessed - or if we want consuming modules to opt into that.

  5. kpenfound commented on Jul 20, 2026

    @kpenfound
    ContributorAuthor

    even with Collections support, there is the question of whether we always want to unilaterally pre-generate any workspace directory as it is accessed - or if we want consuming modules to opt into that.

    Yeah I could see that as an optional argument for selecting a directory from a workspace

  6. marcosnils commented on Jul 20, 2026

    @marcosnils
    Contributor

    Consensus is that we'll wait for #13688. and then come back here to settle on the final API / UX

  7. kpenfound commented on Jul 21, 2026

    @kpenfound
    ContributorAuthor

    After discussion, we feel there are 3 good options:

    1. A new optional argument for Workspace.Directory(), so that you can call Workspace.Directory(path, { generate: true}) which will run the generators on that directory before returning it, and those generators that we care about are CWD aware. It returns a Workspace that can be overlaid on the current Workspace.
    2. A new API for Workspaces for Generators. This could possibly lead into Collections/Artifacts APIs better. This would be something like Workspace.Generate( { path: path } ). Generate() can take no arguments or filters like path and other things that come later with Collections. It returns a Workspace that can be overlaid on the current Workspace.
    3. A new api in ModuleSource. Something like ModuleSource.GenerateLocalDependencies(). This would be a minimal change for the SDK modules to use and introduces a higher level solution than 1 and 2

    cc @shykes @TomChv

  8. kpenfound commented on Jul 21, 2026

    @kpenfound
    ContributorAuthor

    We have agreed on option 3, described in more detail here: #13706

    We also believe there is a good reason to build option 2 as well, however it is not required at the moment to unblock the codegen issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions