dagger/dagger · error

metadata prune: target estimated bytes must be positive and

Error message

metadata prune: target estimated bytes must be positive and lower than maximum

What it means

PruneMetadataEstimate requires 0 < targetBytes < maximumBytes: the target must be positive and strictly below the maximum so prune can shrink the cache to a level under the cap. Violating this invariant aborts the prune with this error.

Source

Thrown at dagql/cache_prune.go:127

	started := time.Now()
	report.MaximumEstimatedBytes = maximumBytes
	report.TargetEstimatedBytes = targetBytes
	defer func() {
		report.Duration = time.Since(started)
		if report.Triggered && c != nil {
			c.traceMetadataPruneFinished(ctx, report, rerr)
			metadataPruneLog(ctx, report, rerr)
		}
	}()

	if c == nil {
		return report, fmt.Errorf("metadata prune: nil cache")
	}
	if maximumBytes <= 0 {
		return report, fmt.Errorf("metadata prune: maximum estimated bytes must be positive")
	}
	if targetBytes <= 0 || targetBytes >= maximumBytes {
		return report, fmt.Errorf("metadata prune: target estimated bytes must be positive and lower than maximum")
	}
	if err := ctx.Err(); err != nil {
		return report, err
	}

	c.egraphMu.Lock()
	report.BeforeCompaction = c.cacheMetadataEstimateLocked()
	report.AfterInitialCompaction = report.BeforeCompaction
	report.AfterPrune = report.BeforeCompaction
	if report.BeforeCompaction.EstimatedBytes <= maximumBytes {
		c.egraphMu.Unlock()
		return report, nil
	}
	report.Triggered = true
	c.traceMetadataPruneStarted(ctx, maximumBytes, targetBytes)
	_, report.InitialCompactionOldClassSlots, report.InitialCompactionNewClassSlots = c.compactEqClassesLocked(true)
	report.AfterInitialCompaction = c.cacheMetadataEstimateLocked()
	report.AfterPrune = report.AfterInitialCompaction

View on GitHub (pinned to 82ba2681db)

Solutions

  1. Ensure targetBytes is strictly between 0 and maximumBytes
  2. Check argument order and derivation (e.g. target = max * 0.8)
  3. Add caller-side validation before invoking prune

Example fix

// before
report, err := cache.PruneMetadataEstimate(ctx, max, max) // invalid
// after
target := max * 80 / 100
report, err := cache.PruneMetadataEstimate(ctx, max, target)
Defensive patterns

Strategy: validation

Validate before calling

if targetBytes <= 0 || targetBytes >= maxBytes {
    return fmt.Errorf("targetBytes must be in (0, %d), got %d", maxBytes, targetBytes)
}
report, err := cache.PruneMetadataEstimate(ctx, maxBytes, targetBytes)

Prevention

When it happens

Trigger: Calling PruneMetadataEstimate with targetBytes <= 0, or targetBytes >= maximumBytes (equal values included) — e.g. miscomputed ratios (target==max), inverted arguments, or zero target from unset config.

Common situations: Configuration where target and max are set to the same value; passing arguments in the wrong order (target, max) swapped; target derived as a percentage that rounds to 0 or 100%.

Related errors


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