Skip to content

Reclaim the orphaned buildkit cache volume in the docker clean up hook - #117168

Merged
alexey-milovidov merged 4 commits into
masterfrom
ci-reclaim-buildkit-volume
Sep 2, 2026
Merged

alexey-milovidov merged 4 commits into
masterfrom
ci-reclaim-buildkit-volume

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Aug 30, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • CI Fix or Improvement (changelog entry is not required)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Reclaim the cache of an inactive docker-container buildx builder in the docker clean up hook, so a style-checker host does not accumulate build cache until Install packages fails with No space left on device.

Description

Install packages (amd_release) failed on master:

cannot copy extracted data for './usr/lib/debug/usr/bin/clickhouse.debug' to
'/usr/lib/debug/usr/bin/clickhouse.debug.dpkg-new': failed to write (No space left on device)

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=31f27d85ed6a30aa33cb37f57d4610362ab8bfa1&name_0=MasterCI&name_1=Install%20packages%20%28amd_release%29

The host handed the job 4.3 GiB of 58 GiB and the very first test needs about 5 GiB. This has hit master four times in the last 30 days (2026-07-31, 2026-08-03, 2026-08-04, 2026-08-30), always amd_release, and no open issue tracks it.

Root cause. Nothing the job does explains the other 54 GiB. The clean up hook that runs right before it reported Total reclaimed space: 0B for both docker container prune and docker system prune, and only two images were present. The accumulator is a docker-container buildx builder's cache, which lives in a named buildx_buildkit_<node>_state volume, and none of the commands in the hook reclaim it:

  • docker system prune skips volumes without --volumes;
  • docker builder prune talks to the daemon, so it only reclaims the cache of the docker driver builder - which is why it reports 0B on a host that has just built multi-platform images;
  • the hook does prune per builder, but the runner removes every container between jobs, so by the next job the builder is inactive and the prune fails with No such container: buildx_buildkit_default-builder0 - present verbatim in the failing job's log - leaving the cache on disk.

The host had run Docker server image and three Docker keeper image jobs beforehand, each writing gigabytes into that volume; Docker server image alone took it from 24 GiB to 35 GiB used.

Change (one file). Bootstrap each builder before pruning it. An inactive docker-container builder gets its buildkit container back, the existing per-builder prune then reaches the cache and empties the volume in place, and the builder entry - default-builder included - stays registered for the docker image jobs that run later on the same host. Additionally remove a buildx_buildkit_<node>_state volume whose node is not one of the nodes docker buildx ls lists: that one is unreachable by any prune. The comparison is on the exact node name, or buildx_buildkit_default-builder0_state would look reachable through the unrelated implicit default builder, and the sweep is skipped altogether unless the listing succeeded and yielded at least one node, so a failure to enumerate never reads as "nothing is registered". docker volume rm refuses a volume attached to a running container, so a live cache cannot be thrown away here either. Also print docker system df, because the job that runs out of disk space is rarely the job that filled it, and Local Volumes is the row the prunes cannot reclaim.

Validation. Locally against docker 29.1.3 / buildx 0.30.1:

check result
400 MiB build through a docker-container builder, container then removed builder goes inactive, 534 MiB left in buildx_buildkit_orphantest0_state
docker buildx prune -a -f --builder <name> on it ERROR: Error response from daemon: No such container: buildx_buildkit_orphantest0 - the CI error text
docker builder prune -a -f, docker system prune -f on it 0B / volume untouched
docker buildx inspect <name> --bootstrap then the same per-builder prune bootstrap 5.6 s, prune reports Total: 558.7MB, the volume drops to 352 KiB, docker buildx ls still lists the builder as running
stray buildx_buildkit_ghostnode0_state with no builder selected for removal, while the registered builder's volume and the unrelated clickhouse_integration_tests_volume are skipped
default-builder registered and inactive next to default parsed as nodes: ['default-builder0', 'default'], buildx_buildkit_default-builder0_state skipped; after docker buildx rm default-builder the same volume is selected for removal
docker buildx ls failing exit code 125, no nodes, the volume sweep is skipped

What this does not do. It does not raise runner-init's free-space guard (2.86 GiB / 5%), which is below what this job needs, so a host that arrives full for some other reason can still fail it. Related: #113605

Related: #113270
Related: #113032
Related: #112687
Related: #111960


Workflow [PR]
Sync PR [sync-upstream/pr/117168]

Version info

  • Merged into: 26.9.1.567 (included in 26.9 and later)

`Install packages (amd_release)` failed on master with

    cannot copy extracted data for './usr/lib/debug/usr/bin/clickhouse.debug' to
    '/usr/lib/debug/usr/bin/clickhouse.debug.dpkg-new': failed to write (No space left on device)

https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=31f27d85ed6a30aa33cb37f57d4610362ab8bfa1&name_0=MasterCI&name_1=Install%20packages%20%28amd_release%29

The host handed the job 4.3 GiB of 58 GiB, and the very first test needs about
5 GiB. Nothing the job does explains the other 54 GiB: the clean up hook that
runs right before it reported `Total reclaimed space: 0B` for both
`docker container prune` and `docker system prune`, and only two images were
present.

