Document and verify published product imports

This commit is contained in:
2026-12-02 16:49:46 +00:00
parent 56483f9064
commit e5d91cb19b
32 changed files with 330 additions and 265 deletions

View File

@@ -2,129 +2,69 @@
## Purpose
Explain the implemented restore discovery, planning, installation, and
reporting flow in `internal/app`. User invocation belongs in
[CLI](../cli.md#session-restore), and the operator recovery procedure and
physical restore scope belong in
[Operations](../operations.md#restore-workflow).
Restore imports products declared by the selected publication inventory into a
local session. The [CLI](../cli.md#session-restore) describes invocation and
[Operations](../operations.md#restore-workflow) describes operator recovery.
The session progress manifest stays local; publication is not a checkpoint backup.
Restore separates remote authority, local conflict policy, and filesystem
mutation so each remains testable independently.
## Discovery and planning
The public command supplies production defaults to one private,
invocation-scoped dependency value. Discovery, planning, and execution use that
same value, so focused sequencing tests can replace one boundary without
mutable package hooks.
`internal/artifacts` validates the current pointer and its immutable commit,
including campaign, session, run, checksum, size, generation, and namespace.
Discovery binds the plan to that inventory. Obsolete execution-snapshot
declarations are ignored without reading their bodies. Authored session YAML
remains a separate configuration input.
## Discovery Contract
The planner maps each recognized published source through the built-in product
registry or current concrete configured definitions. Local products use flat
canonical paths regardless of remote destination names. Exact immutable keys,
checksums, sizes, and generations remain attached to actions, including products
carried from earlier publications by locks. Supported prepared documents and,
with `--include-audio`, audio retain their input paths. Prepared glossary inputs
include the four individual envelopes and the combined glossary. Previous-session
requirements use the shared prerequisite-inclusive collector and exact
published-output declarations; execution diagnostics and remote progress
snapshots are not imported.
Discovery delegates current-state pointer and manifest loading to
`internal/artifacts`, then validates the result against the resolved request:
Each target is classified as `download`, `skip_same`, or `conflict` beneath the
session root. Symlinked or non-regular ancestors and leaves remain conflicts;
`--force` authorizes replacement of differing regular files only. Duplicate
local destinations fail planning. Dry runs perform no durable session writes and
report imports plus projected work using the normal read-only assessment for
preserved local progress. Product coverage is conditional on successful
verification of planned downloads; unavailable local assessment is conservative.
- campaign must match;
- session ID must match.
- run ID must match the pointer-selected committed run.
## Installation and local baseline
Restore treats any missing or invalid remote current state as a command error.
A non-dry run acquires the same workspace lock used by runners before loading
local state and classifying files. It writes an incomplete-restore marker before
installation. Transfers use confined sibling temporary files and verify the
inventory's content and object identity before replacement. Installed products
are checked against their canonical paths, content rules, sizes, and checksums.
## Planning Contract
Restore merges accepted products into a clone of local state and saves the local
manifest last. Identical content with valid local generation evidence keeps that
authority. Other accepted products receive typed supplied records. Changed
products invalidate dependent local work using the existing stage relations;
unrelated checkpoints and locally recorded diagnostics remain. Co-published
products need no shared generation history. The resulting coverage satisfies
work without inventing intermediate files or successful publish, notify, or
cleanup execution.
Restore planner action kinds:
Failure leaves the marker and any already-installed files. A retry reclassifies
those files, verifies them, and saves the merged baseline; the marker is removed
after that save succeeds. This is not a whole-workspace rollback guarantee.
- `download`;
- `skip_same`;
- `conflict`.
## Reporting and ownership
Planner behavior:
Reports identify publication identity, actions, counts, and failures. Actual
attempts persist under the restore run's logs. `restore --force` governs file
replacement and is independent of pipeline force.
- prepared campaign, session, party, and all four glossary inputs are restored
from declared immutable run objects to their canonical local input paths;
- a new-protocol restore uses only the selected commit's declared artifact set;
each action carries that artifact's immutable key, checksum, size, and
generation;
- remote-to-local mapping is traversal-safe;
- actions are sorted by local relative path and then remote key;
- planning opens the selected session root and inspects every target by its
normalized session-relative path. Missing ancestors produce a missing target;
an ancestor or leaf symlink is a non-regular conflict and is never opened for
hashing;
- force converts differing eligible regular files from conflicts to downloads;
directories, symlinks, and other non-regular targets remain conflicts.
For a non-dry-run restore, planning/classification happens only after acquiring
the workspace lock. Runner manifest/reuse checks acquire that same lock first.
Restore uses the default enabled targets and their full prerequisite closure to
collect previous requirements as described in [Artifact Internals](artifacts.md#previous-requirement-collection).
Previous-cache readiness is resolved through `previouscache.Resolve` for restore,
prepare, status, and validation. Each requirement selects the unique
`published_output` for its canonical source in the pointer-selected commit,
then strips only that run's immutable `published/` prefix for its safe local
cache path. It never probes candidate objects or derives paths from manifests,
configuration, or basenames.
## Execution Contract
Execution order and safety:
- non-manifest downloads happen before manifest install;
- `manifest.json` installs last;
- downloads use sibling temp files, validate the complete object, then use an
atomic rename;
- manifest replacement is validated before rename;
- each committed object is verified against its declared checksum, size, and
generation before installation;
- installation reopens the selected session root, creates only validated
missing directory components with workspace modes, and rejects symlinked or
non-regular ancestors and leaves before replacement;
- a committed manifest already verified during discovery is retained for the
matching restore action and revalidated before installation, avoiding a
second body transfer;
- failed installs do not roll back files already written in the same execution.
- a durable `.restore-incomplete.json` marker is written before installation.
It blocks runners until a restore retry completes all verified installs and
the local manifest replacement, at which point it is removed.
- 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
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`;
- 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
- dry-run mode prints a summary, performs no durable session writes, and may
read remote current-state or object-identity data to produce that summary;
- execution mode persists the canonical restore report described in
[Operations](../operations.md#restore-workflow);
- report includes plan counts, per-action status, and execution failures.
## Invariants
- restore uses committed remote current state as authority;
- one restore or status inspection observes the single pointer-selected commit
loaded at discovery; later pointer changes cannot add objects or substitute a
different run into its plan;
- a verified `current/commit-pointer.json` and its selected immutable commit
establish remote commitment; when absent, republish the session;
- restore does not execute pipeline stages.
## Implementation And Tests
- Discovery: `internal/app/restore_discovery.go`
- Planning: `internal/app/restore_plan.go`, `internal/previouscache`
- Execution: `internal/app/restore_execute.go`
- Reporting and command coordination: `internal/app/restore_report.go`,
`internal/app/restore.go`
- Tests: `internal/app/restore_discovery_test.go`,
`internal/app/restore_plan_test.go`,
`internal/app/restore_execution_test.go`,
`internal/app/restore_recovery_test.go`,
`internal/app/restore_workflow_test.go`
Discovery is in `internal/app/restore_discovery.go`, planning and coverage in
`internal/app/restore_plan.go`, transfers in `internal/app/restore_execute.go`,
local baseline installation in `internal/app/restore_manifest_paths.go`, and
command coordination/reporting in `internal/app/restore_command.go` and
`internal/app/restore_report.go`. The restore, import-workflow, artifact, and
recovery tests cover source mapping, identity, conflicts, preservation, retry,
and carried products.