Document the shared pipeline and verify the cutover

This commit is contained in:
2026-11-30 02:40:17 +00:00
parent 706c1bb7ad
commit 2ec43305da
30 changed files with 394 additions and 866 deletions

View File

@@ -62,18 +62,15 @@ command configuration loader may still use object storage to retrieve a missing
remote session file before planning begins.
After preparation, the application projects remaining selected work and uses
invocation-owned Audita and Scriptorium runners for applicable readiness checks.
invocation-owned Audita, Notarius, and Scriptorium runners for applicable readiness checks.
The same runners are available to processing. Explicit session validation uses
existing prepared inputs and invocation-owned factories. See
[preflight internals](preflight.md).
Notarius is composed only when extraction is enabled; the extract stage owns
prepared reference resolution, receipt, bundle, and configured-lane policy.
The adapter validates the ordered selector/absolute-path pairs and is the sole
owner of serializing them as repeated `--reference` arguments before `--json`.
It also serializes an effective resume request as `--resume` and a nonempty
validated chunk mode as `--chunk_cache <mode>`. The extract stage, not the
adapter, resolves force precedence before constructing the request.
Notarius is composed only when extraction is enabled. The stage resolves
prepared references and promotes configured products; the adapter builds native
inspection, preflight, and run commands and validates the completion report.
Force selects native cache refresh before request construction.
Its request may also carry already-resolved ConfigKit secret references.
Audita and Scriptorium requests carry the same kind of list. All three adapters use the shared
subprocess helper to convert their selected references into exact-name child

View File

@@ -33,15 +33,15 @@ validator. The focused stage documents own their input/output flow;
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
unrecognized token into a valid source. Extraction sources are registered only
from `pipeline.notarius.outputs`; the Notarius index has no selectable source
ID.
from `pipeline.notarius.outputs`; the retained bundle is not a selectable
source.
Prepared stable source IDs are `narratio.input.players`,
`narratio.input.party`, `narratio.input.glossary.party`,
`narratio.input.glossary.campaign`, `narratio.input.glossary.setting`,
`narratio.input.glossary.spells`, and `narratio.input.spell_catalog`. Artifact policy owns their canonical manifest
`narratio.input.glossary.spells`, and `narratio.input.glossary.combined`. Artifact policy owns their canonical manifest
kind and prepared filename vocabulary. Canonical party mode preserves the
party source bytes in the party record and supplies the players record from the
effective standalone party document in the party record and supplies the players record from the
deterministic `derived_from_party` projection; both remain ordinary prepared
source IDs for consumers.
@@ -132,10 +132,10 @@ Prepared stable sources (`narratio.input.*`):
Extraction sources (`narratio.extraction.*`):
- use the shared typed bundle evidence inspection in `extraction_evidence.go`;
- use the shared product evidence inspection in `extraction_evidence.go`;
- require a current successful extract record with the exact configured source,
compatible contract and Notarius provenance, a confined regular durable
payload, matching checksum, and the current resolved trimmed-transcript
Notarius provenance, a confined regular flat product with matching size and
checksum, and the current resolved trimmed-transcript
identity;
- remain unavailable unless catalog hydration receives valid evidence. Resume
treats absent or obsolete evidence as a rerun decision and unsafe evidence as
@@ -249,7 +249,7 @@ generation, and removal is idempotent.
- session/work/run paths;
- previous-cache paths;
- spool/cache paths;
- managed session, run, and diagnostic paths;
- S3 session/run/current-state key layout.
New publication creates run-scoped immutable objects, including

View File

@@ -85,17 +85,16 @@ Execution order and safety:
- restored manifest local references are rebased beneath the selected local
session root. Unsafe relative references and producer-machine absolute paths
outside the manifest's producer session root are rejected; producer-local
spool paths and run-local diagnostic references are not restored as
run-local diagnostic references are not restored as
authority. Cleanup remains ordinary restored stage state and is not reset or
synthesized by restore.
Audio restore path:
- uses `audio.MaterializeS3Audio`;
- integrates spool and S3 audio cache paths;
- reuses cached audio only when its opened regular file, content digest, and
identity sidecar all match the selected remote object version; otherwise it
refreshes through the validated download path.
- restores selected audio directly into the prepared session audio directory;
- reuses a prepared copy only when manifest identity and its content checksum
match; otherwise downloads to a verified temporary sibling before installation.
## Reporting Contract

View File