The accumulator is a `docker-container` buildx builder's cache. It lives in a
named `buildx_buildkit_<node>_state` volume, and none of the commands in the
hook reclaim a volume: `docker system prune` skips volumes without `--volumes`,
and `docker builder prune` talks to the daemon, so it only reclaims the cache of
the `docker` driver builder - which is why it reports `0B` on a host that has
just built multi-platform images. The hook does prune per builder, but the
runner removes every container between jobs, so by the time the next job starts
the builder has no buildkit container and the prune fails with
`No such container: buildx_buildkit_default-builder0` - visible in the log of
the failing job - leaving the cache unreachable and on disk. The host had run
`Docker server image` and three `Docker keeper image` jobs beforehand, each
writing gigabytes into that volume; `Docker server image` alone took the host
from 24 GiB to 35 GiB used.

Drop such a builder and remove the volume it leaves behind. `--all-inactive`
keeps a builder whose container is still up, and `docker volume rm` refuses a
volume attached to a running container, so a cache that is still reachable is
pruned by the existing per-builder prune rather than thrown away here. This
mirrors what `_clean_buildx_volumes` in `ci/praktika/native_jobs.py` already
does after the native docker build jobs.

Also print `docker system df`, because the job that runs out of disk space is
rarely the job that filled it, and `Local Volumes` is the row the prunes cannot
reclaim.

Validated locally against docker 29.1.3 / buildx 0.30.1: a 400 MiB build through
a `docker-container` builder leaves a 934 MiB volume that survives
`docker buildx prune --builder`, `docker builder prune -a -f` and
`docker system prune -f` once its container is removed - reproducing the CI
error text exactly - and is reclaimed by the two added commands, while a builder
whose container is still running keeps both its entry and its volume.
The previous commit on this branch carried a truncated tree that dropped every
file outside `.github`, `ci` and `docs`. Restore the tree to `master` and keep
only the intended change to `ci/jobs/scripts/job_hooks/docker_clean_up_hook.py`.
@clickhouse-gh

clickhouse-gh Bot commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [a05b89d]

Summary: ✅


AI Review

Summary

This PR changes the docker clean up hook to bootstrap inactive buildx builders before pruning them, then remove only buildx_buildkit_<node>_state volumes whose exact node is no longer registered. The current head addresses the earlier destructive cases around removing default-builder, prefix-based node matching, and fail-open orphan-volume deletion; I do not see a remaining blocker or major in the code as it stands.

Tests
  • ⚠️ The PR CI visible during review did not run the install / docker jobs that actually exercise this hook on reused tiny runners, so the only execution evidence is the manual Docker 29.1.3 / buildx 0.30.1 validation in the PR description. A smoke run of Install packages (amd_release) or Docker server image on an affected runner would close that gap.
Final Verdict

✅ No remaining review findings on the current head.

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Sep 2, 2026
The review points out that `docker buildx rm --all-inactive --force` is
broader than reclaiming an orphaned cache: on a stock runner the
pre-provisioned `default-builder` is usually just `inactive`, not
unrecoverable, and removing it makes a later bare `docker buildx build`
fall back to the implicit `default` docker driver, besides throwing away a
cache that could have been reused.

Reclaim the space without touching the builder entry: bootstrap each
builder before pruning it, so an `inactive` `docker-container` builder gets
its buildkit container back, the prune reaches the cache and empties the
`buildx_buildkit_<node>_state` volume in place, and the builder stays
registered for the docker image jobs that expect it.

Only a volume whose node belongs to no registered builder is removed - that
one is unreachable by any prune. `docker volume rm` additionally refuses a
volume attached to a running container.

Validated locally against docker 29.1.3 / buildx 0.30.1: a 400 MiB build
through a `docker-container` builder whose container is then removed leaves
a 534 MiB volume and reproduces the CI error text
`ERROR: Error response from daemon: No such container: buildx_buildkit_orphantest0`;
`docker buildx inspect <name> --bootstrap` takes 5.6 s, the following prune
reclaims 558.7 MB, the volume drops to 352 KiB and the builder is still
listed. A stray `buildx_buildkit_ghostnode0_state` volume with no builder is
selected for removal, while the volume of the registered builder is skipped.
Two gaps in the orphan volume sweep, both pointed out in review.

`any(node.startswith(builder) ...)` was not "the node belongs to a
registered builder": a stock runner lists both `default-builder` and the
implicit `default` builder, so `buildx_buildkit_default-builder0_state`
looked reachable through `default` and would never be removed - exactly the
volume this change is about. Parse the node names from the indented
`\_ <node>` rows of `docker buildx ls` and compare against them.

`docker buildx ls` failing left `builders` empty, which made every detached
`buildx_buildkit_*_state` volume look orphaned, including the cache of a
still-registered builder. Skip the sweep unless the listing succeeded and
produced at least one node.

Validated locally on docker 29.1.3 / buildx 0.30.1. With `default-builder`
registered and inactive next to `default`, the parse yields
`builders: ['default-builder', 'default']`,
`nodes: ['default-builder0', 'default']`, and
`buildx_buildkit_default-builder0_state` is skipped; after
`docker buildx rm default-builder` the same volume is selected for removal.
A failing `docker buildx ls` exits 125 with no nodes and the sweep is
skipped.

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok.

@alexey-milovidov alexey-milovidov self-assigned this Sep 2, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Sep 2, 2026
Merged via the queue into master with commit 6ff4042 Sep 2, 2026
174 checks passed
@alexey-milovidov
alexey-milovidov deleted the ci-reclaim-buildkit-volume branch September 2, 2026 21:22
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-ci pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants