dagger/dagger · error

failed to get usage for %s

Error message

failed to get usage for %s

What it means

In sizeFromMetadata (cacheRecord size computation), a non-NotFound failure from Snapshotter.Usage(ctx, snapshotID) is wrapped as "failed to get usage for %s". The code computes a cache record's disk size by querying the snapshotter; NotFound is deliberately swallowed (treated as zero usage, e.g. blob-only or pruned records), but any other failure — I/O error, snapshotter corruption — aborts the size calculation.

Source

Thrown at engine/snapshots/refs.go:168

func sizeFromMetadata(
	ctx context.Context,
	sizeG *flightcontrol.Group[int64],
	cm *snapshotManager,
	md *cacheMetadata,
	snapshotID string,
) (int64, error) {
	return sizeG.Do(ctx, snapshotID, func(ctx context.Context) (int64, error) {
		s := md.getSize()
		if s != sizeUnknown {
			return s, nil
		}

		var usage snapshots.Usage
		if !md.getBlobOnly() {
			var err error
			usage, err = cm.Snapshotter.Usage(ctx, snapshotID)
			if err != nil && !errors.Is(err, cerrdefs.ErrNotFound) {
				return s, errors.Wrapf(err, "failed to get usage for %s", snapshotID)
			}
		}

		if dgst := md.getBlob(); dgst != "" {
			added := make(map[digest.Digest]struct{})
			info, err := cm.ContentStore.Info(ctx, dgst)
			if err == nil {
				usage.Size += info.Size
				added[dgst] = struct{}{}
			}
			walkBlobVariantsOnly(ctx, cm.ContentStore, dgst, func(desc ocispecs.Descriptor) bool {
				if _, ok := added[desc.Digest]; !ok {
					if info, err := cm.ContentStore.Info(ctx, desc.Digest); err == nil {
						usage.Size += info.Size
						added[desc.Digest] = struct{}{}
					}
				}
				return true

View on GitHub (pinned to 82ba2681db)

Solutions

  1. Check the snapshotter's on-disk state under /var/lib/containerd/io.containerd.snapshotter... for the snapshotID
  2. Verify file permissions on the snapshot storage directory
  3. Restart containerd to recover a wedged snapshotter
  4. If the snapshot is genuinely gone, clear the record's metadata or let GC prune the record
Defensive patterns

Strategy: try-catch

Validate before calling

if _, err := cm.Snapshotter.Stat(ctx, snapshotID); err != nil {
    // snapshot gone or unreadable — size will fall back to blob metadata
}

Try / catch

usage, err := cm.Snapshotter.Usage(ctx, snapshotID)
if err != nil && !errors.Is(err, cerrdefs.ErrNotFound) {
    // mirror the library: only non-NotFound is fatal
    return errors.Wrapf(err, "failed to get usage for %s", snapshotID)
}

Prevention

When it happens

Trigger: Calling Size()/usage accounting on a cache record whose snapshotID exists in metadata but whose snapshotter Usage lookup fails with something other than ErrNotFound.

Common situations: Overlayfs/native snapshot directories corrupted or partially deleted on disk; permission problems on the containerd state dir; snapshotter driver misbehaving after unclean shutdown.

Related errors


AI-assisted analysis of dagger/dagger@82ba2681db (2026-09-05). Data as JSON: /api/errors/daba031e36f493a7. Report an issue: GitHub.