Skip to content

config: fix a default GC policy filter never matching any record - #6856

Merged
tonistiigi merged 2 commits into
moby:masterfrom
ZRHann:fix-default-gc-policy-filter
Jun 10, 2026
Merged

tonistiigi merged 2 commits into
moby:masterfrom
ZRHann:fix-default-gc-policy-filter

Conversation

@ZRHann

@ZRHann ZRHann commented Jun 10, 2026 •

Copy link
Copy Markdown
Contributor

Summary

The first default GC policy is meant to prune the most easily reproducible cache (local sources, cache mounts, git checkouts) once the build cache exceeds 512MB and the data has been unused for 48h.

Its filter was written as a single comma-joined string:

Filters: []string{"type==source.local,type==exec.cachemount,type==source.git.checkout"}

Each element of GCPolicy.Filters is passed to containerd/filters.ParseAll. Selectors separated by commas within a single string are ANDed together (ParseAll only ORs across separate slice elements). Since a record only ever has a single type, the expression type==source.local AND type==exec.cachemount AND type==source.git.checkout can never be satisfied — so this policy matched nothing and was effectively a no-op.

Fix

Split the filter into separate slice elements so they are ORed, matching the documented intent. This is also the form that already works when the array is written in buildkitd.toml:

filters = ["type==source.local", "type==exec.cachemount", "type==source.git.checkout"]

A regression test verifies the first default policy's filter matches the three reproducible record types and not regular build cache.

The first default GC policy is meant to prune the most easily
reproducible cache (local sources, cache mounts, git checkouts) once it
exceeds 512MB and has not been used for 48h. Its filter was written as a
single comma-joined string:

    "type==source.local,type==exec.cachemount,type==source.git.checkout"

Each element of the Filters slice is passed to
containerd/filters.ParseAll, where commas within one string are ANDed
together. A record only ever has a single type, so the AND can never be
satisfied: this policy matched nothing and was effectively a no-op.

Split the filter into separate slice elements so they are ORed, matching
the documented intent and the array form already used in user
buildkitd.toml configs.

Signed-off-by: ZRHann <zrhann@foxmail.com>
@ZRHann ZRHann changed the title config: fix default GC policy filter never matching any record config: fix a default GC policy filter never matching any record Jun 10, 2026
@ZRHann
ZRHann force-pushed the fix-default-gc-policy-filter branch from 67340aa to b69e279 Compare June 10, 2026 13:34
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
@tonistiigi tonistiigi added this to the v0.31.0 milestone Jun 10, 2026
@ZRHann

ZRHann commented Jun 10, 2026

Copy link
Copy Markdown
Contributor Author

@tonistiigi thanks for the review! Do you think we should drop the test, though? It only checks the specific types the default happens to use, so it's really just a change detector. I couldn't think of a better, more general way to test this.

@tonistiigi

Copy link
Copy Markdown
Member

@ZRHann I think it is fine atm. This filters API is so confusing that it is better to force updating the test if something changes to make sure nothing was missed.

@tonistiigi
tonistiigi merged commit b0d67c2 into moby:master Jun 10, 2026
167 of 169 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