Skip to content

cache: make in-use pruning opt-out and guard DiskUsage against pruned parents - #34

Merged
piob-io merged 2 commits into
masterfrom
devin/1788363401-prune-inuse-switch
Sep 2, 2026
Merged

piob-io merged 2 commits into
masterfrom
devin/1788363401-prune-inuse-switch

Conversation

@piob-io

@piob-io piob-io commented Sep 2, 2026 •

Copy link
Copy Markdown

Summary

Fixes the buildkitd SIGSEGV at cache/manager.go DiskUsage that fires after a buildctl prune --all --keep-storage N reclaimed anything, without changing what that prune does for existing --keep-storage users.

Root cause. #29 lets pruneOnce pick records with len(cr.refs) > 0 when all && keepBytes != 0. A parent layer's only refs are usually the structural layerParent refs of its children, so a size prune can remove a parent while the children survive. DiskUsage rebuilds the graph from cm.records and does m[p].refs-- for each child's parent without checking the parent is still there → nil deref. Upstream never hits it because upstream prune only ever removes leaves (len(cr.refs) == 0).

Changes

  • DiskUsage: skip parents missing from m instead of dereferencing nil.
  • New worker.oci toml key pruneInUse (default true = today's behavior) plumbed config.OCIConfig.PruneInUse → base.WorkerOpt.PruneInUse → cache.ManagerOpt.PruneInUse; the containerd worker hardcodes true. pruneOnce becomes
    if len(cr.refs) > 0 && (!cm.pruneInUse || !opt.all || opt.keepBytes == 0) { continue }
    so pruneInUse = false restores upstream leaf-first semantics (records with refs are never candidates; chains collapse bottom-up across prune() iterations).
  • Tests: TestPruneKeepStorageInUseDiskUsage (parent+child chain, size prune removes the in-use parent, DiskUsage must not panic — reproduces the production SIGSEGV without the guard) and TestPruneKeepStorageLeafFirst (pruneInUse=false removes the child only).

Default stays on so setup-docker-builder@v1 users of max-cache-size-mb (which relies on the #29 behavior with GC disabled) are unaffected; setup-docker-builder@release/v2 will write pruneInUse = false since it runs with GC enabled and never needs in-use pruning.

cache package tests: TestMergeOp fails identically on master in this environment (size assertion, filesystem-dependent); everything else passes.

Link to Devin session: https://app.devin.ai/sessions/5c8deaae10f14cf49877e6f03ff873f9
Open in Devin Desktop: https://app.devin.ai/desktop/session/5c8deaae10f14cf49877e6f03ff873f9?variant=devin
Requested by: @piob-io


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled. (Staging)

… parents

A size-bounded prune --all may remove a record that still has live refs,
including a parent whose only refs are its child records. The next
DiskUsage then dereferences a nil entry for the missing parent and the
daemon crashes with SIGSEGV.

Guard the parent rescan in DiskUsage so a missing parent is skipped, and
put the in-use pruning behavior behind a new worker.oci pruneInUse toml
key. It defaults to true so existing users of prune --keep-storage keep
their current behavior; setting it to false restores upstream leaf-first
semantics where records with refs are never prune candidates.

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@devin-ai-integration

Copy link
Copy Markdown

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

@piob-io
piob-io merged commit b941f1c into master Sep 2, 2026
215 of 216 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants