Skip to content

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

Closed
sipsma wants to merge 2 commits into
dagger:mainfrom
sipsma:content-keyed-filtered-workspace-reads
Closed

sipsma wants to merge 2 commits into
dagger:mainfrom
sipsma:content-keyed-filtered-workspace-reads

Conversation

@sipsma

@sipsma sipsma commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

What changed and why

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, gets a new cache key on every commit, even where the selected files didn't change.
  • Host workspaces don't have this problem: host.directory already carries the content digest of what it synced.

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 and host reads are unchanged.

No read returns anything different. The only effects are cache identity, and evaluating and hashing the filtered copy when the read is made.

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 keeps its cache keys across commits that don't touch the selected files.
  • 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.

Runs:

Lint

dagger check golangci-lint:lint-all, with the pinned lint module and golangci-lint v2.14.0. 0 issues at the base commit and 0 at this change, so 0 new.

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

Measured effect

golangci-lint/lint-all on dagger/dagger, run against a commit that changes only engine/ after a run of its parent commit, on a fresh engine with a remote cache, with the workspace loaded from a Git ref:

before after
lint runs keyed the same as on the parent commit 0 of 11 5 of 11
cache hits 23 of 204 50 of 203
executed calls 180 152
wall time 104 s 105 s

The five lints of Go modules the commit didn't touch keep their keys, and their lookups hit. Wall time doesn't move in this measurement:

  • the changed root module's lint (90 s) is the critical path;
  • the cached lints' outputs weren't uploaded to the remote cache, which is a separate fix.

The effect on per-package Go builds across commits is still being measured.

Not in this change

  • Subpath reads without a filter are unchanged.

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]>
@sipsma

sipsma commented Oct 22, 2026

Copy link
Copy Markdown
Contributor Author

Moved to #14829: a branch on this repository, so that CI runs. Native CI doesn't run on PRs from forks.

@sipsma sipsma closed this Oct 22, 2026
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.

1 participant