Files
narratio/docs/roadmap/cleanup.md

115 lines
5.9 KiB
Markdown
Raw Normal View History

# Durable Session Cleanup
2026-11-30 14:08:28 +00:00
Status: Complete.
## Goal
Automatic cleanup should leave only a reusable, durable session. After an
authorized cleanup succeeds, the session's entire `runs/` directory is absent.
Run history is execution material, not a dependency of the retained session.
The previous cleanup implementation removed eligible material from the
published run while retaining original Notarius bundles and latest diagnostic
targets. This work replaces that retention policy and extends
[cleanup](../internal/stage-cleanup.md) to all local runs for the selected session.
## Retention Contract
Preserve the manifest, prepared inputs (including reference snapshots and
previous-session inputs), prepared audio, canonical transcripts, and canonical
artifacts. Preserve the durable evidence needed to validate and reuse those
products through supported session workflows.
Remove all material beneath `runs/`, including staging files, original subprocess
bundles, generated invocation files, logs, debug captures, and earlier failed
attempts. A later successful cleanup deliberately discards earlier failure
evidence as well as the successful run's evidence.
Remove managed `logs/<stage>` and `debug/<stage>` links whose targets are being
deleted, including restore views. Successful cleanup must leave no dangling
managed diagnostic links. Empty view directories may remain; their presence
does not imply that diagnostics are available.
Original Notarius bundles cease to be session-durable material. Required products
must already be promoted into canonical locations. Optional bundle contents are
disposable unless explicitly declared as retained session products; do not
preserve entire bundles merely to retain unselected auxiliaries.
Subprocess-owned state and caches, other sessions, and remote published objects
remain outside this cleanup operation. Manual whole-session cleanup retains its
separate purpose and scope.
## Authorization And Lifecycle
Retain `workspace.cleanup_after_publish` as the existing opt-in control. Disabling
it preserves run history and diagnostics. Do not introduce an archive, another
retention setting, or a relocation scheme for discarded evidence.
Cleanup remains the final ordinary pipeline stage after `notify`, executed only
when selected by the invocation. Preserve the existing successful-publication
checks against the manifest and configured campaign/session identity. A failed
processing or publication invocation must not proceed to automatic cleanup.
Selecting only `publish`, or ending a bounded run before cleanup, must not cause
cleanup as an implicit finalization side effect.
Once authorized, target the selected session's complete `runs/` tree rather than
only the published run ID. Continue to use canonical path helpers, the session
lock, and existing root-confined deletion machinery. Publication evidence
authorizes cleanup; directory contents do not establish authorization.
Finish all writers that use run-local paths before deleting those paths. Cleanup
completion, manifest persistence, and final invocation reporting must not depend
on deleted files or recreate `runs/`. Keep this coordination within the existing
stage and invocation lifecycle.
Cleanup failures remain visible and leave the invocation incomplete, while
successful publication remains authoritative. Deletion need not be transactional:
partial cleanup can remove some diagnostics before failing. A retry must finish
the remaining work without requiring republishing. Missing run directories and
already-removed managed links are successful, idempotent conditions.
2026-11-30 12:51:24 +00:00
## Required Changes
Stage reuse, artifact resolution, extraction validation, publication, and recovery
use canonical products and manifest-held semantic evidence. Historical provenance
can describe removed attempts. Missing diagnostics do not invalidate products.
Session-wide deletion and managed-view removal replace published-run pruning and
retained-bundle exceptions. Retention-only markers and protected-tree traversal
are removed. Cleanup's reuse decision accounts for all remaining run material
and managed views, including attempts created after an earlier cleanup.
The existing stage and invocation lifecycle coordinates writer completion,
manifest persistence, retry, and final reporting. Run-local directories are
created on demand for actual work. Cleanup-only and fully reused invocations can
leave an already-clean session without recreating `runs/`.
The operations guide, configuration reference, affected internal and integration
documentation, and architecture policy describe the resulting retention behavior.
Architecture policy reflects session-wide cleanup scope and diagnostic lifetime.
Release documentation explains diagnostic loss and retaining diagnostics by
disabling automatic cleanup.
The [implementation plan](implementation.md) owns sequencing and validation steps.
## Verification
Use focused behavioral tests with real temporary session directories and fake
external boundaries. Cover these outcomes without duplicating existing
path-safety and publication tests unnecessarily:
- Successful cleanup removes multiple historical runs, original bundles, and
their managed diagnostic views, while preserving durable session data and
separately owned subprocess state and caches.
- A cleaned session can reuse valid completed stages and perform supported
downstream work without needing deleted bundles or diagnostic files. Verify
this through the ordinary runner, not only by checking that files remain.
- Disabled cleanup, invocation ranges excluding cleanup, and unsuccessful
publication do not trigger deletion. Existing authorization and confinement
protections still apply to the broader target.
- Partial deletion failures are reported; retry completes cleanup without
republishing. Repeated cleanup of an already-clean session succeeds.
- New attempts after a successful cleanup are removed by the next authorized
cleanup. Cleanup and final reporting leave `runs/` absent and managed views
consistent.