Repository navigation
fix: remove only what the SDK generates from clients/ - #75
Merged
Merged
Conversation
grouville
self-requested a review
October 9, 2026 06:48
grouville
approved these changes
Oct 9, 2026
`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
force-pushed
the
fix/clients-ownership
branch
from
October 9, 2026 11:40
b62a4e0 to
b7cc89e
Compare
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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Decision: user files must survive; a removed client's generated files do go.
Root cause
Three sites in
typescript-sdk.dang(line numbers at8a7c580) treatedclients/as a fully generated directory:clientScope,targets.length == 0branch —typescript-sdk.dang:1882:ws.withoutDirectory("/" + dir)wiped the wholeclients/when the last target left.dagger module client rmis the engine'sWorkspace.withoutClientdropping the record and callinggenerateScopewith 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 fromclientScope(:1891) and from the entrypoint path ofmoduleFiles(: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 tookapp/clients/notes.txtandapp/clients/other/notes.txtin the transcript.prunedEmbeddedClientsDir—typescript-sdk.dang:1475-1480, the legacy[runtime]module path, on every generation: removed a module-rootclients/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.tsunderclients/— 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 thepackage.jsonof a<name>/directory that holds<name>.gen.ts, and indagger/, whendagger/client.gen.tsis present, itspackage.jsonand the bundle files. The bundle list is nowcoreBundleFiles, shared bymoduleSdkDirectory,embeddedSdkDirectoryand the rule, so the two cannot drift. No client names are enumerated.prunedOwnedFiles(ws, dir, generated)replacesprunedDirFiles: 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-generatedclients/therefore still disappears entirely when the last target leaves (remove-clients-checkkeeps its<dir>/expectation), while aclients/holding a user file stays, and a package directory holding one stays with its generated files gone.node_modulesis never owned and never counted, as before: it goes only with the directory it was installed into.withoutDirectorywipes are routed through it:clientScopewith no targets prunes against an empty render, andprunedEmbeddedClientsDirdoes the same for a legacy-layout module'sclients/— stale flat<m>.gen.tsfiles still go, a user file there survives.Checks:
fixtures/client/existinggainsclients/notes.mdandclients/stale-dep/README.mdbeside the stale flatclients/stale-dep.gen.ts.generate-client-respects-existing-checkasserts both survive (not inremovedPaths, present in the resulting tree) whilestale-dep.gen.tsis still removed;generate-client-on-synthetic-workspace-checkasserts the same on the synthetic tree.remove-clients-checkis unchanged. Newremove-clients-keeps-user-files-checkplants a user file underclients/and one inside the generatedclient-app/package before dropping the last target, and asserts the generated files and the emptieddagger/package go, the user files stay, andclients/andclient-app/remain.generate-keeps-user-files-in-clients-dir-check(generate.dang): a legacy-layout module whoseclients/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) withDAGGER_LEAVE_OLD_ENGINE=1; no cloud engine.Parse gates after the edits, both clean:
Checks, run from a scratch copy of this branch with
.dagger/modules/engine-e2e/workspace.tomlas itsdagger.toml(the checkout's owndagger.tomlonly exposesengine-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:And the whole workspace suite (70 checks: e2e, packager, registry, runtimes, sdk), which ran to completion four times on this branch:
packager/library-bindings/staleis the known red on unmodifiedmainwith 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,targetandotherinitialized with--legacy-runtime,app/annpm init -yproject with both clients added, the twonotes.txtfiles committed, thendagger -y module client rm ./otherfromapp/.Before, on
8a7c580:After, on this branch — only
other's own generated files and the wiring change, and both notes files stay:app/clients/other/survives because it still holds the user'snotes.txt; had it held nothing else it would have gone with its last generated file, asclients/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:1726on main) deletes a module'ssdk/wholesale on the entrypoint path.prunedClientPackages(:1937) deletes a scope-level<name>/directory wholesale when it carries a<name>.gen.ts.withoutLegacyScopeClients(:1902) andwithoutLegacyWorkspaceCore(:400) delete the earlier layouts'.dagger/clientsand.dagger/corewholesale;generate-client-respects-existing-checkstill 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).