Repository navigation
core: key filtered workspace reads by their content - #14829
Merged
Merged
Conversation
This was referenced Oct 22, 2026
tiborvass
approved these changes
Oct 26, 2026
A filtered read from a Directory- or GitRef-backed workspace is a copy of the selected files, but it is identified by its recipe over the workspace root, so two roots that differ only outside the selection give different keys to everything built on it. A Git root's identity is its commit, so CI that loads a workspace from a Git ref gets new keys for all work on every commit, even for parts of the repository that did not change. Host reads already carry the content digest of their sync. The test reads the same selection from two roots that differ elsewhere, and from one where the selection changed, through include and exclude filters with and without a subpath, on Directory- and GitRef-backed workspaces. It also checks that a subpath read without a filter is left as it was: it keeps its name and still reaches its root through a link. Signed-off-by: Erik Sipsma <[email protected]>
A filtered read from a Directory- or GitRef-backed workspace (include, exclude or gitignore) was identified only by its recipe over the workspace root. A Git root's identity is its commit, so on a workspace loaded from a Git ref, as CI loads it, every filtered read and everything built on it got a new key on every commit, even where the files it selects were unchanged. Host reads were not affected: host.directory carries the content digest of its sync. A filtered read is already a copy of the selected files into a fresh directory, so it can reach nothing but those files: give it their content hash, as module context directories get after filtering. A subpath read without a filter is a view into the root, which can still reach the root's files through .. or a symlink, so this change leaves it as it was and adds no content digest to it. No read changes what it returns. Signed-off-by: Erik Sipsma <[email protected]>
Giving a filtered read its content digest evaluates the read while Workspace.directory or Workspace.file is still resolving it. A read that cannot evaluate, such as a filtered read of a subpath the root doesn't have, then failed the workspace call itself. Before, the read was returned unevaluated and failed only where it was used, so a caller could handle it: Directory.exists reports a missing path as false. dagger module client add and dagger module init rely on that on host workspaces with overlay edits, whose sparse roots often lack the paths they check, so their tests in TestGenerators failed. When the read fails to evaluate or hash, return it as it is, with no content digest. It keeps the recipe identity it has without this change, and its evaluation is retried where it is used, as before, so a missing path fails there, where a caller can handle it. The test reads a missing subpath through a filter on a Directory-backed workspace and checks that exists reports it missing. A Git root carries a content digest, so a subpath read of it is evaluated, and fails, when it is made, before any filter; that is unchanged, and the test skips it. Signed-off-by: Erik Sipsma <[email protected]>
The comment on contentKeyedFilteredRead said host reads already carry the content digest of their sync. That holds only for an unedited host workspace, whose reads are host.directory syncs. Reads from a host workspace with overlay edits, under a mounted path or from a rootless local workspace read from a Directory root and do come through it. Signed-off-by: Erik Sipsma <[email protected]>
The comment on contentKeyedFilteredRead explained why a read that fails to evaluate or hash is returned without a content digest by comparing it with the behaviour before this change. Say why it is right instead: there is no content digest to give it, and a missing path is something a caller handles where it uses the read, so it must not fail the workspace call. Signed-off-by: Erik Sipsma <[email protected]>
sipsma
force-pushed
the
sipsma/content-keyed-filtered-workspace-reads
branch
from
October 26, 2026 22:46
4176ad7 to
93f71f4
Compare
eunomie
pushed a commit
to eunomie/dagger
that referenced
this pull request
Oct 29, 2026
A module function run with `-W <repo>@<sha>` reads its workspace from a Git tree, whose identity is its commit. Exec work on a filtered Workspace.directory read must be reused across commits that leave the selected files unchanged, as it is for a local checkout. Content-keyed filtered workspace reads (dagger#14829) made that so. Its tests load a Git ref as a workspace through the API; this adds the CLI flow: a module in the repository, a fresh session per commit, a read with include and gitignore mounted next to a cache volume, and an exec whose output is random. A README-only commit must reuse the exec; a commit inside the selection must re-run it. The test fails with dagger#14829's content keying removed, on the README-only commit. Signed-off-by: Erik Sipsma <[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.
What changed and why
Filtered reads of Git-ref and Directory-backed workspaces now get the content hash of the files they select. Their recipes still change with every commit, but the cache treats results with the same content digest as interchangeable. So work built on them is reused across commits that don't change those files. A read that can't be evaluated keeps its keying and behaviour from main.
A filtered read from a workspace loaded from a Git ref, or created with
Directory.asWorkspace, is identified only by its recipe over the workspace root. For example,ws.directory("/", include: [...]).host.directorysyncs, which already carry the content digest of what they synced.dagger module client addanddagger module initstage, which read from a sparse host sync with the edits applied;This change gives a filtered read the content hash of the files it selects.
resolveRootfsFromDirectory(core/schema/workspace.go), the filtered branch now evaluates its copy and teaches itGetContentHashFromDirectorythroughWithContentDigest. Module context directories already get the same treatment after filtering.A read that fails to evaluate or hash gets no content digest. For example, a filtered read of a subpath the root doesn't have.
Workspace.directoryorWorkspace.filecall: a missing path is something a caller handles where it uses the read, so the read is evaluated, and fails, there. On a Git-ref workspace, a read of a missing subpath already fails when it's made, before any filter, as on main.Directory.existsreports a missing path asfalse.dagger module client addanddagger module initrely on that when they check whether to create paths that don't exist yet.So no read returns anything different from main. The only effects are cache identity, and evaluating and hashing the filtered copy when the read is made, not when it's first used.
test-base-extrarun of this PR's first commit: the 380 reads that took this path spent 10.9 s in total on evaluation and hashing, across parallel sessions. That's a median of about 14 ms per read; the slowest took 0.82 s.Who benefits
Every workspace loaded from a Git ref or made with
Directory.asWorkspace. That includes CI that runsdaggeragainstgithub.com/<org>/<repo>@<sha>.Tests
New test:
TestWorkspace/TestFilteredReadsAreContentKeyed(core/integration/workspace_content_keyed_test.go).exists, returnsfalsewith no error. On a GitRef-backed workspace this case is skipped: a Git root carries a content digest, so a subpath read of it is evaluated, and fails, when it is made, before any filter. That's unchanged from main.Several
TestGeneratorstests rundagger module client addanddagger module initon edited host workspaces, where those commands check for paths that don't exist yet. They failed with this PR's first commit, which evaluated the read inside theWorkspace.directorycall. They pass with the fallback above.Runs, for the first commit:
TestDirectorysuite: 191 passed. https://dagger.cloud/dagger/traces/d3f3722ef010e9899a6fa5b7905e0bbcTestFilteredReadsAreContentKeyed,TestDirectoryBackedSyntheticWorkspaceUsesSourceContent,TestGitRefBackedSyntheticWorkspaceUsesSelectedRef,TestValueBackedWorkspaceLoadsModulesFromTree). https://dagger.cloud/dagger/traces/adaabbf10f1e0106dba5845c2073d015Runs, for the fallback:
workspace directory "missing": snapshot: stat missing: no such file or directory.TestGeneratorstests that broke in CI fail the same way. https://dagger.cloud/dagger/traces/a9a16e3ee5eec163db81e51bf3eccd09TestFilteredReadsAreContentKeyedpasses, failed-read test included, and so do the eightTestGeneratorstests. https://dagger.cloud/dagger/traces/a955d30152e17babe8c956d61b30272fTestWorkspaceandTestGeneratorssuites: both pass in this PR's CI, in thetest-split/test-workspacesandtest-split/test-base-extrachecks.Lint
golangci-lint/lint-allpasses in this PR's CI.Cache model
Nothing under
dagql/changes. This adds one caller of the existing content-digest teaching path. The cache model indagql/tla/CacheLifecycle.tlatreats equivalence classes as a static partition and leaves runtime teaching out of scope, so it needs no change.dagger --env dev check tla-check:quickpasses all 18 configurations: https://dagger.cloud/dagger/traces/0757f34ddc4223af1e9c37f6c43765ccNot in this change
Replaces #14815, moved from a fork to a branch here so that CI runs.