Skip to content

fix: remove only what the SDK generates from clients/ - #75

Merged
TomChv merged 1 commit into
mainfrom
fix/clients-ownership
Oct 9, 2026
Merged

TomChv merged 1 commit into
mainfrom
fix/clients-ownership

Conversation

@TomChv

@TomChv TomChv commented Oct 8, 2026

Copy link
Copy Markdown
Member

Problem

#29 [TypeScript SDK] client rm deletes user files anywhere in clients/ — case E9.
Including files outside the removed client's folder. Decision needed.

From the E9 write-up (host app/ with clients ./target, ./other):

echo "user notes" > app/clients/other/notes.txt
echo "user notes" > app/clients/notes.txt
git add -A && git commit -m userfiles
cd app && dg -y module client rm ./other
git status --short
 D app/clients/notes.txt
 D app/clients/other/notes.txt
 D app/clients/other/other.gen.ts
 D app/clients/other/package.json
 M app/clients/target/package.json
 M app/package.json
 M dagger.toml

"The plan expects user files in the client directory to stay. The SDK prunes everything under clients/ it did not render, including a file outside the removed client's own directory." Decisions needed: "client rm: should it remove generated client files? Go keeps them (its own e2e asserts this); TypeScript deletes everything in clients/, user files included."

— SDK Main-Engine Test Run, 2026-10-07 — issue #29, case E9.

Decision: user files must survive; a removed client's generated files do go.

Root cause

Three sites in typescript-sdk.dang (line numbers at 8a7c580) treated clients/ as a fully generated directory:

  • clientScope, targets.length == 0 branch — typescript-sdk.dang:1882: ws.withoutDirectory("/" + dir) wiped the whole clients/ when the last target left. dagger module client rm is the engine's Workspace.withoutClient dropping the record and calling generateScope with the remaining set, so this is the path when the removed client was the last one; with a target left, the next site is.
  • prunedDirFiles — typescript-sdk.dang:1505, fed from clientScope (:1891) and from the entrypoint path of moduleFiles (:1450): removed every file under the directory that this run did not render (node_modules excepted) and every subdirectory not in the generated tree. This is what took app/clients/notes.txt and app/clients/other/notes.txt in the transcript.
  • prunedEmbeddedClientsDir — typescript-sdk.dang:1475-1480, the legacy [runtime] module path, on every generation: removed a module-root clients/ wholesale.

Fix

One ownership rule, used by all three sites: the SDK removes only what it generates, and a directory only once nothing is left in it.

  • ownedClientFiles(dir) decides ownership by shape rather than by remembering what a previous run wrote (nothing remembers, and the layout has changed more than once): every *.gen.ts under clients/ — flat <m>.gen.ts, loader.gen.ts, <m>/<m>.gen.ts, dagger/client.gen.ts, and whatever a later layout adds under that suffix — plus the package.json of a <name>/ directory that holds <name>.gen.ts, and in dagger/, when dagger/client.gen.ts is present, its package.json and the bundle files. The bundle list is now coreBundleFiles, shared by moduleSdkDirectory, embeddedSdkDirectory and the rule, so the two cannot drift. No client names are enumerated.
  • prunedOwnedFiles(ws, dir, generated) replaces prunedDirFiles: removals = owned − this run's output. A directory the removals empty goes whole, at any depth; one still holding anything else stays — clients/ itself included. An all-generated clients/ therefore still disappears entirely when the last target leaves (remove-clients-check keeps its <dir>/ expectation), while a clients/ holding a user file stays, and a package directory holding one stays with its generated files gone. node_modules is never owned and never counted, as before: it goes only with the directory it was installed into.
  • Both withoutDirectory wipes are routed through it: clientScope with no targets prunes against an empty render, and prunedEmbeddedClientsDir does the same for a legacy-layout module's clients/ — stale flat <m>.gen.ts files still go, a user file there survives.
  • README: the "complete desired set" paragraph now says what survives.

Checks:

  • fixtures/client/existing gains clients/notes.md and clients/stale-dep/README.md beside the stale flat clients/stale-dep.gen.ts. generate-client-respects-existing-check asserts both survive (not in removedPaths, present in the resulting tree) while stale-dep.gen.ts is still removed; generate-client-on-synthetic-workspace-check asserts the same on the synthetic tree.
  • remove-clients-check is unchanged. New remove-clients-keeps-user-files-check plants a user file under clients/ and one inside the generated client-app/ package before dropping the last target, and asserts the generated files and the emptied dagger/ package go, the user files stay, and clients/ and client-app/ remain.
  • New generate-keeps-user-files-in-clients-dir-check (generate.dang): a legacy-layout module whose clients/ holds a user file keeps it across generation, while a stale flat client there is pruned.

Verification

Engine: dagger --x-release=55e112468d5b08e3a8746e7e74a4dc38898cf07a (v1.0.0-beta.17 at 55e11246) with DAGGER_LEAVE_OLD_ENGINE=1; no cloud engine.

Parse gates after the edits, both clean:

dagger --x-release=55e112468d5b08e3a8746e7e74a4dc38898cf07a -m . functions
dagger --x-release=55e112468d5b08e3a8746e7e74a4dc38898cf07a -m .dagger/modules/e2e functions

Checks, run from a scratch copy of this branch with .dagger/modules/engine-e2e/workspace.toml as its dagger.toml (the checkout's own dagger.toml only exposes engine-e-2-e:*, which builds whole engines).

The client group, which is where this change lives — all nine, including the new remove-clients-keeps-user-files-check:

dagger --x-release=55e112468d5b08e3a8746e7e74a4dc38898cf07a check -m .dagger/modules/e2e "e-2-e:client:*"
== CHECKS ==  ✔ 9 passed
✔ client/client-vendors-library-check                 ✔ client/module-scope-client-bindings-check
✔ client/generate-client-check                        ✔ client/multiple-clients-check
✔ client/generate-client-compiles-check               ✔ client/remove-clients-check
✔ client/generate-client-on-synthetic-workspace-check ✔ client/remove-clients-keeps-user-files-check
✔ client/generate-client-respects-existing-check

And the whole workspace suite (70 checks: e2e, packager, registry, runtimes, sdk), which ran to completion four times on this branch:

dagger --x-release=55e112468d5b08e3a8746e7e74a4dc38898cf07a check -m .dagger/modules/e2e
== CHECKS ==  ✘ 1 failed  ✔ 69 passed   (three runs; the one red is packager/library-bindings/stale)
== CHECKS ==  ✔ 70 passed               (one run)

packager/library-bindings/stale is the known red on unmodified main with this engine — the committed library bindings target beta.15 — and is untouched here; it came out green on one of the four runs. Both new checks (client/remove-clients-keeps-user-files-check, generate/generate-keeps-user-files-in-clients-dir-check) passed in every run. The coordinator is re-running the full suite on this branch independently.

Manual repro — the E9 transcript as written: a workspace with this SDK installed from .dagger/modules/typescript-sdk, target and other initialized with --legacy-runtime, app/ an npm init -y project with both clients added, the two notes.txt files committed, then dagger -y module client rm ./other from app/.

Before, on 8a7c580:

$ git status --short
 D app/clients/notes.txt
 D app/clients/other/notes.txt
 D app/clients/other/other.gen.ts
 D app/clients/other/package.json
 M app/clients/target/package.json
 M app/package.json
 M dagger.toml

After, on this branch — only other's own generated files and the wiring change, and both notes files stay:

$ git status --short
 D app/clients/other/other.gen.ts
 D app/clients/other/package.json
 M app/clients/target/package.json
 M app/package.json
 M dagger.toml

$ find app/clients -type f | sort
app/clients/dagger/client.gen.ts
app/clients/dagger/core.d.ts
app/clients/dagger/core.js
app/clients/dagger/index.ts
app/clients/dagger/package.json
app/clients/dagger/telemetry.ts
app/clients/notes.txt
app/clients/other/notes.txt
app/clients/target/package.json
app/clients/target/target.gen.ts

app/clients/other/ survives because it still holds the user's notes.txt; had it held nothing else it would have gone with its last generated file, as clients/dagger/ does when the last target leaves.

Not covered / follow-ups

Same class of bug, not in the matrix row, left as they are:

  • prunedEmbeddedSdk (typescript-sdk.dang:1726 on main) deletes a module's sdk/ wholesale on the entrypoint path.
  • prunedClientPackages (:1937) deletes a scope-level <name>/ directory wholesale when it carries a <name>.gen.ts.
  • withoutLegacyScopeClients (:1902) and withoutLegacyWorkspaceCore (:400) delete the earlier layouts' .dagger/clients and .dagger/core wholesale; generate-client-respects-existing-check still asserts the former.

Also noticed, unrelated to the fix: the README's client-scope table and install examples still say .dagger/clients/, while the SDK writes <scope>/clients/ (which is what the E9 transcript shows).

`dagger module client rm` deleted every file under a scope's clients/ that
the run did not render — a user's notes.txt inside the removed client's
package and one beside the packages — and the last target leaving wiped the
directory whole. Three sites treated clients/ as fully generated:
clientScope's empty-target branch (withoutDirectory on clients/),
prunedDirFiles (clientScope with targets left, and the entrypoint path of
moduleFiles), and prunedEmbeddedClientsDir (a legacy-layout module's
clients/, on every generation).

One ownership rule now serves all three, decided by shape rather than by
remembering what a previous run wrote: nothing remembers, and the layout has
changed more than once. Owned is every *.gen.ts under clients/, a
package.json beside the <name>.gen.ts that names its package, and the bundle
files beside dagger/client.gen.ts. Removals are the owned set minus this
run's output, and a directory goes only once nothing is left in it — so an
all-generated clients/ still disappears whole when the last target leaves,
while one holding a user's file stays, package directories included.

Reported as SDK Main-Engine Test Run 2026-10-07, issue #29 (case E9).

Signed-off-by: Tom Chauveau <[email protected]>
@TomChv
TomChv force-pushed the fix/clients-ownership branch from b62a4e0 to b7cc89e Compare October 9, 2026 11:40
@TomChv
TomChv merged commit 1f25a4f into main Oct 9, 2026
5 checks passed
TomChv added a commit that referenced this pull request Oct 13, 2026
…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 added a commit that referenced this pull request Oct 13, 2026
…und them (#99)

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]>
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.

2 participants