GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — engine: prune DAGQL cache by metadata size by sipsma · Pull Request #13846 · dagger/dagger

Conversation

@sipsma

@sipsma sipsma commented Aug 5, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Summary

Persisted DAGQL cache roots can retain substantial in-memory result, e-graph, module, and schema state while consuming little or no physical cache space. Existing automatic pruning is triggered by disk usage, so those roots can remain indefinitely when disk thresholds are not crossed.

This change adds a coarse structural estimate for DAGQL cache metadata:

3072 * results + 512 * terms + 768 * allocated equivalence-class slots

Reading the estimate is O(1) and allocation-free because these counts already exist in the cache. When the estimate exceeds the provisional 4 GiB maximum, the engine uses the existing pruning candidate order and ownership simulation to prune toward 3 GiB. This makes zero- and tiny-disk persisted roots eligible without weakening active-session or unpruneable-root protection.

Disk GC remains independent. Disk-stat failures do not suppress structural pruning, and structural no-progress suppression does not suppress disk policies. The persistence schema remains version 17; an oversized graph may still create an import peak before the scheduled startup trim.

The change also adds:

  • gc.dagqlCache.maxEstimatedBytes and targetEstimatedBytes configuration;
  • dagger_dagql_cache_metadata_estimated_bytes;
  • aggregate-only pruning logs and traces;
  • schema-17 restart/startup coverage, zero-disk integration coverage, race tests, and scale/calibration benchmarks.

The 4 GiB/3 GiB defaults are provisional rollout values. The estimate deliberately approximates cache-owned memory rather than attributing exact retained heap.

Performance

At one million results on the benchmark host:

  • estimate read: 6.5 ns/op, zero allocations;
  • structural snapshot: 1.004 s, versus 2.025 s for the existing disk snapshot path;
  • slowest measured full-prune fixture: 27.318 s;
  • maximum sampled pruning scratch: 888,102,912 bytes;
  • sparse forced class compaction from 1,000,000 slots to 2,000: 31.7 ms write-lock hold.

Testing

On the rebased head:

go test -race ./dagql -run '^(TestCacheMetadata|TestCachePruneMetadata|TestRemovePersistedEdge|TestLazyRefArg)' -count=1
go test -race ./engine/server -run '^(TestResolveDagqlCacheGCConfig|TestGCLocked.*Metadata.*|TestScheduledGCTrimsImportedMetadataWithoutPersistenceReset|TestLocalCachePressureCheckUsesMetadataWhenDiskStatFails|TestMetadataPrune.*|TestMonitorMetadata.*|TestGCSessionCompletionClearsMetadataPruneBlock|TestExplicitPruneClearsMetadataPruneBlock|TestCanceledMonitorMetadataPruneDoesNotSetBlock|TestEnsureWorkspaceLoaded.*)$' -count=1
go test ./dagql ./engine/server ./engine/engineutil ./core/schema -count=1
go test ./cmd/json-schema ./engine/config -count=1
go run ./cmd/json-schema engine.json > /tmp/engine.schema.json
cmp docs/static/reference/engine.schema.json /tmp/engine.schema.json
dagger api call engine-dev test --pkg ./core/integration --run='TestLocalCache/TestDagqlMetadataGCProtectsActiveZeroDiskResults'
dagger api call engine-dev test --pkg ./core/integration --run='TestEngine/TestPrometheusMetrics'

The metadata-pressure E2E passed with trace b22591406cd051b4de63502a8d7ae884; the metrics E2E passed with trace 9146773cba455b106d9255c81edf24e8.

After the lint-only follow-up commit, the affected server race suite and repository lint check also passed:

