Skip to content

🐞 0.21.0 gives result *core.ModuleObject is detached error #13246

Open

Description

@marcofranssen

What is the issue?

Since I bumped from dagger 0.20.8 to 0.21.0 I see following error:

result *core.ModuleObject is detached

Dagger version

dagger v0.20.8 (image://registry.dagger.io/engine:v0.20.8) darwin/arm64/v8

Steps to reproduce

Not sure, might be related to our own modules. I would appreciate it if someone can point me at how to troubleshoot/further debug to deliver more info in this issue.

I checked the release notes, but couldn't identity the root cause, or changes I have to make in our modules.

Log output

No response

Activity

  1. marcofranssen commented on May 28, 2026

    @marcofranssen
    Author

    After upgrading from Dagger 0.20.8 to 0.21.0, module methods started failing with:

    result *core.ModuleObject is detached

    The issue was caused by storing dependency module objects inside exported module
    state, for example keeping a *dagger.SomeDependencyModule field on a module struct
    and returning that struct from chained methods.

    That pattern worked in 0.20.8, but in 0.21.0 the dependency module object can
    become detached when Dagger serializes/deserializes module state between calls.

    Example Failure Pattern

    Before:

      type MyModule struct {
          Tool *dagger.Tool
      }
    
      func (m *MyModule) WithConfig(value string) *MyModule {
          m.Tool = m.Tool.WithConfig(value)
          return m
      }
    
      func (m *MyModule) Run(ctx context.Context) (string, error) {
          return m.Tool.Run(ctx)
      }

    This can fail because Tool is itself a module object. After WithConfig returns
    MyModule, the stored Tool object may no longer be attached to the active query
    graph.

    Fix

    Do not store dependency module objects in module state. Store only serializable
    configuration or core Dagger values, then reconstruct the dependency module object
    when needed.

    After:

      type MyModule struct {
          ConfigValue string
      }
    
      func (m *MyModule) tool() *dagger.Tool {
          return dag.Tool().WithConfig(m.ConfigValue)
      }
    
      func (m *MyModule) WithConfig(value string) *MyModule {
          m.ConfigValue = value
          return m
      }
    
      func (m *MyModule) Run(ctx context.Context) (string, error) {
          return m.tool().Run(ctx)
      }

    Result

    After replacing persisted dependency module fields with plain state and helper
    methods that rebuild dependency clients, the module works on Dagger 0.21.0. The
    fix keeps module state serializable and avoids carrying detached ModuleObject
    instances across function boundaries.

  2. marcofranssen commented on May 28, 2026

    @marcofranssen
    Author

    Feel free to close the issue, leaving it open as this might be something that has to be improved in documentation.

  3. sipsma commented on Jun 1, 2026

    @sipsma
    Contributor

    This is most likely a bug, will see if I can repro and fix if so

    EDIT:

    On deeper inspection I am less sure about what's happening here.

    @marcofranssen When I try to do a repro close to the description even on v0.20.8 I get this error: object "Repro" field "Tool" cannot reference external type from dependency module "tool"

    Which is expected. What I am confused about is that it never worked, even on that version. Can you give a more detailed repro in case I am missing something?

  4. wvell commented on Jun 1, 2026

    @wvell
    Contributor

    @marcofranssen Thank you for your detailed issue. We ran into the same issue and your solution seems to fix it for us.

  5. sipsma commented on Jun 1, 2026

    @sipsma
    Contributor

    If others hitting this can provide their own repro I would highly appreciate it. *core.ModuleObject is detached shouldn't happen and indicates a bug. However the original repro in the description doesn't yet have enough details for me to actually reproduce the bug yet.

    With another user I did fine a case where using cache="never" could cause this, so would like to know if that's why everyone else is hitting this or if there's something else that could also cause this error.

  6. marcofranssen commented on Jun 2, 2026

    @marcofranssen
    Author

    @sipsma yes we do have some cache="never" in the nested modules indeed.

    @sipsma if we can connect on slack or discord I could show you how to reproduce.

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

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions