Skip to content

core: fix module source cache dependency retention - #13243

Merged
sipsma merged 6 commits into
dagger:mainfrom
sipsma:fix-module-source-toolchain-context
May 29, 2026
Merged

sipsma merged 6 commits into
dagger:mainfrom
sipsma:fix-module-source-toolchain-context

Conversation

@sipsma

@sipsma sipsma commented May 28, 2026

Copy link
Copy Markdown
Contributor

Summary

This PR fixes several cache persistence dependency gaps around module sources and module-backed SDK implementations:

  • persist generated code results so generated context state can survive engine restarts
  • retain cache volume source results referenced by module sources
  • remove unused toolchain context source state that was only persisted/attached but not actually used
  • retain dagql results embedded in module-backed SDK implementations, including the SDK implementation module and optional SDK source directory
  • avoid storing long-lived module SDK server/object state by instantiating the SDK module server per operation

It also enables the engine HTTP debug listener for newly provisioned local container engines at 127.0.0.1:6060, without publishing that port to the host. That gives us a way to ask users for /debug/dagql/cache dumps from default Docker engines via a helper container sharing the engine network namespace.

Validation

  • go test ./core/sdk ./core
  • go test ./engine/client/drivers

sipsma added 5 commits May 27, 2026 15:12
TypeScript SDK initialization can retain GeneratedCode objects in the DagQL cache. The object already owns its generated code directory through an ObjectResult dependency and carries only scalar VCS path metadata, but it did not implement the persisted object codec. During graceful engine shutdown this caused DagQL cache persistence to fail with GeneratedCode does not implement persisted object encoding, which marked the shutdown unclean and discarded restart cache state.

Make GeneratedCode a persisted DagQL object. Its payload stores the generated code directory by persisted result ID plus VCS generated and ignored path lists. Decode restores the directory through the existing persisted object result loader and reconstructs the scalar metadata without rerunning codegen or forcing lazy directory evaluation at shutdown.

Add a TypeScript function-cache persistence integration case. It runs a TypeScript module through an isolated persisted dev engine, stops and restarts that engine, and verifies an always-cached function result survives the restart. This reproduces the previous GeneratedCode shutdown persistence failure and protects the real TypeScript codegen path.

Signed-off-by: Erik Sipsma <[email protected]>
CacheVolume stored source-backed cache volume initialization as a raw DirectoryID. That kept the source out of DagQL dependency retention, so a persisted CacheVolume could survive while the directory result it depends on was released or pruned. It also forced container cache locking to abuse EncodePersistedObject as a stable lock key, which stops making sense once persisted object refs require the real persistence cache.

Store CacheVolume.Source as a nullable ObjectResult[*Directory] and implement AttachDependencyResults so source directories are retained with the cache volume. Encode persistence with SourceResultID and decode by loading the retained Directory result. Keep the schema API accepting DirectoryID by loading IDs at resolver boundaries.

Split cache volume lock key generation into an internal lockKey helper that still encodes a stable source ID for locked cache mounts without going through persistence. Update the withMountedCache dynamic rewrite path and unit coverage for persisted source result IDs, dependency attachment, and lock keys.

Signed-off-by: Erik Sipsma <[email protected]>
ModuleSource carried an internal ToolchainContextSource projection plus ToolchainConfigIndex and ToolchainProjection fields. The fields were only wired through ModuleSource persistence and dependency attachment; no active schema or runtime path populated or consumed them.

That made the cache model misleading: ToolchainContextSource looked like a persisted object-result dependency, and AttachDependencyResults even attempted to attach it, but because the projection state was otherwise dead there was no coherent behavior to preserve.

Hard-cut the unused projection state from ModuleSource and remove its attach, encode, and decode plumbing. Toolchains continue to be represented through ConfigToolchains and Toolchains, which are the active fields used by module source loading and schema behavior.

Signed-off-by: Erik Sipsma <[email protected]>
ModuleSource can retain cache-backed dependencies through fields like ContextDirectory, SourceRootSubpath, and Dependencies, but it did not ask its SDK implementation whether the implementation also embeds dagql results. Module-backed SDK implementations do embed those results: the SDK module object and, when present, the full SDK source directory. If the owning ModuleSource survived while those implementation results were not retained, later SDK operations could try to reuse stale module provenance and fail with missing shared result errors.

Add an SDK.AttachDependencyResults hook and make ModuleSource delegate attachment through it. The Go and Dang built-in SDKs have no embedded dagql results, so they are explicit no-ops. The module-backed SDK attaches its implementation module and optional source directory, rewrites those fields to the attached results, and refreshes the implemented function map from the attached module.

Also stop storing long-lived module SDK server/object state. A module SDK now keeps only durable inputs and instantiates a fresh dagql server/object for each runtime, typedef, codegen, or client-generation operation. Persisted lazy SDK wrappers likewise load a fresh SDK per operation instead of caching a loaded implementation back into the ModuleSource, which avoids introducing untracked implementation refs after persistence attachment has already run.

Add focused unit coverage that ModuleSource retains SDK implementation dependencies and that the module SDK rewrites both retained implementation inputs during attachment.

Signed-off-by: Erik Sipsma <[email protected]>
Default Docker-provisioned engines already start with debug logging enabled, but the HTTP debug endpoints remain disabled unless the engine is launched with an explicit debug address. That makes it hard to collect point-in-time cache dumps from a user's default engine after a cache bug is observed, because there is no listener to query from inside the container.

Start newly provisioned local container engines with --debugaddr 127.0.0.1:6060. Binding to loopback keeps the listener inside the engine container's network namespace and does not publish any host port. Users can still collect debug data by running a separate helper container with --network container:<engine>, or by any future in-container helper, without exposing pprof, expvar, /debug/gc, or DagQL cache dumps to the host network by default.

Keep normal engine API port publishing unchanged: only the requested engine API port is passed through the driver ports list. Add a focused driver test that captures the generated run options and verifies the loopback debug listener argument is present while only the normal API port is published.

Signed-off-by: Erik Sipsma <[email protected]>
@sipsma sipsma added this to the v0.21.1 milestone May 28, 2026
The go:generate-dagger-runtimes CI check reported that the generated Go runtime module files were stale. Running the requested generator updated every generated runtime module's OpenTelemetry dependencies from v1.43.0 to v1.44.0, along with the matching go.sum entries.

This is a mechanical generated output update only. The generator check passes locally with:

  dagger --progress=plain check go:generate-dagger-runtimes

Signed-off-by: Erik Sipsma <[email protected]>
@sipsma
sipsma requested review from a team as code owners May 28, 2026 04:49
@sipsma
sipsma merged commit ddc4c45 into dagger:main May 29, 2026
78 checks passed
eunomie added a commit to eunomie/dagger that referenced this pull request May 30, 2026
…attern

Commit ddc4c45 (PR dagger#13243) added a TypeScript persistence subtest in
engine_persistence_test.go that calls modInit with inline source. The
dynamic module init helpers it relied on were already removed in
29f2782 (workspace branch is moving away from 'dagger module init'),
so the integration test package fails to compile, which fails go:lint
and every test-split target.

Switch the subtest to moduleFixture with typescript/runtime-cache-control,
which already defines the same testAlwaysCache() function with identical
crypto.randomBytes semantics. Use daggerCallAt(".", ...) to match the
fixture-based pattern used by the sibling go subtest.

Signed-off-by: Yves Brissaud <[email protected]>
eunomie added a commit to eunomie/dagger that referenced this pull request May 30, 2026
…attern

Commit ddc4c45 (PR dagger#13243) added a TypeScript persistence subtest in
engine_persistence_test.go that calls modInit with inline source. The
dynamic module init helpers it relied on were already removed in
29f2782 (workspace branch is moving away from 'dagger module init'),
so the integration test package fails to compile, which fails go:lint
and every test-split target.

Switch the subtest to moduleFixture with typescript/runtime-cache-control,
which already defines the same testAlwaysCache() function with identical
crypto.randomBytes semantics. Use daggerCallAt(".", ...) to match the
fixture-based pattern used by the sibling go subtest.

Signed-off-by: Yves Brissaud <[email protected]>
eunomie added a commit to eunomie/dagger that referenced this pull request May 30, 2026
…attern

Commit ddc4c45 (PR dagger#13243) added a TypeScript persistence subtest in
engine_persistence_test.go that calls modInit with inline source. The
dynamic module init helpers it relied on were already removed in
29f2782 (workspace branch is moving away from 'dagger module init'),
so the integration test package fails to compile, which fails go:lint
and every test-split target.

Switch the subtest to moduleFixture with typescript/runtime-cache-control,
which already defines the same testAlwaysCache() function with identical
crypto.randomBytes semantics. Use daggerCallAt(".", ...) to match the
fixture-based pattern used by the sibling go subtest.

Signed-off-by: Yves Brissaud <[email protected]>
eunomie added a commit that referenced this pull request May 30, 2026
…attern

Commit ddc4c45 (PR #13243) added a TypeScript persistence subtest in
engine_persistence_test.go that calls modInit with inline source. The
dynamic module init helpers it relied on were already removed in
29f2782 (workspace branch is moving away from 'dagger module init'),
so the integration test package fails to compile, which fails go:lint
and every test-split target.

Switch the subtest to moduleFixture with typescript/runtime-cache-control,
which already defines the same testAlwaysCache() function with identical
crypto.randomBytes semantics. Use daggerCallAt(".", ...) to match the
fixture-based pattern used by the sibling go subtest.

Signed-off-by: Yves Brissaud <[email protected]>
tiborvass pushed a commit that referenced this pull request Jun 1, 2026
…attern

Commit ddc4c45 (PR #13243) added a TypeScript persistence subtest in
engine_persistence_test.go that calls modInit with inline source. The
dynamic module init helpers it relied on were already removed in
29f2782 (workspace branch is moving away from 'dagger module init'),
so the integration test package fails to compile, which fails go:lint
and every test-split target.

Switch the subtest to moduleFixture with typescript/runtime-cache-control,
which already defines the same testAlwaysCache() function with identical
crypto.randomBytes semantics. Use daggerCallAt(".", ...) to match the
fixture-based pattern used by the sibling go subtest.

Signed-off-by: Yves Brissaud <[email protected]>
shykes pushed a commit that referenced this pull request Jun 1, 2026
…attern

Commit ddc4c45 (PR #13243) added a TypeScript persistence subtest in
engine_persistence_test.go that calls modInit with inline source. The
dynamic module init helpers it relied on were already removed in
29f2782 (workspace branch is moving away from 'dagger module init'),
so the integration test package fails to compile, which fails go:lint
and every test-split target.

Switch the subtest to moduleFixture with typescript/runtime-cache-control,
which already defines the same testAlwaysCache() function with identical
crypto.randomBytes semantics. Use daggerCallAt(".", ...) to match the
fixture-based pattern used by the sibling go subtest.

Signed-off-by: Yves Brissaud <[email protected]>
tiborvass pushed a commit that referenced this pull request Jun 1, 2026
…attern

Commit ddc4c45 (PR #13243) added a TypeScript persistence subtest in
engine_persistence_test.go that calls modInit with inline source. The
dynamic module init helpers it relied on were already removed in
29f2782 (workspace branch is moving away from 'dagger module init'),
so the integration test package fails to compile, which fails go:lint
and every test-split target.

Switch the subtest to moduleFixture with typescript/runtime-cache-control,
which already defines the same testAlwaysCache() function with identical
crypto.randomBytes semantics. Use daggerCallAt(".", ...) to match the
fixture-based pattern used by the sibling go subtest.

Signed-off-by: Yves Brissaud <[email protected]>
social4hyq pushed a commit to social4hyq/homebrew-core that referenced this pull request Sep 20, 2026
dagger 0.21.1

Created-by: HarmonybrewBot
Commit-by: HarmonybrewBot
Merged-by: HarmonybrewBot
Description: Created by `brew bump`

---

Created with `brew bump-formula-pr`.<details>
  <summary>release notes</summary>
  <pre>## v0.21.1 - 2026-05-29

### Added
- Add native GraphQL interfaces and unified object IDs in DagQL by @vito in dagger/dagger#12041 \
  Dagger now exposes objects through the standard `Node` interface and `ID` scalar, enabling APIs to accept generic Dagger objects while preserving SDK compatibility through legacy `FooID` and `loadFooFromID` views for older clients.

### Fixed
- Python SDK: fix unhandled module registration cases and bugs by removing the AST-based module analyzer and returning to runtime introspection by @eunomie in dagger/dagger#13251
- Fix Go module generation to avoid unnecessary dependency churn in generated `go.mod` and `go.sum` files by @sipsma in dagger/dagger#13244
- Fix registry authentication so `withRegistryAuth` credentials are not incorrectly skipped and authenticated publishes keep working after anonymous pulls to the same registry by @marcosnils + @sipsma in dagger/dagger#13255 dagger/dagger#13256
- Fix published image layer structure so `withDirectory` and `withFile` operations preserve expected layer boundaries instead of being squashed into a few large layers by @sipsma in dagger/dagger#13242
- Fix Dockerfile `RUN --mount=type=bind` conversion when the bind source selector points to a regular file, improving compatibility with file and directory bind mounts by @sipsma in dagger/dagger#13273
- Fix module source cache dependency retention, including ephemeral `missing shared result` errors after cache persistence or engine restarts by @sipsma in dagger/dagger#13243
- Fix a bug where some cache entries did not have their size calculated during background and shutdown pruning by @sipsma in dagger/dagger#13225
- Fix repeated `op://` 1Password secret reads by caching resolved 1Password secret values during a run, avoiding provider rate limits when the same secret is mounted or read multiple times by @matipan in dagger/dagger#13249
- Fix Windows Changeset exports so `RemovePaths` entries cannot remove files outside the selected export root through backslash or absolute-path interpretation by @marcosnils in dagger/dagger#13222
- Fix `dagger --x-release` for tagged releases so semver refs download release artifacts instead of looking in the main-build artifact namespace, and prevent local runner override environment from leaking into the re-executed CLI by @grouville in dagger/dagger#13259

### What to do next?
- Read the [documentation](https://docs.dagger.io)
- Join our [Discord server](https://discord.gg/dagger-io)
- Follow us on [Twitter](https://twitter.com/dagger_io)

</pre>
  <p>View the full release notes at <a href="https://github.com/dagger/dagger/releases/tag/v0.21.1">https://github.com/dagger/dagger/releases/tag/v0.21.1</a>.</p>
</details>
<hr>

See merge request: Harmonybrew/homebrew-core!9585
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