Skip to content

Apply only the paths a changeset reports - #13947

Closed
eunomie wants to merge 3 commits into
dagger:mainfrom
eunomie:workspace-changes-from-baseline-fix-lead-08677b55
Closed

eunomie wants to merge 3 commits into
dagger:mainfrom
eunomie:workspace-changes-from-baseline-fix-lead-08677b55

Conversation

@eunomie

@eunomie eunomie commented Aug 21, 2026 •

Copy link
Copy Markdown
Member

dagger generate on a module that already has generated output re-reports the whole generated
context, every time, as soon as a single generated file actually changes — files the SDK never
rewrote included. Only the very first generation of a module ever looked right, which is why
this went unnoticed: test fixtures start from an empty workspace.

The bug, minus the SDK

before = a directory holding keep.txt and nested/other.txt
after  = the same two files regenerated (identical bytes, fresh timestamps), plus added.txt

after.changes(before).addedPaths          →  ["added.txt"]        ← correct

target = a directory holding keep.txt = "local edit"
target.withChanges(after.changes(before))
  →  keep.txt is now "same"               ← overwritten, never reported
  →  nested/other.txt appeared            ← never reported

Why

The paths a Changeset reports come from comparing content, so a file rewritten with
identical bytes is not reported. But applying one went through Directory.diff, which is a
filesystem-level diff — a different modification time alone puts a path in it. Codegen hits
that every single time, since generated files come back from a container with fresh timestamps.

On a host-backed workspace it snowballs: the overlay sizes the baseline it compares against
from the reported paths, so the surplus files diff against nothing and come back as newly
added
. Hence the whole-context re-report.

Changeset.export and Changeset.layer had the same gap. Export is the worse one — it wrote
unreported paths straight into your working tree, while the preview the CLI shows you comes
from asPatch, which is content-based. What you were shown was not what got written.

The fix

All three follow the paths the changeset reports.

One deliberate consequence: a changeset no longer propagates a timestamp-, ownership- or
permission-only change through withChanges. Those were never expressible via asPatch
either, so the two ways of applying a changeset now agree.

Not fixed here

A regenerate still reports the directories leading to a newly added file — mod/,
mod/internal/, mod/internal/dagger/ — as added, even though the host has them. That is a
separate and older defect in sparseHostBase: it asks the host only for the touched paths
themselves, so when a touched path is an addition the host does not have yet, the directories
leading to it are missing from the baseline as well. It only affects additions — modifying an
existing file materialises its ancestors for free.

TestModuleRegenerateOverExistingOutput pins the current behaviour exactly rather than
asserting the ideal, so fixing that defect fails there loudly and the assertion tightens to
equality with what the changeset reports.

On the test gap

The existing changeset tests assert the right thing — testChangeApplying already requires an
unchanged file to survive being applied over. No fixture could violate it, though: both sides
are built from engine primitives, which carry normalized timestamps, so the underlying diff was
already tight; and the changeset is applied back onto the very tree it was diffed from, where
over-copying writes identical bytes over themselves. You need a tree of foreign provenance on
one side and a different apply target to see it. Both new tests have both.

@eunomie
eunomie force-pushed the workspace-changes-from-baseline-fix-lead-08677b55 branch from 0b55414 to dd53054 Compare August 21, 2026 15:04
@eunomie
eunomie marked this pull request as draft August 21, 2026 15:15
eunomie added a commit to eunomie/python-sdk that referenced this pull request Aug 25, 2026
Generation threaded the workspace through ModuleSource.generate and diffed it
back with Workspace.changes. On v1.0.0-beta.10 that loses the baseline: the
module's whole generated context comes back as added rather than only what
generation changed. Every generate and generateAll claimed to add the module's
own dagger.json, which the engine owns and had not touched, and once a module
has generated output on disk, files codegen rewrites byte for byte are reported
as added too.

The engine defect is in applying a changeset, not in comparing workspaces:
withChanges projects the structural before/after diff, which a fresh mtime alone
puts a path into, rather than the content-based paths the changeset reports.
dagger/dagger#13947 fixes it.

Write the generated context as a directory instead, the shape go-sdk settled on
in dagger/go-sdk#30. A directory overlay diffs correctly, so Workspace.changes
still does the cwd rooting and the outside-the-cwd guard, and nothing here has
to be reverted once the engine fix lands.

generatedContextDirectory does not resolve the local dependency closure the way
generate(ws) did, so generation stages it explicitly, and generateAll merges
each module's changeset rather than threading one workspace through all of them.

The generate fixture now commits the .gitattributes that generation emits, so
e-2-e:generate-skips-existing-files-check catches a generator returning its
whole context: every other file there is genuinely new on a fresh module.

Signed-off-by: Yves Brissaud <[email protected]>
Regenerating a module re-reported its entire generated context — including
engine-owned files an SDK never touched — as soon as one generated file
genuinely changed. Only the very first generation looked right, which is why
fixtures that start from an empty workspace never caught it.

A Changeset's paths come from ComputePaths, which compares content: a file
rewritten with identical bytes but a fresh mtime is not reported as changed.
Applying one went through the before/after structural diff instead, and
Directory.diff is metadata-sensitive — an mtime difference alone puts a path
in the diff. So Directory.withChanges wrote paths the changeset never
claimed, overwriting whatever the target held there.

On a host-backed workspace that surfaces as the re-report. The overlay takes
its touched paths from ComputePaths but builds its delta root with
withChanges, so the delta root outgrows the touched paths; the sparse host
base a comparison is measured against is sized from those same touched paths,
so the surplus files diff against nothing and read as newly added.

Narrow the copy to the paths ComputePaths reports. The changeset merge path
applies the same content the same way, so it takes the same filter.

Signed-off-by: Yves Brissaud <[email protected]>
Changeset.export and Changeset.layer both hand out the raw before/after
structural diff, which is metadata-sensitive and so spans more paths than
ComputePaths reports. Export writes those surplus paths into the caller's
working tree: a generator that rebuilds a whole tree and returns
generated.changes(source) writes every file it regenerated, not the ones it
changed, and can land on content the user edited in between. What the CLI
previews before applying comes from asPatch, which is content-based, so the
files written did not match the diff shown. And layer is documented as "a
snapshot containing only the created and modified files", which it was not.

Route both through the narrowing Directory.withChanges already does, so the
rule that a changeset touches exactly the paths it reports lives in one
place.

Signed-off-by: Yves Brissaud <[email protected]>
@eunomie
eunomie force-pushed the workspace-changes-from-baseline-fix-lead-08677b55 branch from dd53054 to bb653b1 Compare August 25, 2026 14:32
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]>
eunomie added a commit to eunomie/python-sdk that referenced this pull request Aug 28, 2026
… itself

A dagger-module.toml module no longer gets one flat gen.py holding core and
every dependency merged. It gets the core API from its own module-facing
schema, one dagger/clients/<dep>.py per declared dependency under the
dependency's final name, and dagger/clients/<self>.py: a client for itself,
which is how it calls itself through the engine and gets function-level
caching on its own calls.

The self client needs the module's own client-facing schema, and reading that
builds the module, which needs the vendored sdk/ this generation produces. The
circle is broken by staging: pass one vendors the library, the core and the
dependency clients plus the committed self client — or a stub whose every name
is a placeholder that says the client is not generated yet — onto a scratch
workspace, the engine builds the module from that, and the self client is
generated from the schema it reports.

Local dependencies are staged first, by ownership. Those registered to this
SDK are generated here, recursively, and overlaid onto the staging workspace,
because the engine's own generateLocalDependencies runs each dependency's
generator through Workspace.generators, which is empty in a value workspace
and fails there; the recursion carries the active path and fails on a cycle.
A dependency registered to another SDK is handed to the engine, the only thing
that knows its generator. Anything else local is assumed committed, as the
engine assumes too. The staging is an input to resolving the module source,
never the diff baseline, so a dependency's generated files do not ride along.

The generated-clients subtree is exclusively generated and swept before the
merge, so a dropped dependency or a renamed alias is reported as a removal;
the rest of sdk/ keeps merging onto what is there. Legacy dagger.json modules
still go through the engine's generated context, which works around
dagger/dagger#13947.

Verified against a live beta.11 engine: a module depending on a local module
twice, once aliased, generates from nothing; its three clients bind the right
names and the same path; and greet-via-dep, greet-via-alias and greet-self all
answer through the generated clients at runtime.

Signed-off-by: Yves Brissaud <[email protected]>
@github-actions

Copy link
Copy Markdown
Contributor

This PR is stale because it has been open 14 days with no activity. Remove stale label or comment or this will be closed in 7 days.

@github-actions

Copy link
Copy Markdown
Contributor

This PR was closed because it has been stalled for 7 days with no activity.

@github-actions github-actions Bot closed this Sep 24, 2026
eunomie added a commit to dagger/php-sdk that referenced this pull request Nov 13, 2026
Generation no longer falls back to the engine's generatedContextChangeset
for a module on the built-in PHP runtime, so the code a module gets comes
from this repository only. Delete Mod.legacyChanges and atCwd, which also
retires the dagger/dagger#13947 workaround.

A module on the PHP runtime that cannot move to the generated entrypoint
is now refused. The refusal names every reason read from the module's
files, including a direct generation with dependencies and a later
engineVersion, and points to the README's migration section. Exclusions
of generated files need a generation to detect, so they are reported
only once nothing cheaper refuses. A module with an entrypoint this SDK
did not write, or a runtime other than php, gets no change.

The targetVersion and clients refusals for a module that keeps the
runtime go: such a module no longer reaches them.

Signed-off-by: Yves Brissaud <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant