Skip to content

Workspace overlay & export - #13600

Merged
vito merged 8 commits into
mainfrom
workspace-overlay-export
Jul 13, 2026
Merged

vito merged 8 commits into
mainfrom
workspace-overlay-export

Conversation

@shykes

@shykes shykes commented Jul 9, 2026 •

Copy link
Copy Markdown
Contributor

Implement the proposed Workspace overlay & export API

Closes #13566

TODO before release

  • Complete SDK-owned client generation in the official Go and TypeScript SDKs, and restore end-to-end coverage for sdk install → api client init → generate → compile/run. Until then, development builds based on this change do not generate official clients.
  • Apply generator changes through currentWorkspace.withChanges(...).export instead of exporting to .; add coverage for running dagger generate from a nested workspace directory.
  • Resolve withoutSDK(name:) through the same module-key/as-sdk.name lookup as sdk(name:); test removing an aliased SDK.

@shykes shykes changed the title Add workspace overlay API Workspace overlay & export Jul 9, 2026
@shykes
shykes requested a review from vito July 9, 2026 20:02
@shykes
shykes force-pushed the workspace-overlay-export branch from 8880972 to 5251804 Compare July 9, 2026 20:37
Comment thread core/schema/workspace.go
if ws.HostPath() == "" {
return rootfs, fmt.Errorf("workspace has no root filesystem")
}
return s.resolveRootfs(ctx, ws, ".", core.CopyFilter{}, false)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rebased my LLM work on top of this and noticed this ends up doing a full upload:

▶ ✔ current-workspace | with-new-file hello.txt hello | changes 21.7s
Changeset@xxh3:dcc3b5fbba6b2752
  ✔ uploading /home/vito/src/dagger/llm-workspace 21.7s ████████████ 90 MB

It would be nice if that could be skipped somehow, since the end goal is producing a Changeset anyway which are meant to just represent the delta in scenarios like this.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree but I think that would require more work than this PR supports. I added a comment to track this. Do you agree with it?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The full sync is pretty painful when an agent makes minimal changes so I think we'll feel this pretty quickly, but it's still better than erroring so I'm happy to keep iterating on it in future PRs, don't wanna block this one.

Here's what my LLM came up with, for what it's worth: vito@8e2ffa5 - haven't fully tested yet

NOTE: GitHub only shows one file in its UI for me; seems like a bug. Here's a gist version

Basically it builds up changes on an empty base and tracks which files actually changed, and then syncs only those paths, since we still need to do that for an accurate diff. (e.g. if something fully rewrote README.md we still want to see the diff compared to the previous version even if it used withNewFile to clobber it).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what I can tell, this full sync applies to dagger install, dagger workspace config, etc. So it's going to be a pretty painful regression in common paths. Seems worth addressing here or very soon after

@sipsma sipsma Jul 10, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shykes I had codex do a comparison, this PR does indeed seem to massively regress performance of even just dagger install and dagger workspace config:

Setup:

  • Checkout size of my dagger repo: 3.9 GB, including a 652 MB .git directory and large ignored directories.
  • Each cold measurement started with a fresh engine cache.
  • Both versions operated on the same minimal native dagger.toml.
Command upstream/main This PR
dagger workspace config check-generated true 0.99s 45.19s
Host filesystem input 2.29 MiB 3.805 GiB
dagger install ./modules/wolfi 14.05s 71.72s
Host filesystem input 0.95 MiB 3.807 GiB

That's big enough that I really feel like we should just fix it now before merging. @vito already posted a potential fix above, I think we should just try that.

@shykes
shykes force-pushed the workspace-overlay-export branch from 5251804 to 0b80db2 Compare July 10, 2026 11:37
@shykes
shykes requested review from a team as code owners July 10, 2026 11:37
@shykes
shykes force-pushed the workspace-overlay-export branch 4 times, most recently from 3227a5e to c28b2d0 Compare July 10, 2026 14:49
@shykes
shykes force-pushed the workspace-overlay-export branch from 4dc6e25 to bd6f1ee Compare July 10, 2026 15:43
ws, err := Detect(ctx, fakePathExists(existing), "/repo/app")
require.NoError(t, err)
require.Equal(t, "/repo", ws.Root)
require.True(t, ws.HasGitRoot)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could be interesting to have one opposite test somewhere, with a case HasGitRoot == false

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added TestDetectInRootDoesNotClaimGitRoot, covering an explicit boundary with HasGitRoot == false.

parent dagql.ObjectResult[*core.Workspace],
args workspaceUninstallArgs,
) (dagql.ObjectResult[*core.Workspace], error) {
return s.withoutModule(ctx, parent, args)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: shouldn't this check it's actually removing an SDK?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this deleted? It doesn't seem like the equivalent test coverage was really replaced in full. Intentional?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes we're moving the SDK-specific tests to the SDK repos

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @eunomie and @TomChv to confirm.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I had missed that. Hopefully the tests still run as part of the github.com/dagger/dagger CI though, right? That's a separate conversation though, not a blocker here really.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't see this test coverage was replaced, why is it deleted?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as client_generator_test.go: moving SDK-specific tests to SDK module repos.

@vito

vito commented Jul 10, 2026 •

Copy link
Copy Markdown
Contributor

Noticed test-workspaces is timing out, which matches what I see on my LLM branch rebased on this.

Minimal hang is:

dagger call engine-dev test  \
          --run 'TestWorkspaceAPI/TestWorkspaceSDKReadersUseStagedOverlay' \
          --pkg ./core/integration

When I run that I see that it gets stuck in a Workspace.sdks call:

https://dagger.cloud/dagger/traces/5e21485e9c1e38b7b882a8556b3e378a?listen=57320f8fabe19c5a&listen=a6f6684e2c1451f6&test=TestWorkspaceAPI/TestWorkspaceSDKReadersUseStagedOverlay&viewMode=tests

(Confusingly the UI pretends the test 'passed' - I guess because I interrupted it, it never "failed")

@sipsma

sipsma commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

This is coming directly from Codex. Erik checked it, and it makes sense to him.

Blocker: Workspace.sdks creates a self-referential DagQL cache result and hangs.

In core/schema/workspace_sdk.go, workspaceSDKResults creates every SDK child with:

dagql.NewObjectResultForCurrentCall(ctx, srv, sdk)

At that point the current call is the Workspace.sdks list call itself. NewObjectResultForCurrentCall installs that exact call frame on the child rather than deriving a list-element call. When ObjectResultArray.AttachDependencyResults attaches the child, the cache looks up the same call that is currently being initialized, so the result waits on its own in-progress call.

This is observable with only one SDK: TestWorkspaceAPI/TestWorkspaceSDKReadersUseStagedOverlay did not complete in a bounded 75-second local run, matching the test-workspaces CI timeout and the independently reported trace stuck in Workspace.sdks.

There is a second identity problem behind the hang: if multiple SDK children all reuse the same current call, they are indistinguishable to the cache.

Workspace.modules already demonstrates the appropriate pattern: create each child through an internal identity-bearing selector (Workspace.__workspaceModule) with the module fields as arguments. I recommend adding an equivalent __workspaceSDK selector, constructing each SDK child through it, and adding a two-SDK integration test that checks both payloads and distinct IDs.

@shykes

shykes commented Jul 10, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @vito and @sipsma I'm looking into your 2 last comments.

I thought I had addressed the hang in test-workspace, but it appears not.

vito added a commit to vito/dagger that referenced this pull request Jul 10, 2026
The overlay sparse-read design doc described the implementation against the
pre-rebase overlay model (stored Root/BaseRoot/DeltaRoot fields). The dagger#13600
update slimmed the overlay to {Base, Changes} with the read root derived
from Changes.After, so the fix was re-expressed rather than ported: the
delta root lives as Changes.After, the sparse base as Changes.Before, and
TouchedPaths is the only added field.

Record the reformulation up top — including why TouchedPaths cannot be
derived from the changeset (reverted edits would resurface as phantom
additions), the SourceDirectory gate that keeps the sparse After from
masquerading as the workspace tree, the rootless dispatch hazard (rootless
sources carry a host path but must not read through it), why rename
detection survives a touched-paths base, and the two lock-read full-sync
sites the original design never saw — and rewrite the key code locations
to match the as-built shape. The original diagnosis and design reasoning
below it still apply and are kept.

Signed-off-by: Alex Suraci <[email protected]>
@grouville
grouville force-pushed the workspace-overlay-export branch from 9ad2586 to 0b94829 Compare July 13, 2026 14:26
Signed-off-by: Solomon Hykes <[email protected]>
shykes and others added 4 commits July 13, 2026 09:47
Signed-off-by: Solomon Hykes <[email protected]>
Editing a host-backed workspace forced a filterless host.directory(".")
upload of the whole tree (~11s per Edit() on this repo): the overlay's
changeset was computed against the full host base, its derived read root
(Changes.After) was full host + edits, and Directory.withChanges must
materialize its base, so both edits and reads paid the full sync.

Make the changeset delta-native for host (client-local) overlays instead.
Changes.After becomes the delta root — the accumulated edits applied to an
empty base, never referencing the host tree — and Changes.Before a sparse
host.directory including only the cumulative TouchedPaths, the one field
added to the overlay source. Forcing changes/export then syncs just the
touched files (new files sync nothing), and edits stay in-engine. Renames
survive the sparse base: a removal only ever comes from an edit, so both
sides of a rename are always touched and present in the base.

Since the sparse After must never masquerade as the workspace tree,
SourceDirectory() now returns false for client-local overlays, and reads
resolve per-call instead: a sparse host.directory of just the requested
paths (re-rooted filter, gitignore threaded) with the changeset applied on
top, then descend and trim — untouched files serve host content at read
time, edits win, removals don't resurface. readConfigBytes dispatches on
the touched set so config builders see staged config edits while untouched
configs still read straight from the host file. Whole-tree consumers
(module-source loading, install flows) keep materializing full host +
changeset via workspaceOverlayRootfs, now only when actually requested.

Value, git, and rootless workspaces keep the full-root accumulation: their
trees are already in-engine (empty for rootless), so there is nothing to
upload. Rootless local workspaces carry a host path but must not read
through it, so all dispatch is on the base source kind, not the host path.

Signed-off-by: Alex Suraci <[email protected]>
@grouville
grouville force-pushed the workspace-overlay-export branch from 0b94829 to 6376ba0 Compare July 13, 2026 16:48
Signed-off-by: Guillaume de Rouville <[email protected]>
grouville
grouville previously approved these changes Jul 13, 2026
@grouville
grouville self-requested a review July 13, 2026 17:25
@grouville
grouville dismissed their stale review July 13, 2026 17:25

still one thing to finish

vito added a commit to vito/dagger that referenced this pull request Jul 13, 2026
The overlay sparse-read design doc described the implementation against the
pre-rebase overlay model (stored Root/BaseRoot/DeltaRoot fields). The dagger#13600
update slimmed the overlay to {Base, Changes} with the read root derived
from Changes.After, so the fix was re-expressed rather than ported: the
delta root lives as Changes.After, the sparse base as Changes.Before, and
TouchedPaths is the only added field.

Record the reformulation up top — including why TouchedPaths cannot be
derived from the changeset (reverted edits would resurface as phantom
additions), the SourceDirectory gate that keeps the sparse After from
masquerading as the workspace tree, the rootless dispatch hazard (rootless
sources carry a host path but must not read through it), why rename
detection survives a touched-paths base, and the two lock-read full-sync
sites the original design never saw — and rewrite the key code locations
to match the as-built shape. The original diagnosis and design reasoning
below it still apply and are kept.

Signed-off-by: Alex Suraci <[email protected]>
readWorkspaceLockForOverlay materialized the whole workspace tree just to
stat and read the lockfile: it went through workspaceOverlayRootfs, which
resolves a filterless host.directory for host-backed workspaces — a full
upload even on pristine workspaces with no overlay. workspaceLockChangeset
had the same problem, diffing its lockfile write against a filterless base.

Resolve both against an include-scoped rootfs instead: the lock read
requests just the canonical and legacy lock path candidates, and the lock
changeset diffs against a base containing only the lockfile — the diff
never covers anything else, so the changeset is identical. Host workspaces
(pristine or overlaid) now sync only the lock files on install and update
flows; value/git/rootless workspaces resolve the same filter in-engine.

Signed-off-by: Alex Suraci <[email protected]>
vito added a commit to vito/dagger that referenced this pull request Jul 13, 2026
The overlay sparse-read design doc described the implementation against the
pre-rebase overlay model (stored Root/BaseRoot/DeltaRoot fields). The dagger#13600
update slimmed the overlay to {Base, Changes} with the read root derived
from Changes.After, so the fix was re-expressed rather than ported: the
delta root lives as Changes.After, the sparse base as Changes.Before, and
TouchedPaths is the only added field.

Record the reformulation up top — including why TouchedPaths cannot be
derived from the changeset (reverted edits would resurface as phantom
additions), the SourceDirectory gate that keeps the sparse After from
masquerading as the workspace tree, the rootless dispatch hazard (rootless
sources carry a host path but must not read through it), why rename
detection survives a touched-paths base, and the two lock-read full-sync
sites the original design never saw — and rewrite the key code locations
to match the as-built shape. The original diagnosis and design reasoning
below it still apply and are kept.

Signed-off-by: Alex Suraci <[email protected]>
Reading Workspace.sdks hung indefinitely when the workspace contained an SDK.
The integration test TestWorkspaceSDKReadersUseStagedOverlay reproduced the
same symptom as the test-workspaces CI timeout: its query stopped inside
Workspace.sdks and never returned.

workspaceSDKResults created each WorkspaceSDK child with
dagql.NewObjectResultForCurrentCall. That helper assigns the resolver's current
call to the returned object. In this resolver the current call is the enclosing
Workspace.sdks list call, not a call identifying one element of that list.
When ObjectResultArray.AttachDependencyResults attached a child to the list,
the cache looked up Workspace.sdks while that exact call was still being
initialized. The result therefore waited on its own in-progress cache entry.
This explains why one SDK was enough to deadlock. It also meant every SDK in a
multi-item result shared one call identity, so the cache could not distinguish
children with different payloads.

Construct each SDK through a new internal Workspace.__workspaceSDK selector,
following the established Workspace.__workspaceModule pattern. Select it from
the owning Workspace result and pass the SDK name, ref, module names and
sources, and client names and sources as selector arguments. DagQL can now
derive a deterministic call for each child without referring back to the list
call. Including the complete SDK payload in the arguments also ensures that
two different SDK entries cannot alias in the cache. Route Workspace.sdk
through the same helper so single-item and list reads use one identity model.

Add TestWorkspaceSDKsHaveDistinctIdentity with two SDK entries whose refs,
authored modules, and generated clients differ. It reads the full list in one
query, verifies both payloads, requires non-empty IDs, and asserts that the IDs
are distinct. Run it together with
TestWorkspaceSDKReadersUseStagedOverlay to cover both regressions: the existing
single-SDK query must terminate, and multiple children must remain distinct.

Signed-off-by: Guillaume de Rouville <[email protected]>

@grouville grouville left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, introduced the cache hit fix

@vito
vito merged commit cf2ec52 into main Jul 13, 2026
87 checks passed
@vito
vito deleted the workspace-overlay-export branch July 13, 2026 23:01
sipsma added a commit that referenced this pull request Oct 8, 2026
The TestClientGenerator suite was deleted from core/integration in the
workspace overlay and export change (#13600). Client generation tests
are planned to move to the SDK modules, per future/sdk-tests.md. Since
then the test-split/test-client-generator check builds a dev engine and
runs go test with a selector that matches nothing:

  testing: warning: no tests to run
  ok  github.com/dagger/dagger/core/integration 0.066s [no tests to run]

Remove the check, its release-branch workflow entry, and the now-dead
skip entries in the base and package shards. A future TestClientGenerator
suite would run in the base catch-all shard by default.

Also drop the release-branch workflow entry for test-split/test-cgroups.
That check was split into test-provision and test-telemetry in #11735
and no longer exists.

Also point a helper comment that named the deleted suite at
TestGenerators, which uses the same helper.

Signed-off-by: Erik Sipsma <[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.

Workspace overlay and export

5 participants