go test -race ./engine/server -run '^(TestResolveDagqlCacheGCConfig|TestGCLocked.*Metadata.*|TestScheduledGCTrimsImportedMetadataWithoutPersistenceReset|TestLocalCachePressureCheckUsesMetadataWhenDiskStatFails|TestMetadataPrune.*|TestMonitorMetadata.*|TestGCSessionCompletionClearsMetadataPruneBlock|TestExplicitPruneClearsMetadataPruneBlock|TestCanceledMonitorMetadataPruneDoesNotSetBlock)$' -count=1
dagger check 'golang:lint-all'

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
sipsma added 19 commits August 5, 2026 16:58
@sipsma
docs: design metadata-aware cache pruning
615a02d
Signed-off-by: Erik Sipsma <[email protected]>
@sipsma
docs: refine metadata pruning design
b087da9
Signed-off-by: Erik Sipsma <[email protected]>
@sipsma
docs: rewrite metadata pruning design
fa45dbd
Signed-off-by: Erik Sipsma <[email protected]>
@sipsma
docs: clarify metadata pruning execution
0a46329
Signed-off-by: Erik Sipsma <[email protected]>
@sipsma
docs: specify candidate snapshot locking
d114c9a
Signed-off-by: Erik Sipsma <[email protected]>
@sipsma
docs: simplify DAGQL metadata pruning design
d801635
Signed-off-by: Erik Sipsma <[email protected]>
@sipsma
docs: address metadata pruning council review
27fc2b5
Signed-off-by: Erik Sipsma <[email protected]>
@sipsma
docs: clarify metadata pruning trigger and calibration
dc1e998
Signed-off-by: Erik Sipsma <[email protected]>
@sipsma
dagql: prune cache by metadata estimate
348fbe2
Signed-off-by: Erik Sipsma <[email protected]>
@sipsma
engine: schedule DAGQL metadata pruning
4573145
Signed-off-by: Erik Sipsma <[email protected]>
@sipsma
dagql: silence untriggered metadata prune output
73687bb
Signed-off-by: Erik Sipsma <[email protected]>
@sipsma
test: cover automatic DAGQL metadata pruning
49c3302
Signed-off-by: Erik Sipsma <[email protected]>
@sipsma
dagql: calibrate metadata class estimate
c81de1c
Lower the class-slot coefficient to 768 bytes after the required 200k churn benchmark measured the 1024-byte hypothesis at a 2.199 estimate-to-post-GC-heap ratio. The calibrated coefficient measures 1.649 while preserving the approved structural formula and keeping a common one-million-entry graph above the 4 GiB trigger.

Signed-off-by: Erik Sipsma <[email protected]>
@sipsma
test: benchmark DAGQL metadata pruning
ca83937
Signed-off-by: Erik Sipsma <[email protected]>
@sipsma
docs: document DAGQL metadata pruning
d032d00
Signed-off-by: Erik Sipsma <[email protected]>
@sipsma
engine: tighten metadata pruning correction coverage
686e238
Signed-off-by: Erik Sipsma <[email protected]>
@sipsma
test: measure sparse metadata class compaction
938cc52
Signed-off-by: Erik Sipsma <[email protected]>
@sipsma
test: keep metadata pruning workload active longer
3b5780b
Signed-off-by: Erik Sipsma <[email protected]>
@sipsma
docs: clarify metadata pruning calibration defaults
06c452b
Signed-off-by: Erik Sipsma <[email protected]>
@sipsma
sipsma requested a review from a team as a code owner August 5, 2026 17:11
@sipsma
sipsma force-pushed the metadata-memory-pruning-implementer-d394f80d branch from 505daef to 06c452b Compare August 5, 2026 17:13
@sipsma
engine: satisfy cache pruning lints
b19467f
Signed-off-by: Erik Sipsma <[email protected]>
@grouville
grouville self-requested a review August 5, 2026 19:58
grouville
grouville approved these changes Aug 5, 2026
View reviewed changes

@grouville grouville left a comment •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While testing this branch I think I might have found a small race in pruning. It may be a known trade-off, so genuine question at the end, AND, as it's best effort, approving to unblock. LGTMm after the linting issues get fixed ✅

The scenario:

  1. Pruning starts by taking a snapshot of the results that active sessions are using, and builds its plan from that.
  2. Right after that, a new session gets a cache hit on a persisted result.
  3. Pruning applies the plan and deletes that result's persisted edge. Before deleting, it re-checks the unpruneable flag, but not whether a session started using the result in the meantime.

Nothing crashes: the session keeps its reference and finishes fine. But when the session closes, the result is dropped from the cache, so the next run has to rebuild it. This matters more with this PR, because metadata pruning now runs in the background whenever the estimate goes over the limit: exactly when sessions are live and getting hits.

I've tried checking the docs you made on the subject, it seems to read both ways: "ownership may have changed... The implementation accepts that", but also "prune will not cut it while it is still in that active closure".

I guess it's an accepted trade-off, just questioning wether it's worth closing?

In case it's the latter, I've made a small repro and a possible fix: grouville/dagger@repro-dagql-prune-active-session-race

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@sipsma

sipsma commented Aug 5, 2026

Copy link
Copy Markdown
Contributor Author

While testing this branch I think I might have found a small race in pruning. It may be a known trade-off, so genuine question at the end, AND, as it's best effort, approving to unblock, after the linting issue gets fixed ✅

