Skip to content

fix: prune only the files this SDK generated, never the directory around them - #99

Merged
TomChv merged 1 commit into
mainfrom
fix/prune-only-generated-87
Oct 13, 2026
Merged

TomChv merged 1 commit into
mainfrom
fix/prune-only-generated-87

Conversation

@TomChv

@TomChv TomChv commented Oct 13, 2026

Copy link
Copy Markdown
Member

Problem

An sdk/ directory inside a module made dagger generate delete files the user
owns, with exit 0 and nothing printed. On the engine the issue was filed against
(v1.0.0-beta.16) it took the whole module directory — hand-written src/, the
manifest, everything — and a second generate re-scaffolded src/index.ts from
the template, so the tree looked healthy afterwards while the user's code was
gone. On v1.0.0-beta.17, which this SDK pairs with, the blast radius is the
removed directory itself: sdk/notes.txt goes unnamed.

Two more sites had the same shape: a legacy .dagger/core/ took everything
under it (and, pre-beta.17, the .dagger/ around it, modules included), and
flipping legacyRuntime on deleted a user's file in clients/ and
entrypoint/.

Fixes #87

Root cause

Three sites removed a directory wholesale instead of removing what this SDK had
written into it (line numbers on main @ d97f678, typescript-sdk.dang):

  • prunedEmbeddedSdk:2012 — ws.withoutDirectory("/" + moduleSdkPath(sourcePath)), the reported case
  • withoutLegacyWorkspaceCore:435 — ws.withoutDirectory("/" + scopeFile(cfg, ".dagger/core"))
  • prunedInactiveDispatch:1833 — withoutDispatcher.withoutDirectory(prefix + dangEntrypointDir), the legacyRuntime flip

The engine primitive is not at fault: withoutDirectory on a nested path keeps
its siblings. #75 had already solved this class for clients/ — ownedFiles
(then ownedClientFiles) decides ownership by shape and prunedOwnedFiles
removes owned-minus-rendered, taking a directory only once nothing is left in
it — and prunedEmbeddedSdk was the follow-up that PR named.

Fix

Same rule, applied to all three:

  • ownedClientFiles → ownedFiles, with its bundle rule read per directory:
    the bundle files are ours beside a client.gen.ts, wherever that sits. That
    is the one shape clients/dagger, the embedded sdk/ and the old
    .dagger/core/typescript share. clients/ behaviour is unchanged — it holds
    no client.gen.ts of its own, only dagger/client.gen.ts.
  • prunedFiles is the removal half on its own, for a directory whose owned set
    is known by name rather than by shape: a module's entrypoint/, which holds
    the generated Dang program and nothing else.
  • The three sites call one of the two. Their intent is kept: an all-generated
    directory still goes whole rather than lingering as a husk of the layout the
    module left.

Verification

Engine v1.0.0-beta.17 throughout.

Reproduced on unmodified main, as the issue describes (scratch workspace
on this SDK, a module scope at verify/app, sdk/notes.txt + sdk/client.gen.ts
planted and committed, dagger generate -y): exit 0, nothing printed, and

 D verify/app/sdk/client.gen.ts
 D verify/app/sdk/notes.txt

The whole-module variant did not reproduce on beta.17 — that half was an engine
bug fixed between beta.16 and beta.17. The SDK-level data loss is what remains,
and is what this fixes.

Same workspace with the fix — two module scopes (verify/app,
.dagger/modules/deep) plus a planted legacy .dagger/core:

 D .dagger/core/typescript/client.gen.ts
 D .dagger/core/typescript/index.ts
 D .dagger/core/typescript/package.json
 D .dagger/modules/deep/sdk/client.gen.ts
 D verify/app/sdk/client.gen.ts

