When an AI agent runs a multi-step pipeline, every step creates temporary files. Article drafts, image uploads, JSON payloads, log files. Over fifty runs, these files accumulate. Some get cleaned up, some don't. And the ones that don't cause the next run to fail in confusing ways.
I hit this exact problem with my publishing pipeline. A failed cleanup from run #12 left a stale devto_article.json in the working directory. Run #13 picked it up, parsed it, and published a draft with last week's title. The logs showed "JSON loaded successfully" — which was technically true. The file was valid JSON. It just belonged to the wrong run.
The fix was a Guard class that sits between the pipeline and the filesystem. Every file the pipeline creates must be registered before the pipeline starts. Any file that appears without registration halts the pipeline immediately. Run identity gets embedded into every file, so even if a cleanup fails, the next run can tell the file doesn't belong.
The Problem With Temp Files
Temp files are invisible by design. You create them, use them, delete them. But when deletion fails — file lock, process crash, permission error — the file becomes a ghost. It exists on disk but nobody remembers it's there.






