Skip to content

core: key module calls on their declared clients - #14299

Closed
eunomie wants to merge 5 commits into
dagger:mainfrom
eunomie:serve-module-cache-deps
Closed

eunomie wants to merge 5 commits into
dagger:mainfrom
eunomie:serve-module-cache-deps

Conversation

@eunomie

@eunomie eunomie commented Sep 23, 2026 •

Copy link
Copy Markdown
Member

Problem

A caller can serve a local client's module and cache a function result computed from it. Today, if only the client's target module changes, the caller's cached result can stay stale: the served module never enters the caller's cache key, so the cache lookup hits even though the inputs really changed.

Fix

Before a module function's cache lookup, the call gains one implicit input: a digest of the local clients the caller's dagger.toml declares for that module's scope, plus those clients' own declared clients, recursively.

  • A module with no declared clients gets no extra input, so its cache key is unaffected.
  • The digest is an implicit input, not a visible argument, so it never appears in dagger call output or in Dagger Cloud's trace.

The change is built from four commits: a reproduction test for the stale result; a workspace helper mapping each module scope to its local client paths; a small dagql addition letting a dynamic-input hook set an implicit input after the hook runs (so a function's cache-key hook can add one); and the fix itself, which keys module calls on their declared clients.

Test

core/integration/module_serve_test.go adds TestServeModuleDeclaredClientCache with four subtests:

  • an unchanged target hits the cache,
  • a changed target misses and then hits,
  • an unresolvable target fails and then succeeds correctly,
  • the new implicit input stays hidden from dagger call display.

The test was verified failing before the fix and passing after, on the reproduction.

Trade-offs (reviewed and accepted)

  • Only clients declared in dagger.toml are tracked; an undeclared serveModule address is not.
  • Git clients are out of scope here — they are handled separately by core: let serveModule pins win over version queries #14284.
  • The per-call cost on large client fan-outs has not been measured; it is accepted to try as-is.

Known side effect

Replaying a recorded call by ID now recomputes this digest from the caller's current clients rather than reusing the recorded value. This matches how other engine-computed implicit inputs already behave.

Also: key git module calls on their commit

A fifth commit extends the same cache-key work to git modules. A call to a git module could return a stale cached result after a commit that changed only a sibling module the module serves: the module's identity covered only its own loaded files, not the rest of its repository.

moduleImplementationScoped (core/schema/module.go) now adds the module's git commit to its scoped cache key, so the whole repository tree at that commit is covered. It is a one-line change, covered by TestServeModuleGitCommitCache.

Cost: the cache key of every git-loaded module changes once (a one-time invalidation on upgrade), and results are no longer shared between two commits of a repository even when the module's own files did not change; consumers at the same commit still share. Directory and host modules are unchanged.

📄 Understanding this change

A hook can then add engine-computed identity that call displays omit.

Signed-off-by: Yves Brissaud <[email protected]>
A module serves its clients at run time, after the cache lookup, so a
changed target left the caller's cached result stale.

Signed-off-by: Yves Brissaud <[email protected]>
A git module's code can serve modules beside it in its repository,
which the module's own files, and so its cache key, do not cover.

Signed-off-by: Yves Brissaud <[email protected]>
@eunomie
eunomie force-pushed the serve-module-cache-deps branch from ceff7b9 to 84239a7 Compare October 1, 2026 15:37
eunomie added a commit to eunomie/dagger that referenced this pull request Oct 1, 2026
…ll-story

* upstream/pr-14299:
  core: key git module calls on their commit
  core: key module calls on declared clients
  dagql: let dynamic input hooks set implicit inputs
  workspace: map module scopes to local clients
  core: reproduce stale serveModule caller results

Signed-off-by: Yves Brissaud <[email protected]>
eunomie added a commit to eunomie/dagger that referenced this pull request Oct 3, 2026
Extends the local-client mapping from dagger#14299; local clients, and the
call key built from them, are unchanged.

Signed-off-by: Yves Brissaud <[email protected]>
@eunomie eunomie closed this Oct 6, 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