Carry an unfinished invalidation into the next run
2 November 2026 · Guardrails & fail-closed · the engineering team
The story
Our deploy removes keys from the store, both files that are no longer in the release and old ones it prunes, and then asks the CDN to invalidate those paths in one request. If that request is refused, the deploy ends as failed. Its record lists the removed and pruned keys, and the invalidation field is empty. The keys are gone from the store, and nothing has told the edge to forget them.
We changed the deploy to read that record. Before it plans any upload, it looks at the newest record for the target and site. If that record is a failed deploy, not an undeploy, with an empty invalidation and at least one deleted key, the deploy invalidates those paths first and writes the result into its own record. If that catch-up is refused, the deploy fails before any upload and writes no record, so the failed one stays newest and the next run tries the catch-up again. A dry run lists the catch-up and issues nothing. The tests cover the cases where nothing should happen: an undeploy record, a deployed record, a record that already has an invalidation, and a record where nothing was deleted. After a successful catch-up, the next rerun finds a deployed record and issues no second one.
The CloudFront call now makes up to three attempts, waiting 500ms and then 2000ms, and an access-denied or 403 error is thrown at once. All attempts share one caller reference, so a create that landed but whose reply was lost is not made twice. And when a deploy runs with no invalidator, it no longer drops the catch-up: the new record carries the keys, the warning says they are carried to the next deploy, and a later deploy with an invalidator issues them. A corrupt newest record now stops the deploy with an error that names the file.
The pattern
A failed step that was meant to follow a deletion should leave enough in the record for the next run to finish it. Here the record holds the deleted keys and an empty invalidation, and the next run treats that pair as work still owed. The run does the owed work before it does anything new, and it fails closed if it cannot: no upload, no new record, and the old record stays where the next run will find it.
The same idea covers the case where the work cannot be done at all. If there is no invalidator, the debt moves into the new record instead of vanishing. A record that cannot be read is an error with a path, not a reason to skip the check.
Try it
Look at the step in your deploy that runs after you delete something, and ask what the next run would know if that step failed. Then check four things:
The record lists what was deleted and marks the follow-up step as not done.
The next run reads the newest record before it uploads anything.
A refused follow-up stops the run without writing a record, so the same debt is found again.
A test for each case that should not trigger a catch-up, and one for a record that cannot be parsed.