Skip to content

core: key filtered workspace reads by their content - #14829

Merged
sipsma merged 5 commits into
mainfrom
sipsma/content-keyed-filtered-workspace-reads
Oct 26, 2026
Merged

sipsma merged 5 commits into
mainfrom
sipsma/content-keyed-filtered-workspace-reads

Conversation

@sipsma

@sipsma sipsma commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

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: [...]).

  • A Git tree's identity is its URL and commit.
  • So on such a workspace, every filtered read, and everything built on it, is new to the cache on every commit, even where the selected files didn't change.
  • Unedited host workspaces don't have this problem: their reads are host.directory syncs, which already carry the content digest of what they synced.
  • Other host-backed reads do read from a Directory root, and take the path this change touches:
    • reads from a host workspace with overlay edits, such as the ones dagger module client add and dagger module init stage, which read from a sparse host sync with the edits applied;
    • reads under a mounted path;
    • reads from a rootless local workspace.

This change gives a filtered read the content hash of the files it selects.

  • In resolveRootfsFromDirectory (core/schema/workspace.go), the filtered branch now evaluates its copy and teaches it GetContentHashFromDirectory through WithContentDigest. Module context directories already get the same treatment after filtering.
  • A filtered read is already a copy of the selected files into a fresh directory, so its content hash covers everything it can reach.
  • A subpath read without a filter is a view into the root that can still reach the root's files, so it is left as it was.
  • Whole-root reads, unfiltered subpath reads and unedited host reads are unchanged.

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.

  • It is returned as it is: with no content to hash, its recipe is its only identity, and so its cache key.
  • On a Directory-backed or edited host workspace, it must not fail the Workspace.directory or Workspace.file call: 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.
  • So a caller can still handle it: Directory.exists reports a missing path as false. dagger module client add and dagger module init rely 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.

  • Measured on CI's test-base-extra run 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.
  • That's the time evaluating and hashing took, not the time added over main. On main a read is evaluated too when it's used, only later. What's new is the hashing, and evaluating reads that are never used.

Who benefits

Every workspace loaded from a Git ref or made with Directory.asWorkspace. That includes CI that runs dagger against github.com/<org>/<repo>@<sha>.

  • Any module that reads the workspace with include, exclude or gitignore filters now has that work reused across commits that don't touch the selected files, as long as the earlier result is still in the cache.
  • Only reads that evaluate get a content digest. A read whose includes don't exist yet keeps main's keying, so it gets no cross-commit benefit. That isn't a regression: it is keyed exactly as on main. Such reads are common on edited host workspaces, whose sparse root holds only what each read selects.
  • golangci-lint's per-module lint and the Go per-package builds are examples.

Tests

New test: TestWorkspace/TestFilteredReadsAreContentKeyed (core/integration/workspace_content_keyed_test.go).

  • Workspaces: two roots that differ only outside the selection, and one where the selection changed. Each runs on Directory-backed and GitRef-backed workspaces.
  • Reads: include, exclude, and subpath + include.
  • Assertions: an unchanged selection reuses work; a changed one doesn't.
  • Non-regression: an unfiltered subpath read keeps its name, and still reaches its own root through a link.
  • Failed reads: on a Directory-backed workspace, a filtered read of a subpath the root doesn't have, followed by exists, returns false with 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 TestGenerators tests run dagger module client add and dagger module init on 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 the Workspace.directory call. They pass with the fallback above.

Runs, for the first commit:

Runs, for the fallback:

Lint

golangci-lint/lint-all passes 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 in dagql/tla/CacheLifecycle.tla treats equivalence classes as a static partition and leaves runtime teaching out of scope, so it needs no change. dagger --env dev check tla-check:quick passes all 18 configurations: https://dagger.cloud/dagger/traces/0757f34ddc4223af1e9c37f6c43765cc

Not in this change

  • Subpath reads without a filter are unchanged.

Replaces #14815, moved from a fork to a branch here so that CI runs.

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
sipsma force-pushed the sipsma/content-keyed-filtered-workspace-reads branch from 4176ad7 to 93f71f4 Compare October 26, 2026 22:46
@sipsma
sipsma merged commit ef43669 into main Oct 26, 2026
92 checks passed
@sipsma
sipsma deleted the sipsma/content-keyed-filtered-workspace-reads branch October 26, 2026 23:05
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]>
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.

2 participants