verify/app/sdk/notes.txt, .dagger/modules/deep/sdk/notes.txt,
.dagger/core/notes.txt and every .dagger/modules/* survive.

New regression checks (.dagger/modules/e2e/generate.dang), each red
without the fix — proven on a scratch copy of this branch with
typescript-sdk.dang reverted to origin/main:

Check Failure without the fix
generate:generate-keeps-user-files-in-sdk-dir-check a user's file in a module's sdk/ must survive the move onto an entrypoint, kept [...] — no sdk/ in the tree at all
generate:generate-prunes-legacy-workspace-core-check generation took .dagger/core whole, with a user's file in it, got removed [.dagger/core/]
generate:generate-flips-back-keeps-user-files-check a user's file in a module's entrypoint/ must survive the flip, kept [...]

Each asserts the resulting tree, not only the changeset, and each also asserts
the intent that was there: the emptied sdk/, .dagger/core/typescript/,
clients/dagger/ and entrypoint/ still go.

Runs (all green, check -m .dagger/modules/e2e):

  • the three new checks — 3 passed
  • generate:generate-check, generate:generate-idempotent-check,
    generate:generate-prunes-entrypoint-check,
    generate:generate-keeps-user-files-in-clients-dir-check,
    generate:generate-flips-back-to-runtime-check,
    generate:generate-flips-back-with-client-check + the three new — 9 passed
  • client:* — 13 passed
  • generate:generate-prunes-stale-bindings-check,
    generate:generate-workspace-module-check,
    generate:generate-compat-shim-pruned-check,
    generate:generate-every-scope-check,
    generate:generate-source-edit-is-scoped-check — 5 passed

Not covered

  • The full check suite was not run here (init:*, runtimes:*, manifest:*,
    discovery:*, sdk:*, registry:*); nothing in those paths touches pruning.
  • Applying the fix leaves an empty .dagger/core/typescript/ directory on disk
    in the two-scope CLI run, although the changeset records the directory removal
    and the in-engine tree has it gone. Cosmetic, and idempotent on the next run
    (the emptied directory owns nothing, so it is a no-op); looks like an apply
    artifact rather than something this change introduced.
  • The legacyRuntime flip is covered by the e2e check, not by a CLI run — it
    needs the setting written into dagger.toml by hand.
  • .dagger/core/typescript's owned set is taken from the design doc that
    described that layout (design/unified-clients-shared-core.md): the vendored
    @dagger.io/dagger package. A file that layout wrote under some other name
    would now be left behind rather than deleted.

…und them

Three prune sites took a directory whole. A file the user had put inside one
went with it, and on an engine before v1.0.0-beta.17 so did the directory
around it: an `sdk/` left over from the embedded layout deleted the module it
sat in — hand-written `src/` included — with exit 0 and nothing printed
(issue #87).

The rule #75 gave `clients/` now covers all three: remove what this SDK
generated and nothing else, and take a directory only once the removals leave
nothing in it.

- `ownedClientFiles` becomes `ownedFiles`, and its bundle rule is read per
  directory — the bundle files are ours beside a `client.gen.ts`, wherever
  that sits, which is what makes `clients/dagger`, the embedded `sdk/` and the
  old `.dagger/core/typescript` the same shape. `clients/` is unaffected: it
  has no `client.gen.ts` of its own.
- `prunedFiles` is the removal half on its own, for a directory whose owned
  set is known by name rather than by shape: a module's `entrypoint/`, which
  holds the generated Dang program.
- `prunedEmbeddedSdk`, `withoutLegacyWorkspaceCore` and the `entrypoint/`
  removal in `prunedInactiveDispatch` go through it. Their intent is kept —
  an all-generated directory still goes whole, rather than lingering as a husk
  of the layout the module left.

Signed-off-by: Tom Chauveau <[email protected]>
@TomChv
TomChv force-pushed the fix/prune-only-generated-87 branch from 3d361a3 to c815b07 Compare October 13, 2026 11:50
@TomChv
TomChv merged commit bdc192a into main Oct 13, 2026
5 checks passed
TomChv added a commit that referenced this pull request Oct 19, 2026
…le (#110)

`dagger generate` deleted a user's directory. Any direct child of a
TypeScript scope that holds a file named after it — types/types.gen.ts,
api/api.gen.ts, graphql/graphql.gen.ts, the layout an openapi or graphql
codegen writes — was removed whole, every file of the user's in it, exit 0
and nothing printed.

prunedClientPackages migrates the layout that wrote each client as a
package at the scope root, and it recognized one by that marker alone and
took the directory with withoutDirectory. It was the last wholesale
removal over a path whose contents are not all this SDK's: #99 made every
sibling prune ownership-based — prunedOwnedFiles, prunedFiles,
prunedEmbeddedSdk, withoutLegacyWorkspaceCore — and this one was outside
that scope. Its own docstring and the README already claimed the rule it
did not follow.

Route it through prunedFiles with the set ownedFiles claims, the same rule
the siblings use: the generated files go, and the directory follows only
once nothing is left in it. Ownership is read from a synthetic parent
because ownedFiles knows a package's manifest as <name>/package.json, the
depth the layout gave it — so an all-generated package still goes whole,
manifest included, rather than lingering as a husk.

Both call sites are covered by a check that fails without the fix: a
module scope on the entrypoint path, and a client-only scope. Each asserts
the resulting tree, and each asserts the other half too, so the intent
survives.

Signed-off-by: Tom Chauveau <[email protected]>
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.

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

1 participant