# Stage: cleanup ## Purpose And Authorization The final selected cleanup stage removes local run history after successful publication when `workspace.cleanup_after_publish` is enabled. It validates the published run, commit and pointer evidence and configured campaign/session identity. Explicit whole-session cleanup is a separate operator action. ## Execution And Resume Cleanup removes recognized managed stage and restore log/debug links without following them, then deletes the selected session's entire `runs/` directory through a confined workspace root. Missing runs and links are successful; unsafe paths and managed-name conflicts fail. Subprocess state, caches, durable session products and remote objects are outside its scope. Resume inspects both the runs directory and managed views without mutation. An empty runs directory, a new attempt, or a dangling managed view requires cleanup again. Deletion is not transactional: a failure can leave partial progress and is recorded as a failed stage. A later selected cleanup retries without another publish. See [operations](../operations.md#cleanup). ## Implementation And Tests `internal/stage/cleanup_plan.go`, `cleanup.go`, `internal/fileops/cleanup.go`, `attempt_views.go`, and their tests own authorization, inspection, managed view removal and confined deletion.