@@ -15,8 +15,11 @@ sibling temporary file, validates the complete result, and passes that file to
remote object selection, validation, conflict handling, and temporary-file
cleanup.
Directory bundles are not promoted by `internal/fileops`; extraction owns its
validated Notarius bundle rename.
Directory bundles are not promoted by `internal/fileops`; extraction retains
the original bundle in its run and promotes individual validated products.
Managed latest-attempt links are updated and inspected by fileops. Cleanup uses
those validated targets when retaining current diagnostics.
## Cleanup Contract

View File

@@ -12,7 +12,7 @@ manifest placement belongs in
- required `schema_version: narratio.session-manifest.v2`
- identity (`session_id`, `campaign`, `run_id`)
- local path metadata (`local_workdir`, `local_spool_dir`)
- local path metadata (`local_workdir`)
- remote identity metadata (`s3_bucket`, `s3_session_prefix`, `s3_run_prefix`)
- `inputs` records
- durable `artifacts` records

View File

@@ -4,7 +4,8 @@ The application performs downstream checks after selected preparation completes
or is reused and before remaining selected processing. It projects remaining
work against a clone of the locked manifest using the same stage decisions and
analysis planner as `session plan`. Projected polish selects Audita; projected
enabled trim and analysis select Scriptorium requirements. A projection is not
enabled extraction selects Notarius inspection and preflight; enabled trim and
analysis select Scriptorium requirements. A projection is not
an execution commitment. Empty target sets invoke no checker.
Audita receives the verified four prepared glossary files and the same
@@ -14,6 +15,10 @@ transient diagnostics, and preserves exit classification. No preflight result
is cached as a stage. A failure stops later processing without presenting it as
complete.
Notarius uses the same execution controls and verified reference snapshots. It
checks an available verified transcript or reports that a synthetic one was used.
Readiness warnings and native failures remain visible; checks do not publish work.
For `session validate`, the application selects enabled downstream definitions
independently of reuse and checks the existing prepared manifest. It does not
resolve live files into candidate glossary projections or run prepare. The

View File

@@ -20,7 +20,7 @@ dependency order, and safely materialize validated outputs.
Supported source families:
- built-ins: `narratio.transcript.*`, `narratio.bounds.session`
- prepared stable inputs: `narratio.input.players`, `narratio.input.party`,
`narratio.input.glossary.{party,campaign,setting,spells}`, `narratio.input.spell_catalog`
`narratio.input.glossary.{party,campaign,setting,spells,combined}`
- configured artifacts: `narratio.artifact.<key>`
- extraction lanes: `narratio.extraction.<key>`
- previous-session cache: `narratio.previous_session.artifact.<key>`

View File

@@ -2,53 +2,24 @@
## Purpose
Remove explicitly configured local data for the run selected by a successful
publish commit. Cleanup is the twelfth and final canonical stage, after
`notify`.
Remove eligible run data only after a successful publish, according to the
workspace cleanup policy. Explicit session cleanup is a separate operator action.
## Authorization And Targets
Cleanup is disabled unless at least one of these policies is true:
- `pipeline.spool.delete_audio_after_publish`
- `pipeline.workspace.cleanup_after_publish`
An enabled cleanup requires the manifest's publish stage to be succeeded with
`uploaded=true`, a canonical `published_run_id`, and the exact remote commit and
current commit-pointer keys for the manifest campaign/session prefix. The
configured campaign and session must match the manifest. Cleanup derives its
only possible targets through the canonical artifact path helpers:
- the published run's session spool-audio directory; and
- the published run's workspace run directory.
It does not scan parent directories, infer the newest run, or read object
storage. Every deletion uses the root-confined file operation, which rejects a
root itself, traversal, symlink escape, and out-of-root targets.
`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
Disabled cleanup records an explicit skipped result. Enabled cleanup removes
targets in deterministic policy order and treats an already-missing target as
success. A successful record contains the published run ID and completed policy
names.
A previous cleanup success is reusable only while its semantic configuration
matches and every selected target remains absent. A recreated target makes the
stage non-resumable. A failure is recorded against cleanup; publish remains
succeeded and remote current state is unchanged. On a later normal full run,
valid upstream stages are skipped and cleanup is retried without republishing.
`narratio run SESSION --stage publish` selects publish only and never invokes cleanup. A bounded run
through `notify` or any earlier endpoint also excludes it. Operators may run
`narratio run <session_id> --stage cleanup` directly; missing, failed, malformed,
or identity-mismatched publication evidence fails before deletion.
Cleanup is idempotent and retries failed deletion without republishing. Retained
protected files are intentional and do not trigger endless cleanup. Bounded
runs ending before cleanup do not execute it. See [operations](../operations.md#cleanup).
## Implementation And Tests
- Planning and evidence validation: `internal/stage/cleanup_plan.go`
- Execution and resume: `internal/stage/cleanup.go`
- Root-confined deletion: `internal/fileops/cleanup.go`
- Focused tests: `internal/stage/cleanup_plan_test.go`,
`internal/stage/cleanup_test.go`, and
`internal/app/cleanup_orchestration_test.go`
`internal/stage/cleanup_plan.go`, `cleanup.go`, `internal/fileops/cleanup.go`
and their tests own authorization, protected targets, and confined deletion.

View File

@@ -2,147 +2,40 @@
## Responsibility
`extract` runs after `render` and before `analyze`. It converts the canonical
`narratio.transcript.final_trimmed` JSON into configured Notarius lane artifacts.
An omitted or disabled Notarius section makes the stage explicitly self-skip
with reason `notarius_disabled`, no outputs, and no Notarius runner.
The external protocol is documented in the
[Notarius integration contract](../integrations/notarius.md). Configuration
fields belong in [Configuration](../config.md), and physical paths and force
procedures belong in [Operations](../operations.md).
The extract stage invokes the configured Notarius pipeline on the verified
final trimmed transcript and prepared references, promotes configured lane
products, and records Narratio-owned content evidence. Notarius owns its
pipeline, cache, validation and completion protocol; see the
[integration contract](../integrations/notarius.md).
## Lifecycle
`internal/stage/extract.go`:
1. resolves the final trimmed transcript from the shared artifact catalog;
2. resolves every configured prepared reference through the shared
manifest-authoritative identity resolver before creating run-local output;
3. resolves each reference to a stable content-addressed session snapshot,
reusing verified bytes or reconstructing a missing/corrupt regular entry,
and rejects any source change observed while copying;
4. fingerprints the byte- and provenance-bearing Notarius invocation evidence,
including sorted reference identities and the explicit downstream
configuration-overlay selection;
5. creates a run-local staging directory and invokes the injected
`notarius.Runner`, carrying the optional already-resolved credential
reference without exposing its value, the optional exact configuration
overlay, plus effective resume and chunk-cache controls after force
precedence;
6. revalidates the reference snapshots, then validates the v2 successful
receipt, confined index, management documents, configured required lane
descriptors, validation summaries, and regular payload files;
7. atomically promotes the complete bundle to its immutable durable location;
8. records one non-selectable `notarius_index` output and one selectable
`notarius_lane` output per configured lane; and
9. registers each lane as `narratio.extraction.<output_key>` for downstream
Scriptorium and publish resolution.
Lane records retain checksum, contract, producer run ID, and Notarius system,
run, pipeline, and lane provenance. Stage metadata retains the durable bundle
root, receipt, diagnostic paths, rejection/warning summaries, producing
Narratio run ID, the resolved trimmed-input identity, and invocation
fingerprint. The input identity binds the exact transcript bytes, canonical
source ID, producer stage/output/run identity, and resolution provenance.
Reference metadata contains only selector, source ID, canonical session-relative
path, checksum, and size; adapter requests receive selector and absolute stable
snapshot path, never payload contents. Snapshot bytes must
match the prepared identity both before and after Notarius runs, so a concurrent
prepared-file replacement cannot make recorded provenance describe different
bytes from those supplied to Notarius.
Validation completes before the single durable rename, so a rejected result
cannot expose a partial durable bundle.
Snapshot destinations are owned by `internal/artifacts` under
`cache/notarius/references/<sha256>/<prepared-basename>`. They contain no run ID
or timestamp and can be reused across invocations. Identical bytes and basename
share a verified file; changed bytes select a different digest directory.
Unsafe path components and non-regular conflicts fail without recursive
deletion. Snapshot paths are delivery details and never become manifest output
evidence or prerequisites for reuse of an already complete extract bundle.
Any executed extraction outcome that replaces a different effective outcome
marks succeeded analysis and delivery dependents stale. Render is an independent
sibling and remains current. Repeating the same disabled self-skip with no
outputs is stable and does not repeatedly invalidate dependent stages.
Disabled extraction records a skip. An execution resolves manifest-backed input
identities, creates immutable content-addressed reference snapshots, and invokes
Notarius with run-local output, log and debug destinations. The adapter accepts a
successful native completion report for the expected pipeline and confined output
directory. The stage reads each configured lane JSON, validates its safe path and
content, then promotes all required products to flat artifact paths before
recording success. The original bundle and optional domain auxiliaries stay in
the producing run. Positive native fallback counts are recorded and reported.
## Resume Validation
Before the focused validator runs, the application compares extract's versioned
semantic fingerprint. It covers enablement, Notarius pipeline identity, sorted
reference selector/source mappings, sorted declared output contracts, and each
canonical `narratio.extraction.<key>` output identity. It also covers the
explicit Notarius configuration-overlay selection; omitted, empty, and exact
`default` selectors share the base-selection identity. It excludes executable,
timeout, working directory, config path, and private Notarius config contents.
Credential presence, reference name, and resolved value are likewise
operational-only and excluded. Ordinary command loading still resolves a
selected reference before resume evaluation, but a credential-only change does
not rerun a valid completed extraction or stale its dependents.
`internal/stage/extract_resume.go` then permits a skip only when the existing
stage record still matches the current byte- and provenance-bearing invocation
evidence. That evidence covers the current direct trimmed-transcript identity,
sorted prepared-reference identities, pipeline identity, and configured output
contracts, plus the same downstream overlay-selection identity. The same
reference helper and transcript identity are resolved again for artifact
evidence, so changing current transcript bytes, reference bytes, producer
identity, or a named downstream selection makes the prior extraction obsolete.
Operational runner settings do not invalidate otherwise current durable
evidence. This includes `resume` and `chunk_cache`; changing them alone cannot
make a complete extraction non-resumable. If extraction executes, ordinary
runs forward the configured values, while force disables resume and selects
`refresh`.
A valid prepared-reference change makes extraction non-resumable. Missing,
unsafe, or checksum-inconsistent prepared evidence is a hard validation error
with prepare-force guidance because an immediate extract rerun cannot succeed.
The validator then checks the producing run identity, canonical immutable
bundle root, path confinement and absence of symlink components, receipt
identity, exactly one canonical index, the exact configured source set,
contracts and provenance, regular-file status, and stored checksums. Missing or
obsolete results are non-resumable and run again; unsafe filesystem conditions
return an error rather than silently accepting or replacing data.
This sensitivity is limited to the explicit downstream selector. Narratio's
own overlay label and whole effective-configuration digest are not blanket
extraction invalidators. Neither contract can observe files imported by
Notarius configuration, profile contents, prompt/module definitions, or other
transitive inputs. Operators must force extraction after changing any such
private input behind a stable identifier.
Resume checks the direct transcript identity, configured pipeline and lane
selection, reference identities, and manifest-backed output checksums and sizes.
Cache and debug selection, executable version and private downstream config are
not blanket invalidators. Force invokes extraction with cache refresh. A failed
replacement is not represented as a current successful extraction.
## Failure Behavior
Adapter startup, timeout, nonzero exit, receipt decoding, path confinement,
index compatibility, inconsistent warning or diagnostic envelopes,
required-lane rejection or incomplete validation, payload inspection,
checksum, or installation errors fail the stage through ordinary manifest
transition handling.
Stdout receipt and stderr diagnostics remain separate. Downstream stages are
not given selectable extraction sources unless the complete configured result
has passed validation and installation.
When a replacement attempt begins, the current session-stage record no longer
advertises payload from the previous success. A failed replacement therefore
has no current outputs, logs, generated configuration references, or metadata,
while the earlier immutable promoted bundle remains available for audit and
recovery.
Native errors, malformed completion, missing required lanes, unsafe paths, or
invalid JSON fail the attempt while preserving available diagnostics. A partial
report or incidental output is not success. See [operations](../operations.md#extraction-workflow).
## Implementation And Focused Tests
- Stage execution, selection, and resume validation: `internal/stage/extract.go`,
`internal/stage/extract_resume.go`,
`internal/stage/extract_test.go`,
`internal/stage/semantic_contracts_delivery.go`
- Stable snapshot materialization and verification:
`internal/stage/extract_references.go`
- Subprocess boundary: `internal/adapters/notarius/subprocess.go`,
`internal/adapters/notarius/subprocess_test.go`
- Catalog hydration: `internal/artifacts/extraction_catalog.go`,
`internal/artifacts/extraction_catalog_test.go`
- Composition and downstream behavior: `internal/app/runner_test.go`,
`internal/stage/analyze_test.go`, `internal/stage/publish_test.go`
- Opt-in Notarius v0.8.1 production-boundary coverage:
`internal/stage/notarius_cache_integration_test.go`
`internal/stage/extract.go`, `extract_preflight.go`, `extract_native_test.go`,
`internal/artifacts/extraction_evidence.go`, and `internal/adapters/notarius/`
own the stage, readiness, evidence and subprocess boundaries. The opt-in
`notarius_cache_integration_test.go` exercises a real executable.

View File

@@ -37,7 +37,7 @@ Materialize canonical current-session inputs before processing stages.
- rejects duplicate explicit local audio sources after resolution.
- gives distinct local source paths with the same basename deterministic unique
prepared filenames so neither source is overwritten.
- materializes S3 audio through spool/cache-aware logic.
- downloads S3 audio into a temporary sibling before verifying and installing the prepared copy.
- writes effective autocorrection rules as a Seriatim envelope, with checksum,
size, and source provenance, including an empty list when no rules apply.
- renders standalone effective campaign, session, and canonical party documents,
@@ -72,7 +72,7 @@ previous-artifact requirement set. A change reruns prepare and
stales its fixed descendants. Existing successful records without this
evidence rerun once when selected.
Workspace, spool, and cache placement are not semantic when logical selection,
Workspace placement are not semantic when logical selection,
canonical names, and effective bytes are equivalent.
The fingerprint deliberately does not read or rehash large audio. Prepared
input checksums remain the content provenance. Before reusing success, prepare
@@ -86,7 +86,7 @@ reusable; changed or unavailable evidence causes a normal prepare rerun.
- [Configuration](../config.md) owns audio selection, stable input fields, and
previous-session settings.
- [Operations](../operations.md) owns physical input, audio, spool, cache, and
- [Operations](../operations.md) owns physical input, audio, and
previous-state layout.
- [Storage Internals](storage.md) and [Artifact Internals](artifacts.md) explain
the internal collaborators.

View File

@@ -108,7 +108,7 @@ Includes counts/lists for:
- run and previous uploads contain only manifest-declared regular files opened
from verified descriptors; symlinks, special files, replacement races, and
undeclared entries are rejected or ignored before uploads begin.
- run-local diagnostics, including Notarius receipt and stderr files, are
- run-local diagnostics, including Notarius completion report and stderr files, are
archived only when recorded by the session manifest. A run with no declared
current-run diagnostics legitimately uploads none.
- independent publish locks are not overridden by `--force`; every initially

View File

@@ -8,7 +8,7 @@ retention workflow belong in [Operations](../operations.md#local-state-layout).
## Path Ownership
`internal/artifacts` owns canonical session, run, spool, cache, and
`internal/artifacts` owns canonical session, run, and
previous-cache path construction. `SessionPathsFor` provides the session-scoped
path model, and layout creation goes through `EnsureLayoutFor`. Callers should
consume those helpers instead of rebuilding relative paths.
@@ -32,13 +32,11 @@ materialized into canonical session paths before stage success. Managed
previous-session cache paths remain session-durable and are never redirected
into run-local output space.
Polish uses run-local transcript, report/log, and debug destinations; validation
probes use `runs/.validation`. These are not latest-attempt views.
Extraction uses run-local receipt, stderr, and output-root helpers, then
validates and renames the external bundle to the unique immutable Notarius
bundle path supplied by `internal/artifacts`. Exact physical paths belong in
[Operations](../operations.md#extraction-workflow).
Polish and extraction write to actual run-local output, log, and debug paths.
Each attempt advances managed relative `logs/<stage>` and `debug/<stage>` links;
skips do not rotate them. Restore has its own diagnostic attempt. Extraction
promotes validated lanes to flat artifacts and retains the original bundle in
the producing run. See [Operations](../operations.md#local-state-layout).
Prepared references delivered to Notarius use session-durable paths owned by
`internal/artifacts` beneath
@@ -93,7 +91,7 @@ syntax and exact deletion scope belong in [CLI](../cli.md#session-clean) and
- Path model and local store: `internal/artifacts/paths.go`,
`internal/artifacts/local.go`
- Run-local materialization: `internal/stage/run_local.go`
- Immutable bundle installation: `internal/stage/extract.go`
- Bundle validation and product promotion: `internal/stage/extract.go`
- Workspace modes: `internal/fileops/modes.go`
- Cleanup confinement: `internal/fileops/cleanup.go`,
`internal/stage/cleanup.go`, `internal/stage/cleanup_plan.go`, and