Repository navigation
Conversation
Writing a directory into a workspace path had one spelling, withNewDirectory, and it meant two things. On a host-backed checkout it replaced what was there; on a workspace loaded from a Directory or from git it merged. Every SDK writes its scaffolding and its generated clients through that call, so which one you got decided whether `dagger module init` left the user's files alone or deleted them. Add withDirectory for the merge, defined the way Directory.withDirectory is: the source lands on top of what the path already holds and takes nothing else with it. The two overlay branches underneath disagree because they hand the edit different bases. A value or git workspace edits its full read root, where the path holds the workspace's own content. A host-backed one edits a delta root holding only what earlier edits wrote — it never references the host tree, which is what keeps an edit from uploading the whole checkout — and its changeset comes from diffing that against a host base scoped to the touched paths. An edit that layers onto the path finds it empty there, so everything the host has under it diffs against nothing and reads as removed. overlayEdit now takes the paths whose existing content an edit builds on, and seeds the delta root with them first. The seed comes out of the very base the changeset is diffed against, and the overlay records which paths it seeded so that every later edit re-seeds them from its own base. Content the caller never wrote must not sit pinned on the after side: a file they edit on disk meanwhile would come back reported as modified to whatever the host held at seeding time, and exporting would write that over their edit. Signed-off-by: Yves Brissaud <[email protected]>
withNewDirectory replaced what a path held on a host-backed checkout and merged into it on a workspace loaded from a Directory or from git. Nothing in the API said which you would get; only where the workspace came from decided. A guard that leaned on the replacement passed locally and quietly stopped asserting anything in CI, where the same repo arrives as a git workspace, and the reverse cost the SDKs the files a user already had at the destination. Settle it as replacement everywhere. It is the one of the two that cannot be built from the other: layering onto a path is now withDirectory, while emptying a path first, then writing into it, would have to read the destination back to know what to clear. So the edit clears the path before it copies, on either overlay branch. That is also what makes the two agree: an edit whose result at the path owes nothing to what the base held there reads the same on a full read root as on a host overlay's delta root, which holds only what earlier edits wrote. Replacement now covers those earlier edits too — the path ends up holding the source and nothing else, whichever kind of workspace it is. Signed-off-by: Yves Brissaud <[email protected]>
Signed-off-by: Yves Brissaud <[email protected]>
Signed-off-by: Yves Brissaud <[email protected]>
eunomie
force-pushed
the
withnewdirectory-replace-merge-fix-lead-1faef34f
branch
from
August 24, 2026 16:43
f524506 to
1fa82bb
Compare
eunomie
marked this pull request as ready for review
August 24, 2026 17:34
TomChv
approved these changes
Aug 25, 2026
TomChv
left a comment
Member
There was a problem hiding this comment.
Tested with my repro and it fixes both inconsistency in withNewDirectory + withDirectory work as expected.
withNewDirectory - host-backed removed:
target/keep.txt
withNewDirectory - synthetic removed:
target/keep.txt
withDirectory - host-backed removed:
withDirectory - synthetic removed:
Great fixes
This was referenced Aug 25, 2026
This was referenced Aug 27, 2026
Merged
eunomie
added a commit
to dagger/python-sdk
that referenced
this pull request
Aug 27, 2026
Both places this SDK writes a directory into a workspace wanted a merge, not a replacement, and beta.10 only had `Workspace.withNewDirectory`, which replaces. Each therefore read the destination back out of the workspace, merged the new content onto it by hand, and wrote the result: init so it never deletes files a user already put at the module path, generation so a generated context holding only generated files does not remove everything else the module owns. `dagger/dagger#13956` made `withNewDirectory` replace consistently — it merged on synthetic workspaces and replaced on host-backed ones — and added `Workspace.withDirectory`, which merges with `Directory.withDirectory`'s semantics: what is already at the path stays, the source wins on conflict. That is exactly what the read-back-and-merge was reproducing, so call it directly and drop the scaffolding, including the `existingDir` helper that had no other caller. The `generatedContextDirectory` overlay in `Mod.generate` stays as it is: it works around `dagger/dagger#13947`, a different defect, still open on beta.11. Verified on a real workspace with beta.11: `dagger module init python` onto an empty path scaffolds the module, and onto a path already holding `keepme.txt`, `src/user_notes.py` and a stray `sdk/stray.txt` leaves all three in place while laying the template and the vendored library over them. Signed-off-by: Yves Brissaud <[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.
Fixes #13955.
Same call, same source, same path — two different answers depending on where the
workspace came from:
A host-backed checkout replaced whatever was at the path; a workspace loaded from
a
Directoryor from git merged into it. Every SDK writes its scaffolding and itsgenerated clients through
Workspace.withNewDirectory, so on a real checkoutdagger module initdeleted whatever was already at the destination — the user'sfiles, and the module config the engine itself had just written. It was found and
worked around separately in dagger/go-sdk#30, dagger/python-sdk#14 and
dagger/typescript-sdk#35, each time by reading the destination back and layering
onto it by hand.
The split also hides in the other direction: a guard that leans on the
replacement passes locally and quietly stops asserting anything in CI, where the
same repo arrives as a git workspace.
What changes
Workspace.withNewDirectorynow replaces on every kind of workspace, and the newWorkspace.withDirectorymerges on every kind — the same contractDirectory.withDirectoryhas. Callers pick the one they mean instead of the onetheir workspace happens to give them:
The read-back the three SDKs each wrote by hand is now the second field.
Where the split came from
overlayEdithands the edit two different bases. A value or git workspace editsits full read root, where the path holds the workspace's own content. A
host-backed one edits a delta root holding only what earlier edits wrote — it
never references the host tree, which is what keeps an edit from uploading the
whole checkout — and its changeset comes from diffing that against a host base
scoped to the touched paths. An edit that layers onto the path finds it empty
there, so everything the host has under it diffs against nothing and reads as
removed.
So:
withNewDirectoryclears the path before it copies, on either branch. An editwhose result owes nothing to what the base held reads the same on both.
overlayEditgained an explicitreadsExisting— the touched paths whoseexisting content an edit builds on — and seeds the host-backed delta root with
them first. That invariant is what was missing.
The seed comes out of the very base the changeset is diffed against, and the
overlay records which paths it seeded so every later edit re-seeds them from its
own base. Content the caller never wrote must not sit pinned on the after side: a
file they edit on disk meanwhile would come back reported as modified to whatever
the host held at seeding time, and exporting would write that over their edit.
Tests
Both fields, against all three workspace kinds (host-backed, value, git): writing
over existing content, writing to a path that does not exist, composing with
earlier overlay edits, and not resurrecting content an earlier edit removed. Plus
the issue's own comparison, the host-content-staleness regression above, and
dagger module initend to end against a destination that already holds a file.Reverting the fix fails exactly the predicted subtests —
withNewDirectorymerging on value and git,
withDirectoryreplacing on host-backed — and themodule-init test deletes the user's file.