Skip to content

Data loss: an sdk/ directory in a module makes dagger generate delete the whole module, including the user's source #87

Closed

Description

@TomChv

Severity

dagger generate deletes a module's entire directory, including hand-written src/, with exit 0 and no output. A second generate re-scaffolds src/index.ts from the template, so the tree looks healthy afterwards while the user's code is gone.

The trigger — an sdk/ directory inside the module — is exactly what a module migrating off the pre-1.0 embedded layout has.

Reproduced independently twice, on main @ d97f678, engine v1.0.0-beta.16.

Repro (5 lines from a clean, committed tree)

dagger init -y && dagger install dagger.io/sdk/typescript@main
dagger module init typescript --name app -y
mkdir .dagger/modules/app/sdk && echo user > .dagger/modules/app/sdk/notes.txt
git add -A && git commit -m plant        # tree clean
dagger generate -y                        # exit 0, "✔ 1 passed", prints nothing
git status --porcelain
 D .dagger/modules/app/__dagger.dispatch.ts
 D .dagger/modules/app/clients/dagger/client.gen.ts
 D .dagger/modules/app/clients/dagger/core.d.ts
 D .dagger/modules/app/clients/dagger/core.js
 D .dagger/modules/app/clients/dagger/index.ts
 D .dagger/modules/app/clients/dagger/package.json
 D .dagger/modules/app/clients/dagger/telemetry.ts
 D .dagger/modules/app/clients/loader.gen.ts
 D .dagger/modules/app/dagger-module.toml
 D .dagger/modules/app/entrypoint/main.dang
 D .dagger/modules/app/package.json
 D .dagger/modules/app/sdk/notes.txt
 D .dagger/modules/app/src/index.ts
 D .dagger/modules/app/tsconfig.json

.dagger/modules/app/ no longer exists on disk. --no-apply previews this as .dagger/ -1 / 1 file changed, -1 lines — it names nothing and understates it by 13 files.

Where it comes from

moduleFiles() → prunedEmbeddedSdk() (typescript-sdk.dang), which does
ws.withoutDirectory("/" + moduleSdkPath(sourcePath)) to clean up the pre-1.0 layout.

The engine primitive is not at fault — a direct probe keeps siblings correctly:

dagger -c 'current-workspace | without-directory /a/b/target | directory /a | glob "**"'
# -> b/keepme.txt, sibling/, top.txt all retained

A second prune site has the same blast radius: a legacy .dagger/core/old.txt triggers
withoutLegacyWorkspaceCore() and the whole of .dagger/ goes, modules included. Two call sites, one symptom — this looks like a composition bug in moduleFiles/the prune helpers rather than a typo in either.

Blast radius is pinned:

Shape Result
sdk/ at the workspace root, no module nothing deleted
module installed at scope "." only sdk/notes.txt deleted — src/index.ts and unrelated files survive
module at a nested scope (the normal .dagger/modules/app) whole module directory deleted
a file named sdk, or lib/ sdks/ dist/ left alone

The root-vs-nested split is the clue: with scope "." the path has no parent to clobber.

Related

prunedEmbeddedSdk was already flagged as a follow-up when #75 landed the ownership rule for clients/ — it is the one prune site that still removes a directory wholesale. The fix is presumably the same shape: remove only what the SDK generated, and only empty directories.

Suggested regression tests

  1. sdk/ directory inside a module → generate removes sdk/ and nothing else.
  2. Legacy .dagger/core/ present → generate does not touch .dagger/modules/*.
  3. Plant a user file in every generated directory (sdk/, clients/, entrypoint/, src/, module root), regenerate, assert nothing disappears.

Found during a full verification sweep of @main; repros kept at verify/wild/w15f-default, w15e-1, w15e-2, w15e-3, w15g-engine in the playground worktree.

Activity

  1. added
    bug
    on Oct 12, 2026
  2. TomChv commented on Oct 12, 2026

    @TomChv
    MemberAuthor

    Third site with the same shape, found in the same sweep: flipping legacyRuntime deletes user files.

    With legacyRuntime = true set on an entrypoint module and a regenerate, a user's clients/my-helper.ts and entrypoint/MY-NOTES.md are both deleted. Exit 0, nothing printed. Removing the directories is documented intent for a layout flip; taking the user's files with them unnamed is not.

    So the fix wants to cover all three: prunedEmbeddedSdk, withoutLegacyWorkspaceCore, and the flip path's directory removal — same rule as #75 gave clients/: remove only what the SDK generated, and a directory only once it is empty. Repro: verify/wild/w16-flip.

  3. TomChv commented on Oct 13, 2026

    @TomChv
    MemberAuthor

    Correction: the whole-module deletion is an engine bug, already fixed in beta.17

    I wrote this issue against engine v1.0.0-beta.16. Re-running the same repro on v1.0.0-beta.17, from a clean committed tree with an extra src/mine.ts planted:

    $ dagger generate -y          # exit 0
    $ git status --porcelain
     D .dagger/modules/app/sdk/notes.txt
    $ ls .dagger/modules/app/src/
    index.ts  mine.ts
    

    Only the user's file inside sdk/ is lost. src/ and the module directory survive. Verified independently twice, and the agent fixing this reproduced the same on beta.17 at two different scope depths.

    So the catastrophic half — the whole module directory, including hand-written source — was an engine bug between beta.16 and beta.17, not the SDK, and it is already gone. The SDK bug that remains is real but confined: a wholesale withoutDirectory takes the user's files with the generated ones, in sdk/, .dagger/core/, and entrypoint/ (where MY-NOTES.md is still lost on a legacyRuntime flip — clients/ is already safe thanks to #75).

    Severity is therefore data loss, scoped to a file a user placed in a generated directory — not "a plain generate destroys your module". The "do not tag without this" line in my original report was wrong on beta.17; apologies for the alarm.

    Fix in #99, which applies #75's ownership rule to the three remaining sites.

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

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions