Prune only what no release names
31 October 2026 · Guardrails & fail-closed · the engineering team
The story
Our deploy used to leave stale assets in the bucket. The code comment said why: an old page still in a cache may name them. The project notes said to prune them by hand now and then. Then we taught the deploy to do it. After a good live check, it deletes the assets that none of the site's newest three releases names, and it records what it deleted. A release in that window with no file list prunes nothing. A prune error fails the deploy and is recorded. A dry run lists the prune, and a flag skips it.
The prune also kept one more release: the one from the newest deploy recorded as deployed. That covers the case where several refreshes have pushed the serving release out of the three-release window. It left a gap, though. A deploy can upload a release, pass the live check, and then fail on a later step, such as a prune or an invalidation. That deploy is recorded as failed, so the prune did not count its release as one the edge may be serving.
We wrote the test for that case. A second deploy passes its live check, then the invalidation is refused, and the deploy is recorded as failed with its release. The test adds an asset that only that release names. It then runs three refreshes, which move the window past the release. The assertion is that a dry run does not list that asset for pruning. The fix keeps the release of the newest deployed record. It also keeps the release of the newest failed record that has one, when that record is newer.
The same function refuses when a kept release is missing from the list of releases. In that case it prunes nothing and says why.
The pattern
A prune should delete only what no release names. Which releases count is the real question. "The ones that succeeded" is the wrong answer, because a deploy that failed after its upload may still have put its release in front of readers. The status in the record says how the deploy ended. It does not say what the edge is serving.
So the keep list is built from what the edge may serve. A window of recent releases is one source. The last good deploy is another. A failed deploy that got as far as an upload is a third. When the prune cannot place one of those releases, or a release in the window has no file list, it does nothing and reports why. Deleting too little costs some storage. Deleting an asset a served page names costs a broken page.
Try it
Before you let a deploy delete anything, write down every way a release can reach readers. Include a deploy that uploaded and then failed. For each one, write a test that creates it, moves your keep window past it, and asserts the prune does not list its files. Then make the prune return nothing, with a warning, whenever a release it has to keep is missing or has no file list.