Record every key a partial delete removed
1 November 2026 · Guardrails & fail-closed · the engineering team
The story
Our deploy tooling deletes many keys from an object store. Taking a site down removes every key under its prefix. A deploy prunes stale assets. The store deletes in batches of 1000 keys, and each run writes a record that lists the keys it removed.
The store already handled one kind of partial failure. When the service refuses some keys in a batch, the store works out which keys of that batch are gone and reports them in a partial-delete error. It did not handle a call that threw. A network error or throttling on the second batch would leave the first batch deleted, with nothing in the error to say so. We changed the store to catch the throw and reject with a partial-delete error that carries every key the earlier batches deleted. Its message says how many: "delete failed after 1000 key(s)", then the cause. The callers used to loop over batches of 1000 themselves. They now hand the store the whole list in one call, and on a partial-delete error they add the deleted keys to the record.
We wrote two tests. The store test makes the second send throw "socket hang up" over 1500 keys, and checks that the error is a partial-delete error whose deleted list is the first 1000 keys. The take-down test uses an in-memory store that deletes the first 1000 of 1500 keys, then throws. It checks that the store received one call with all 1500 keys, that the run's status is failed, and that the outcome and the written record each list 1000 removed keys. It checks that 500 keys are still in the store, and that invalidation of the site's prefix was still requested.
The pattern
A delete is not atomic once it runs in batches. When it fails part way, some keys are gone and some are not. The failure has to carry the first group out of the function that failed, or the code that writes the record cannot list it.
So the error type for a bulk delete holds the keys already deleted, and every way the delete can stop builds that error. A refusal from the service is one way to stop. A thrown exception is another. If only the first one carries the list, the second one loses it.
Try it
Find a bulk delete in your code that works in batches. Write a test over more than one batch, with a fake store whose second call throws. Assert three things: the error holds the keys the first batch deleted, the run is marked failed, and the record lists exactly those keys. Run it before you change anything and see which of the three fails.