#13952·dagger

Clean shutdown still discards the entire local cache: dagql_import_failure on a snapshot lease the disk GC already evicted

Author: alex-percyCreated Aug 22, 2026Updated Sep 26, 2026

What happened?

A textbook clean shutdown is not sufficient to preserve the local cache. On restart the engine can discard everything with reason=dagql_import_failure, because persisted DagQL state references a containerd snapshot lease that no longer exists on disk.

Measured 2026-08-22 on v0.21.8, restarting two engines drained (dagger_connected_clients == 0) within twenty minutes of each other. The smaller one kept its 160 GB cache. The larger one lost its 428 GB cache, ~15 minutes unready, despite writing the clean marker:

--- outgoing pod ---
19:01:42.565  dagql prune skip policy: no reclaim target   usedBytes=428152591763
19:01:42.654  starting dagql cache close
19:01:44.170  marking dagql cache clean shutdown
19:01:44.179  successfully marked clean shutdown in persistence metadata
19:01:44.188  completed dagql cache close successfully

--- incoming pod, 19 seconds later ---
19:02:03.471  WARN  dagql persistence import failed; wiping and cold-starting
              err="attach imported result 114131864 owner lease \"snapshot\":
                   jg5yg9stux2blzbg4iyqmauz9: not found"
19:02:03.494  WARN  local cache state invalid; resetting worker and dagql persistence state
              reason=dagql_import_failure  error=<nil>
19:02:03.494  INFO  discarding dagql cache without persistence  hasSQLDB=true hasPersistDB=true

reason=dagql_import_failure, not unclean_shutdown. The shutdown prune reclaimed nothing (no reclaim target) and the cache close took two seconds, so the drift did not happen during shutdown — the persistence store and the snapshot store had already diverged during normal operation.

Suspected cause

The engine that failed had been sitting at its GC cap (gc.maxUsedSpace: 400GB, actual 428.15 GB) for days, so disk GC was evicting continuously. The engine that imported fine reported no reclaim target on every prune tick. That suggests disk GC can evict a snapshot while a persisted DagQL root still holds a reference to it, and nothing reconciles the two before the next import.

Impact

For an operator this is the worse of the two failure modes, because it is not preventable from outside the engine. The grace-period race (#13951) is fixable with a drain and a longer terminationGracePeriodSeconds — we verified that works. This one is not: it makes every restart of a large, busy engine a coin-flip on the entire cache, and the risk appears to increase the longer the engine runs at its cap, which is exactly the state a long-lived engine converges to.

It also compounds with the DagQL cache-metadata growth that #13846 fixes: that growth is what forces the restart, and running at the disk cap is what makes the restart destructive.

Suggested directions

  • Make the import failure partial rather than total — drop the roots whose leases are missing and keep the rest. Discarding a 428 GB cache because one result of ~17,000 lost its snapshot is a very large blast radius for a localised inconsistency.
  • Prevent the drift at the source: have disk GC treat a persisted DagQL root's snapshot references as in-use, or drop the corresponding persisted entry when it evicts one.
  • Failing both, reconcile at shutdown — validate persisted references against the snapshot store before writing clean_shutdown=1, and prune the dangling ones.

Dagger version

v0.21.8 (registry.dagger.io/engine:v0.21.8), dagger-helm chart 0.21.8, DaemonSet on k3s, overlayfs snapshotter.