The scenario:

1. Pruning starts by taking a snapshot of the results that active sessions are using, and builds its plan from that.

2. Right after that, a new session gets a cache hit on a persisted result.

3. Pruning applies the plan and deletes that result's persisted edge. Before deleting, it re-checks the `unpruneable` flag, but not whether a session started using the result in the meantime.

Nothing crashes: the session keeps its reference and finishes fine. But when the session closes, the result is dropped from the cache, so the next run has to rebuild it. This matters more with this PR, because metadata pruning now runs in the background whenever the estimate goes over the limit: exactly when sessions are live and getting hits.

I've tried checking the docs you made on the subject, it seems to read both ways: "ownership may have changed... The implementation accepts that", but also "prune will not cut it while it is still in that active closure".

I guess it's an accepted trade-off, just questioning wether it's worth closing?

In case it's the latter, I've made a small repro and a possible fix: grouville/dagger@repro-dagql-prune-active-session-race

That scenario was present before the changes here and while it's a legit possibility it is indeed something we just accept as a tradeoff. The problem is that rechecking adds quite a bit of overhead (i.e. the fix you linked to has to re-scan a potentially large map while holding an contended lock and repeats that work for each edge being considered for removal). We don't want pruning to be a "stop-the-world" type GC and accept that what gets pruned and what gets retained is intrinsically timing and heuristic based anyways, which is okay since it's managing a cache (as opposed to a database or something).

grouville reacted with heart emoji
All reactions
  • ❤️ 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@sipsma
sipsma merged commit 3755efc into dagger:main Aug 5, 2026
88 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@sipsma sipsma mentioned this pull request Aug 12, 2026
[backport-0.21] engine: prune DAGQL cache by metadata size #13886
Merged
@alex-percy alex-percy mentioned this pull request Aug 22, 2026
Clean shutdown still discards the entire local cache: dagql_import_failure on a snapshot lease the disk GC already evicted #13952
Open
@BrewTestBot BrewTestBot mentioned this pull request Aug 26, 2026
dagger 0.21.9, pin [email protected] Homebrew/homebrew-core#300766
Merged
@scottames-github-bot scottames-github-bot Bot mentioned this pull request Aug 31, 2026
chore(deps): update ⬆️ mise-packages scottames/dots#1043
Merged
1 task
@scottames-github-bot scottames-github-bot Bot mentioned this pull request Sep 4, 2026
chore(deps): update ⬆️ dagger to v0.21.9 scottames/dots#1050
Merged
1 task
@apercivall apercivall mentioned this pull request Sep 19, 2026
engine: release snapshot metadata when its snapshot is collected #14251
Closed
social4hyq pushed a commit to social4hyq/homebrew-core that referenced this pull request Sep 20, 2026
HarmonybrewBot HarmonybrewBot
!17786 merge bump-dagger-0.21.9 into main
0cd8be6
dagger 0.21.9

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.9 - 2026-08-25

### Added
- Added SSHFS-backed volumes, allowing remote filesystems to be mounted into containers without copying their contents into Dagger's content store by @sipsma in dagger/dagger#13462

### Fixed
- `Container.withDirectory` and `Directory.withDirectory` no longer restore by @sipsma in dagger/dagger#13848 \
  deleted nested files after execs remove and recreate an ancestor
  directory.
- Engine client enumeration no longer blocks behind another session's by @sipsma in dagger/dagger#13542 \
  initialization or teardown, preventing Cloud keeper heartbeats from stalling
  and live engines from being suspended.
- Session teardown now runs in the background after the main client disconnects, by @sipsma in dagger/dagger#13681 \
  preventing shutdown responses from timing out while the engine releases
  session-owned cache results.
- The engine now bounds retained DAGQL cache metadata independently of disk by @sipsma in dagger/dagger#13846 \
  usage by pruning cold persisted results when the structural estimate exceeds
  its configured limit. This may mitigate metadata growth at scale while
  preserving active and engine-lifetime cache roots.
- Registry protocol probes no longer appear as scary errors in progress output by @vito in dagger/dagger#13410 \
  when image pulls or publishes succeed, while genuine registry failures remain
  visible.
- Registry authentication no longer invalidates downstream container cache reuse across sessions when applied before or after `Container.from` by @sipsma in dagger/dagger#13901

### 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.9">https://github.com/dagger/dagger/releases/tag/v0.21.9</a>.</p>
</details>
<hr>

See merge request: Harmonybrew/homebrew-core!17786
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@grouville grouville grouville approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@sipsma @grouville
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.