6.6 KiB
Durable Session Cleanup
Status: Proposed; not implemented.
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 current cleanup implementation removes eligible material from the published run while retaining original Notarius bundles and latest diagnostic targets. This roadmap replaces that retention policy and extends cleanup 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.
Implementation Work
- Establish durable reuse. Audit stage reuse, artifact resolution, extraction validation, publication, and recovery for dependencies on run-local paths. Retain required semantic evidence in canonical products or manifest state. Historical provenance may describe a removed attempt, but must not be treated as a live file dependency. Missing diagnostics must not invalidate products.
- Simplify cleanup. Replace published-run pruning and retained-bundle exceptions with session-wide run deletion and managed-view removal. Remove retention-only markers, traversal logic, and checks that are no longer needed. Account for all run material, including attempts created after an earlier successful cleanup, when deciding whether cleanup has work to do.
- Complete lifecycle handling. Verify writer shutdown, cleanup retry, cleanup-only invocation, and final reporting using the existing orchestration paths. Use ordinary stage status and errors; avoid a second cleanup scheduler or retention framework.
- Update documentation with implementation. Update the operations guide, configuration reference, affected internal documentation, and the architecture policy. In particular, replace the policy's published-run target restriction with the selected session's run history scope. Explain diagnostic loss and how to retain diagnostics by disabling automatic cleanup. Record the changed retention behavior in release documentation.
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.
Open Decisions
None for the intended retention policy. During implementation planning, identify any required product or reuse evidence currently available only in a run-local bundle and specify its durable destination before enabling complete deletion. This is a dependency audit, not a reason to retain run history by default.