Document durable session cleanup

This commit is contained in:
2026-11-30 14:08:28 +00:00
parent e9d74a7de0
commit 719a6839d1
14 changed files with 84 additions and 60 deletions

View File

@@ -282,7 +282,7 @@ Rules:
| `pipeline.reference_catalog.settings` | map[string]string | No | setting IDs to source-relative vocabulary files | | `pipeline.reference_catalog.settings` | map[string]string | No | setting IDs to source-relative vocabulary files |
| `pipeline.reference_catalog.systems` | map[string]string | No | system IDs to source-relative vocabulary files | | `pipeline.reference_catalog.systems` | map[string]string | No | system IDs to source-relative vocabulary files |
| `pipeline.workspace.root` | string | No | `/var/lib/narratio` | | `pipeline.workspace.root` | string | No | `/var/lib/narratio` |
| `pipeline.workspace.cleanup_after_publish` | bool | No | `false`; selects the published run's workspace target for final cleanup and requires effective `pipeline.publish.enabled=true` and `pipeline.publish.upload_run=true` | | `pipeline.workspace.cleanup_after_publish` | bool | No | `false`; selects the session's entire run history for final cleanup and requires effective `pipeline.publish.enabled=true` and `pipeline.publish.upload_run=true` |
| `pipeline.campaigns.root` | string | No | `/usr/local/share/narratio/campaigns` | | `pipeline.campaigns.root` | string | No | `/usr/local/share/narratio/campaigns` |
| `pipeline.campaigns.default_campaign_id` | string | No | empty | | `pipeline.campaigns.default_campaign_id` | string | No | empty |
| `pipeline.campaigns.session_template_file` | string | No | installation session template; built-in default when absent | | `pipeline.campaigns.session_template_file` | string | No | installation session template; built-in default when absent |

View File

@@ -31,9 +31,10 @@ its pipeline and confined output directory, and validates each configured
`lanes/<lane-id>.json` as a safe regular JSON file. It promotes those required `lanes/<lane-id>.json` as a safe regular JSON file. It promotes those required
lanes to flat session artifacts and records content evidence. The reported lanes to flat session artifacts and records content evidence. The reported
`artifact_count` can include reused or auxiliary results; it is not an inventory. `artifact_count` can include reused or auxiliary results; it is not an inventory.
Optional `chunk-map.json` and `evidence-context.json` stay with the retained Optional `chunk-map.json` and `evidence-context.json` stay in the original
original bundle. A positive native `fallback_count` remains visible in fresh and bundle, which is subject to Narratio cleanup. Selected canonical products and
reused reports. their recorded evidence support reuse without that bundle. A positive native
`fallback_count` remains visible in fresh and reused reports.
Nonzero exit, malformed completion, unsafe output, or a missing required lane Nonzero exit, malformed completion, unsafe output, or a missing required lane
fails extraction. Diagnostics and available files remain for investigation; an fails extraction. Diagnostics and available files remain for investigation; an

View File

@@ -33,7 +33,7 @@ validator. The focused stage documents own their input/output flow;
All formats are validated by strict source-policy rules. Configured artifact and All formats are validated by strict source-policy rules. Configured artifact and
extraction keys use `^[a-z][a-z0-9_]*$`; source parsers never normalize an extraction keys use `^[a-z][a-z0-9_]*$`; source parsers never normalize an
unrecognized token into a valid source. Extraction sources are registered only unrecognized token into a valid source. Extraction sources are registered only
from `pipeline.notarius.outputs`; the retained bundle is not a selectable from `pipeline.notarius.outputs`; the original bundle is not a selectable
source. source.
Prepared stable source IDs are `narratio.input.players`, Prepared stable source IDs are `narratio.input.players`,

View File

@@ -15,11 +15,13 @@ sibling temporary file, validates the complete result, and passes that file to
remote object selection, validation, conflict handling, and temporary-file remote object selection, validation, conflict handling, and temporary-file
cleanup. cleanup.
Directory bundles are not promoted by `internal/fileops`; extraction retains Directory bundles are not promoted by `internal/fileops`; extraction keeps
the original bundle in its run and promotes individual validated products. the original bundle in its run until cleanup and promotes individual validated
products.
Managed latest-attempt links are updated and inspected by fileops. Cleanup uses Fileops updates, inspects and removes recognized managed latest-attempt links
those validated targets when retaining current diagnostics. without following their targets, including dangling links. Unrelated entries are
left alone and conflicting managed names are rejected.
## Cleanup Contract ## Cleanup Contract

View File

@@ -330,12 +330,11 @@ writes, or run-directory creation. Excluded prefix records are not passed to
resume validators. Records after the selected end are not prerequisites and resume validators. Records after the selected end are not prerequisites and
may be made stale by selected work without being scheduled. may be made stale by selected work without being scheduled.
After a publish commits remotely, any configured local cleanup is first recorded Cleanup is an ordinary selected stage. It validates recorded successful
as a session-manifest obligation before deletion begins. Each target becomes publication evidence before deleting local run history, saves its normal stage
complete only after its confined deletion (or safe absence check) and a transition, and retries incomplete work on a later selected invocation without
successful manifest save. An incomplete obligation is retried when publish republishing. Historical run-local paths in records are provenance, not a
executes again and retains the committed run and remote identity that authorized requirement that those files remain present. See [cleanup](stage-cleanup.md).
it; an invocation that does not execute publish does not perform cleanup.
Each invocation derives campaign, session, run, local-path, and remote-prefix Each invocation derives campaign, session, run, local-path, and remote-prefix
metadata from the validated resolved configuration as one projection. A persisted metadata from the validated resolved configuration as one projection. A persisted

View File

@@ -1,25 +1,28 @@
# Stage: cleanup # Stage: cleanup
## Purpose ## Purpose And Authorization
Remove eligible run data only after a successful publish, according to the The final selected cleanup stage removes local run history after successful
workspace cleanup policy. Explicit session cleanup is a separate operator action. publication when `workspace.cleanup_after_publish` is enabled. It validates the
published run, commit and pointer evidence and configured campaign/session
## Authorization And Targets identity. Explicit whole-session cleanup is a separate operator action.
`workspace.cleanup_after_publish` enables automatic cleanup. It requires a
succeeded upload and matching published run, commit, and pointer evidence.
Cleanup confines deletion to that run and protects managed latest log/debug
view targets and the original session-durable Notarius bundle. Subprocess state
and caches are outside its scope.
## Execution And Resume ## Execution And Resume
Cleanup is idempotent and retries failed deletion without republishing. Retained Cleanup removes recognized managed stage and restore log/debug links without
protected files are intentional and do not trigger endless cleanup. Bounded following them, then deletes the selected session's entire `runs/` directory
runs ending before cleanup do not execute it. See [operations](../operations.md#cleanup). 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 ## Implementation And Tests
`internal/stage/cleanup_plan.go`, `cleanup.go`, `internal/fileops/cleanup.go` `internal/stage/cleanup_plan.go`, `cleanup.go`, `internal/fileops/cleanup.go`,
and their tests own authorization, protected targets, and confined deletion. `attempt_views.go`, and their tests own authorization, inspection, managed view
removal and confined deletion.

View File

@@ -17,12 +17,14 @@ successful native completion report for the expected pipeline and confined outpu
directory. The stage reads each configured lane JSON, validates its safe path and directory. The stage reads each configured lane JSON, validates its safe path and
content, then promotes all required products to flat artifact paths before content, then promotes all required products to flat artifact paths before
recording success. The original bundle and optional domain auxiliaries stay in recording success. The original bundle and optional domain auxiliaries stay in
the producing run. Positive native fallback counts are recorded and reported. the producing run until authorized cleanup removes run history. Positive native
fallback counts are recorded and reported.
## Resume Validation ## Resume Validation
Resume checks the direct transcript identity, configured pipeline and lane Resume checks the direct transcript identity, configured pipeline and lane
selection, reference identities, and manifest-backed output checksums and sizes. selection, reference identities, and manifest-backed output checksums and sizes.
It does not reopen the original bundle or completion report.
Cache and debug selection, executable version and private downstream config are Cache and debug selection, executable version and private downstream config are
not blanket invalidators. Force invokes extraction with cache refresh. A failed not blanket invalidators. Force invokes extraction with cache refresh. A failed
replacement is not represented as a current successful extraction. replacement is not represented as a current successful extraction.

View File

@@ -64,7 +64,8 @@ supports remote loading when no authored session override is available. The
- includes the four manifest-backed prepared glossary documents with their - includes the four manifest-backed prepared glossary documents with their
declared input identities for restore; declared input identities for restore;
- publishes extraction lanes only through explicit configured output rules; - publishes extraction lanes only through explicit configured output rules;
neither run-local nor durable Notarius bundles are scanned or uploaded wholesale. original Notarius bundles are not scanned or uploaded wholesale. Historical
run-local references are not required for later publication.
- selected artifact filter applies to configured artifact sources only. - selected artifact filter applies to configured artifact sources only.
- plans every configured output into exactly one source-sorted outcome: - plans every configured output into exactly one source-sorted outcome:
`published`, `carried_locked`, `locked_unpublished`, `optional_missing`, or `published`, `carried_locked`, `locked_unpublished`, `optional_missing`, or

View File

@@ -35,14 +35,14 @@ into run-local output space.
Polish and extraction write to actual run-local output, log, and debug paths. Polish and extraction write to actual run-local output, log, and debug paths.
Each attempt advances managed relative `logs/<stage>` and `debug/<stage>` links; Each attempt advances managed relative `logs/<stage>` and `debug/<stage>` links;
skips do not rotate them. Restore has its own diagnostic attempt. Extraction skips do not rotate them. Restore has its own diagnostic attempt. Extraction
promotes validated lanes to flat artifacts and retains the original bundle in promotes validated lanes to flat artifacts; the original bundle remains in
the producing run. See [Operations](../operations.md#local-state-layout). the producing run until cleanup. See [Operations](../operations.md#local-state-layout).
Prepared references delivered to Notarius use session-durable paths owned by Prepared references delivered to Notarius use session-durable paths owned by
`internal/artifacts` beneath `internal/artifacts` beneath
`inputs/references/<sha256>/<prepared-basename>`. These verified `inputs/references/<sha256>/<prepared-basename>`. These verified
content-addressed snapshots are outside run-local layout, survive ordinary content-addressed snapshots are outside run-local layout, survive ordinary
published-run cleanup, and are excluded from publish and restore enumeration. session run-history cleanup, and are excluded from publish and restore enumeration.
## Locking ## Locking
@@ -53,8 +53,8 @@ not evidence that a lock is active. Command and restore flows wait for this
lock only while their context remains active, and report a release failure. lock only while their context remains active, and report a release failure.
The runner assigns every invocation a run-workspace identity but creates the The runner assigns every invocation a run-workspace identity but creates the
physical directory only before an executing stage that requires it. Fully physical run directory and its `runs/` parent only when an executing stage
reused invocations and cleanup-only invocations therefore do not accumulate requires them. Fully reused invocations and cleanup-only invocations therefore do not accumulate
empty run directories. empty run directories.
## Cleanup Semantics ## Cleanup Semantics
@@ -66,6 +66,7 @@ The canonical cleanup stage:
ID, remote commit key, and current commit-pointer key; ID, remote commit key, and current commit-pointer key;
- consumes the resolved cleanup policy described in - consumes the resolved cleanup policy described in
[Configuration](../config.md); [Configuration](../config.md);
- removes the entire session run history and recognized managed diagnostic views;
- refuses unsafe deletes (root delete, traversal, and out-of-root targets); - refuses unsafe deletes (root delete, traversal, and out-of-root targets);
- treats missing targets as successful, idempotent deletion; and - treats missing targets as successful, idempotent deletion; and
- uses its ordinary failed/succeeded manifest stage record for retry. A later - uses its ordinary failed/succeeded manifest stage record for retry. A later

View File

@@ -287,7 +287,7 @@ Choose the narrowest workflow that matches the intended replacement:
| Intent | Command | Preserved and rebuilt state | | Intent | Command | Preserved and rebuilt state |
| --- | --- | --- | | --- | --- | --- |
| Rebuild analysis only | [`narratio run 2026-04-04 --stage analyze --force`](./cli.md#run) | Preserves transcripts and the current extraction bundle; force-runs selected analysis artifacts and their required analysis prerequisites. | | Rebuild analysis only | [`narratio run 2026-04-04 --stage analyze --force`](./cli.md#run) | Preserves transcripts and current extraction products; force-runs selected analysis artifacts and their required analysis prerequisites. |
| Rebuild extraction and analysis | [`narratio artifacts regenerate 2026-04-04`](./cli.md#artifacts-regenerate) | Preserves transcripts; force-runs the complete configured extraction bundle, then selected analysis. `--artifacts` narrows analysis only. | | Rebuild extraction and analysis | [`narratio artifacts regenerate 2026-04-04`](./cli.md#artifacts-regenerate) | Preserves transcripts; force-runs the complete configured extraction bundle, then selected analysis. `--artifacts` narrows analysis only. |
| Continue bounded work normally | [`narratio run 2026-04-04 --from extract --through analyze`](./cli.md#run) | Uses ordinary resume decisions: current extraction and analysis can be skipped, while incomplete or obsolete work runs. | | Continue bounded work normally | [`narratio run 2026-04-04 --from extract --through analyze`](./cli.md#run) | Uses ordinary resume decisions: current extraction and analysis can be skipped, while incomplete or obsolete work runs. |
@@ -380,7 +380,7 @@ not create a separate workspace or retain a separate current extraction result.
Narratio cannot observe edits inside Notarius configuration behind an unchanged Narratio cannot observe edits inside Notarius configuration behind an unchanged
selector. Force extraction after such an edit when a replacement is intended. selector. Force extraction after such an edit when a replacement is intended.
Use `artifacts regenerate` when both extraction and analysis must be rebuilt; Use `artifacts regenerate` when both extraction and analysis must be rebuilt;
use `run SESSION --stage analyze --force` when the existing extraction bundle use `run SESSION --stage analyze --force` when the existing extraction products
should be preserved. Field should be preserved. Field
semantics belong in [Configuration](./config.md#notarius-configuration-overlay), semantics belong in [Configuration](./config.md#notarius-configuration-overlay),
with Audita selectors covered under with Audita selectors covered under
@@ -419,8 +419,8 @@ The final trimmed transcript and content-identified snapshots under
Successful configured lanes become flat `artifacts/<name>.json` products and Successful configured lanes become flat `artifacts/<name>.json` products and
`narratio.extraction.<name>` sources. The original bundle remains under the `narratio.extraction.<name>` sources. The original bundle remains under the
producing run for evidence; it is not implicitly published. A failed replacement producing run until authorized cleanup removes it; it is not implicitly
does not make the earlier extraction record current. Native fallback counts and published. A failed replacement does not make the earlier extraction record current. Native fallback counts and
readiness warnings remain visible in command reports. readiness warnings remain visible in command reports.
Narratio can reuse completed extraction without starting Notarius. When extraction Narratio can reuse completed extraction without starting Notarius. When extraction
@@ -486,7 +486,7 @@ Run-local diagnostics are:
Audita reporting is enabled, alongside captured streams and invocation records Audita reporting is enabled, alongside captured streams and invocation records
- `runs/{run_id}/extract/logs/notarius.report.json` - `runs/{run_id}/extract/logs/notarius.report.json`
- `runs/{run_id}/extract/logs/notarius.stderr.log` - `runs/{run_id}/extract/logs/notarius.stderr.log`
- `runs/{run_id}/extract/notarius-output/` for retained original bundles - `runs/{run_id}/extract/notarius-output/` for original bundles until cleanup
The run upload is an allowlist derived from the session manifest's declared The run upload is an allowlist derived from the session manifest's declared
current-run outputs, logs, and generated configurations, not a workspace scan. current-run outputs, logs, and generated configurations, not a workspace scan.
@@ -495,7 +495,7 @@ declared source is opened without following symlinked ancestors or the leaf,
verified as a regular file, and streamed from that verified descriptor. verified as a regular file, and streamed from that verified descriptor.
Unlisted files and unsafe entries are never uploaded; a run with no declared Unlisted files and unsafe entries are never uploaded; a run with no declared
current-run diagnostics uploads no run-local files. No distinguished diagnostic current-run diagnostics uploads no run-local files. No distinguished diagnostic
file is uploaded. The durable bundle is never scanned for implicit publication; file is uploaded. The original bundle is never scanned for implicit publication;
only lanes named by explicit `pipeline.publish.outputs` rules are uploaded. only lanes named by explicit `pipeline.publish.outputs` rules are uploaded.
To inspect a published polish report remotely, read its declared object under To inspect a published polish report remotely, read its declared object under
the run archive's `polish/logs/` prefix. Session restore does the run archive's `polish/logs/` prefix. Session restore does
@@ -673,8 +673,8 @@ reference snapshots live under `inputs/references/`.
Each attempted stage writes actual logs and debug capture beneath its run. Each attempted stage writes actual logs and debug capture beneath its run.
`logs/<stage>` and `debug/<stage>` are relative links to the latest attempt, `logs/<stage>` and `debug/<stage>` are relative links to the latest attempt,
including failed attempts; skipped work does not rotate them. Restore writes its including failed attempts; skipped work does not rotate them. Restore writes its
own diagnostic attempt. Original Notarius bundles remain in the producing run. own diagnostic attempt. Original Notarius bundles remain in the producing run
Automatic cleanup retains current view targets and session-durable bundle evidence. until authorized cleanup. The `runs/` directory is created on demand.
Remote audio is downloaded to a temporary sibling and verified before replacing Remote audio is downloaded to a temporary sibling and verified before replacing
its single prepared `audio/` copy. Restore follows the same layout. Subprocess its single prepared `audio/` copy. Restore follows the same layout. Subprocess
@@ -727,10 +727,18 @@ Use `narratio session clean SESSION` to remove an entire local session, or
`narratio session clean --all` for all local sessions. Add `--dry-run` to inspect `narratio session clean --all` for all local sessions. Add `--dry-run` to inspect
planned targets. These commands do not delete subprocess caches or remote data. planned targets. These commands do not delete subprocess caches or remote data.
Automatic run cleanup requires `workspace.cleanup_after_publish` and successful Automatic cleanup requires `workspace.cleanup_after_publish=true` and successful
publication evidence. It preserves current log/debug targets and retained Notarius publication evidence. When selected, it removes the entire session `runs/` tree,
bundle evidence. A failed cleanup can be retried without republishing; bounded including older failures, restore attempts, probes, logs, debug captures, and
runs ending before cleanup do not execute it. See [cleanup internals](internal/stage-cleanup.md). original Notarius bundles. Managed stage and restore views are removed as well.
Canonical products, prepared inputs, manifests, other sessions, subprocess
state and caches, and remote objects remain. Set the option to `false` to keep
run history and diagnostics.
A failed cleanup is reported and may have removed some files already. Retry the
cleanup stage or a full run without republishing. Bounded runs ending before
cleanup do not execute it; their new attempts remain until a later authorized
cleanup. See [cleanup internals](internal/stage-cleanup.md).
## Operational Caveats ## Operational Caveats

View File

@@ -122,7 +122,8 @@ merely on incidental files existing on disk.
A failed or interrupted stage must not be presented as successful. Failure A failed or interrupted stage must not be presented as successful. Failure
should preserve enough local state and diagnostics for inspection, recovery, should preserve enough local state and diagnostics for inspection, recovery,
and resume. Forcing a stage invalidates succeeded transitive dependents and resume until a later authorized cleanup. Forcing a stage invalidates
succeeded transitive dependents
according to a fixed application-owned relation that is separate from canonical according to a fixed application-owned relation that is separate from canonical
execution order. The relation is validated against the stage inventory and is execution order. The relation is validated against the stage inventory and is
not configurable. not configurable.
@@ -264,9 +265,9 @@ transaction boundary.
Automatic local cleanup is permitted only after a successful publish commit, Automatic local cleanup is permitted only after a successful publish commit,
only when explicitly configured, and only through the path-safety guardrails. only when explicitly configured, and only through the path-safety guardrails.
It is the final ordinary pipeline stage after `notify`. The stage derives its It is the final ordinary pipeline stage after `notify`. The stage derives the
exact run-scoped targets from validated publish metadata and the configured selected session's run-history target from validated publish metadata and the
campaign/session identity; it never infers a target from directory contents or configured campaign/session identity; it never infers a target from directory contents or
rereads remote storage. A cleanup failure makes the invocation incomplete while rereads remote storage. A cleanup failure makes the invocation incomplete while
leaving publish succeeded and the committed remote snapshot authoritative. A leaving publish succeeded and the committed remote snapshot authoritative. A
normal later full run reuses valid upstream stages and retries cleanup. normal later full run reuses valid upstream stages and retries cleanup.
@@ -305,9 +306,9 @@ Safe bootstrap diagnostics may identify files and statuses but never values. Dia
prompt content unless a deliberate, bounded inspection mechanism requires it. prompt content unless a deliberate, bounded inspection mechanism requires it.
Logs, reports, generated invocation files, generated configuration, and render Logs, reports, generated invocation files, generated configuration, and render
debug files are diagnostics, not canonical pipeline products. They should be debug files are diagnostics, not canonical pipeline products. They remain
durable and discoverable where configured, and manifest references must preserve discoverable until configured cleanup removes their run history. Manifest
the distinction between diagnostics and artifacts. references must preserve the distinction between diagnostics and artifacts.
Documentation security rules belong in the Documentation security rules belong in the
[Documentation Policy](documentation.md). Credential supply belongs in [Documentation Policy](documentation.md). Credential supply belongs in

View File

@@ -36,6 +36,12 @@ in each URL with the intended tag:
[COPYRIGHT](https://forge.maximumdirect.net/eric/narratio/src/tag/vMAJOR.MINOR.PATCH/COPYRIGHT) | [LICENSE](https://forge.maximumdirect.net/eric/narratio/src/tag/vMAJOR.MINOR.PATCH/LICENSE) | [ATTRIBUTION](https://forge.maximumdirect.net/eric/narratio/src/tag/vMAJOR.MINOR.PATCH/docs/oss/attribution.md) [COPYRIGHT](https://forge.maximumdirect.net/eric/narratio/src/tag/vMAJOR.MINOR.PATCH/COPYRIGHT) | [LICENSE](https://forge.maximumdirect.net/eric/narratio/src/tag/vMAJOR.MINOR.PATCH/LICENSE) | [ATTRIBUTION](https://forge.maximumdirect.net/eric/narratio/src/tag/vMAJOR.MINOR.PATCH/docs/oss/attribution.md)
``` ```
For the next release note, describe the cleanup retention change: when automatic
cleanup is enabled and authorized, it removes the selected session's entire run
history, including failed-attempt diagnostics and original Notarius bundles.
Operators can retain that material by setting `workspace.cleanup_after_publish`
to `false`.
Retire completed roadmaps as appropriate, preserve pending work, and review the Retire completed roadmaps as appropriate, preserve pending work, and review the
candidate through the ordinary development workflow. Commit the candidate and candidate through the ordinary development workflow. Commit the candidate and
push it to `origin/main`, then publish from the clean `main` checkout: push it to `origin/main`, then publish from the clean `main` checkout:

View File

@@ -1,6 +1,6 @@
# Durable Session Cleanup # Durable Session Cleanup
Status: Proposed; not implemented. Status: Complete.
## Goal ## Goal

View File

@@ -1,6 +1,6 @@
# Durable Session Cleanup Implementation Plan # Durable Session Cleanup Implementation Plan
Status: Planned; implementation has not started. Status: Complete.
## Scope And Execution ## Scope And Execution
@@ -301,7 +301,7 @@ without depending on historical run files or changing remote inventory semantics
## Stage 7: Align Documentation And Verify The Completed Sprint ## Stage 7: Align Documentation And Verify The Completed Sprint
Status: Pending. Status: Complete.
Read the affected canonical documents and the documentation policy. Update: Read the affected canonical documents and the documentation policy. Update: