From 56fadeb27d2adc4f9e15847bad0381a15617517b Mon Sep 17 00:00:00 2001 From: Eric Rakestraw Date: Wed, 2 Dec 2026 13:42:03 +0000 Subject: [PATCH] Plan prerequisite history hydration --- docs/roadmap/implementation.md | 370 +++++++++++++++++++-------------- 1 file changed, 210 insertions(+), 160 deletions(-) diff --git a/docs/roadmap/implementation.md b/docs/roadmap/implementation.md index 4448b12..cb4be3c 100644 --- a/docs/roadmap/implementation.md +++ b/docs/roadmap/implementation.md @@ -1,184 +1,232 @@ -# CAT-13: Accurate S3 Planning and Preflight Checks +# CAT-10: Prerequisite-History Hydration -Status: Complete +Status: Pending ## Purpose and scope -Implement [CAT-13](audit/catalog.md#cat-13--p2-give-s3-session-planning-the-evidence-needed-for-truthful-reuse-decisions) -and the [approved planning/preflight decision](audit/discussion.md#3-inspect-s3-when-planning-and-preflighting). -Planning must receive the S3 identity evidence needed to predict preparation -reuse accurately. Preflight must use its existing preparation checks and report -source-access failures accurately. +Implement [CAT-10](audit/catalog.md#cat-10--p2-hydrate-previous-inputs-for-the-full-analysis-prerequisite-closure): +hydrate previous-session inputs needed by the complete analysis prerequisite +closure. This plan replaces the completed CAT-13 plan; that work remains +implemented and closed. -The original analysis is [FC-03](audit/01-correctness.md#fc-03--p2-session-planning-reports-reusable-s3-preparation-as-changed). -Read those linked sections, rather than the full audit, before starting. The -original audit reports remain historical evidence; update disposition and -completion information in the catalog and discussion document. +Read the linked CAT-10 entry, [FC-01](audit/01-correctness.md#fc-01--p2-previous-session-hydration-omits-analysis-prerequisites), +and [TE-03](audit/08-testing.md#te-03--p2-previous-session-hydration-coverage-stops-short-of-dependency-closure). +These sections supply the existing analysis and missing regression scenario. +The original audit reports remain historical evidence. -Complete the stages in order. Each stage is sized for one focused coding-agent -prompt. Follow [development guidance](../development.md) and the applicable -agent, architecture, testing, and documentation policies. Commit each completed -unit with a concise plain-English message. This plan authorizes neither pushing -nor releasing. +Follow [development guidance](../development.md) and its applicable policy +reading guide. Complete these sequential stages as focused coding-agent units, +including their tests and relevant current-behavior documentation. Commit each +completed unit with a concise plain-English message. Pushing and releasing +require separate authorization. -## Selected behavior +## Selected behavior and boundaries -Use the existing shared audio selection, prepared-copy validation, semantic -configuration checks, and S3 key/size/entity-tag comparison. Supply the missing -storage collaborator rather than creating another identity implementation. +Keep two concepts distinct: -| Evidence observed when checking recorded preparation | Planning result | Execution and standalone preflight | -| --- | --- | --- | -| Current remote identities and prepared copies match | Reuse preparation; retain eligible downstream reuse | Reuse preparation | -| Successfully observed identities differ, or existing prepared-copy checks fail | Schedule preparation and its normal dependent invalidation | Run preparation using existing invalidation rules | -| Source inspection fails or supplies insufficient identity evidence | Conservatively schedule preparation with an explicit unverified-source reason and useful cause | Preserve the existing normal preparation attempt; persistent failure prevents readiness | +- Targets are the enabled artifacts, or the exact normalized explicit selection + when supplied. `EffectiveArtifactSet` retains that meaning. +- The prerequisite closure contains those targets and all transitive configured + prerequisites, including disabled prerequisites. History requirements are + collected from this closure. -The third row preserves today's conservative rerun policy. Its reason must -identify inability to verify sources, rather than assert that their content -changed. Dependent work in that plan follows the projected preparation rerun; -it does not certify a remote content change. A successful preparation attempt -after a transient inspection failure may still allow preflight to succeed. -Cancellation and object-store construction errors retain ordinary error -propagation and command failure reporting. +For example, selected `summary` depends on disabled `history`, whose input is +`narratio.previous_session.artifact.history`. Preparation must hydrate that +previous product when available before analysis builds `history` and then +`summary`. An unrelated artifact contributes no history requirement unless it +is itself a target or belongs to the selected closure. -Planning obtains read-only S3 evidence for a selected, successful preparation -reuse candidate. Forced preparation, preparation without recorded success, -local-audio sessions, and ranges excluding preparation do not acquire an audio -identity-check dependency solely for this feature. Existing configuration -acquisition behavior remains unchanged. +Use the concrete dependency relation already derived by configuration, including +explicit ordering and configured-artifact input edges. Family selections have +already expanded to concrete keys. Collect requirements from the full selected +closure independently of current artifact reuse; this extends the existing +target-based preparation policy without adding a runtime input scheduler. -The planning projection reads identities and existing files and models changes -in its cloned manifest. It does not execute preparation, download audio, write -remote objects, create session/run state, persist a manifest, acquire execution -locks, or invoke downstream readiness checks. These are boundaries of this -projection; standalone preflight retains its existing locked, mutating workflow. +Preserve these existing policies: -This work adds no configuration fields, CLI flags, report actions, manifest -schema, retained remote snapshot, or guarantee that sources remain unchanged -between planning and execution. Session restore, publication/checkpoint changes, -audio discovery changes, and other audit findings remain separate work. +- Requirements are deduplicated by previous artifact key; required wins over + optional references, and source locations and results remain deterministic. +- Available optional history is hydrated. Missing optional history follows + existing omission/reporting rules. Missing required history remains an error. + Preserve existing handling of absent previous-session IDs, storage failures, + and invalid remote evidence; optional does not mean every error is ignored. +- Force applies to targets under the current analysis policy. Prerequisites + retain ordinary reuse decisions, and publication selection remains unchanged. +- Analysis resolves previous inputs locally from manifest-backed prepared + records. Acquisition remains in preparation and existing restore handling. +- Preparation, its semantic evidence, storage composition, restore, and status + use the same prerequisite-inclusive requirement collector. -## Stage 1: Distinguish unverifiable preparation sources from changed sources +The shared dependency extraction below is the minimum needed for CAT-10. +[CAT-17](audit/catalog.md#cat-17--p3-centralize-configured-artifact-dependency-queries) +and CAT-18 retain broader graph ownership/indexing work. +The pending [session-restore roadmap](session-restore.md#adapt-preparation-and-operator-reporting) +retains its workflow and remote-authority changes. This plan corrects the +existing previous-cache restore path while preserving its current protocol. -Status: Complete +No new flags, configuration fields, remote discovery fallback, manifest schema, +generic workflow engine, or compatibility layer is needed. Configuration +validation and ConfigKit's ownership boundary remain unchanged. -Read `internal/stage/prepare_resume.go` and its focused tests, especially -`TestPrepareResumeValidatesCurrentS3ObjectIdentity`. Review the existing -`ResumeValidation` result and source discovery errors before editing. +## Stage 1: Share the existing prerequisite closure below the stage boundary -1. Keep confirmed source/prepared-copy mismatches on the existing non-resumable - path. Preserve the current key/size/entity-tag and checksum interpretation. -2. Replace the generic changed-input reason used when - `currentPrepareSourceInputs` returns an error with an accurate explanation - that the sources could not be verified, including useful error context. - Keep the existing non-resumable result and normal rerun policy. -3. Preserve cancellation propagation and existing environment/configuration - errors. Use the current result/error mechanisms; a new error taxonomy or - workflow state is unnecessary. -4. Extend the preparation-resume tests with an unavailable S3 listing and - insufficient identity evidence. Verify that these cannot authorize reuse - and that their reasons distinguish uncertainty from an observed mismatch. - Retain representative unchanged and changed identity coverage. +Status: Pending -Validation: `go test ./internal/stage`. Test semantic diagnostic content rather -than complete error sentences. This stage changes explanations, not the -conditions under which preparation runs. +Read `internal/stage/analyze_plan.go`, the dependency-ordering helpers in +`analyze_fingerprint.go`, `internal/app/preflight_targets.go`, and the existing +analysis planning tests. -## Stage 2: Supply object storage to read-only session planning +1. Move `AnalyzeTargetClosure` into `internal/artifacts`, where preparation, + analysis, and application composition can share it without an import cycle. + Move the ordering, queue, and normalization mechanics needed by that + operation rather than introducing a second traversal. +2. Update analysis planning, fingerprint ordering, and enabled preflight-target + selection to use the shared operations. Redirect other callers of any moved + normalization helper. Remove superseded stage implementations. +3. Preserve deterministic prerequisite-before-dependent ordering, handling of + duplicate/normalized edges, and existing unknown-key/cycle validation. + Configuration retains its origin-aware validation; reverse-edge and + invalidation policy stay with their current owners. +4. Retain the target-selection behavior of `ResolveEffectiveArtifactSet`. + Clarify comments that currently equate this target set with all executed work. +5. Move or adapt existing closure/order tests to their new owner and preserve + stage tests for target/prerequisite roles and force decisions. Cover a nested + disabled prerequisite and exclusion of an unrelated branch without asserting + private helper structure or incidental error wording. -Status: Complete +Validation: `go test ./internal/artifacts ./internal/stage ./internal/app`. +This stage relocates shared mechanics; artifact selections and fingerprints +remain behaviorally unchanged. -Read `internal/app/plan_command.go`, `plan.go`, `semantic_resume.go`, -`object_store.go`, and the preparation branch of `runner_stage_execution.go`. -Use the existing `commandDependencies.newObjectStore` composition seam and -Narratio's object-store contract. +## Stage 2: Collect and consume prerequisite-inclusive history requirements -1. Pass the command-owned storage dependency to plan construction. After - loading the manifest and validating bounded prerequisites, construct the - storage collaborator when S3 preparation is selected, has recorded success, - and is a reuse candidate rather than forced work. A simple eligibility - check is sufficient; do not duplicate source comparison or fingerprinting. -2. Give `projectSelectedWork` an explicit optional object-store dependency and - populate its `stage.Env.ObjectStore`. Continue to use - `evaluateStageResume` and the normal pre-execution decision/modeling logic. - The shared validator performs the actual read-only listing when required. -3. Update all projection callers and relevant tests for the dependency: - `buildSessionPlan`, `inspectInvocationRequirements`, and - `assessSessionReadiness`. Runtime callers pass their already composed - `runtime.env.ObjectStore`; they do not create another client for projection. - Ranges without an S3 preparation check may pass no store. -4. Propagate initialization errors with context through existing command - failure reporting. Listing/identity-inspection failures use Stage 1's - conservative, explicitly unverified result. Honor the invocation context. -5. Add an application-level regression using a prepared S3 session and the - existing fake storage boundary. For identical source evidence, compare the - plan's preparation/dependent decisions with actual execution reuse. Change - a remote identity and verify normal rerun/invalidation is projected and - execution agrees. Include unavailable inspection and construction failure. -6. Exercise the command's injected dependency path so the regression proves - that production planning can reach the store, rather than only testing a - projection manually supplied with one. Preserve coverage of local-audio, - forced/new preparation, and downstream-only planning without introducing - unnecessary remote requirements. +Status: Pending -Validation: `go test ./internal/app ./internal/stage ./internal/audio`. -Use real temporary prepared files and manifests and a fake external store. -Prove that planning leaves authoritative manifest bytes, prepared files, and -the session tree unchanged, including failure paths. Observe that identity -planning performs no audio download or remote mutation. Reuse existing -no-workspace/no-subprocess tests instead of duplicating their entire coverage. +Read `internal/artifacts/previous_requirements.go`, `effective_set.go`, +`internal/stage/prepare.go`, `semantic_contracts_initial.go`, and the callers +listed below. -## Stage 3: Verify S3 checks through the existing preflight workflow +1. Have `CollectPreviousArtifactRequirements` expand the supplied target keys + through the shared closure and scan every included definition. Return an + error alongside requirements so closure failures can propagate. Preserve + existing merging, source-location diagnostics, and deterministic ordering. +2. Keep unresolved/default selection handling at the existing caller boundary. + A resolved empty target set remains empty. Do not replace the target set with + an expanded `EffectiveArtifactSet` or mutate configuration. +3. Update every production collector caller: -Status: Complete + - `collectPreparePreviousRequirements`, used by preparation and + `buildPrepareSemanticConfig`; + - `needsObjectStoreForRun`, used by `composeInvocation`; + - `buildPreviousCacheRestoreActions`; and + - `inspectSessionState` for previous-input readiness. +4. Let `needsObjectStoreForRun` return `(bool, error)` and propagate collection + errors through `composeInvocation`. A selected prepare stage with history + requirements and a previous-session ID must compose storage even when only + a prerequisite consumes history. Preserve the audio/publication branches + and existing behavior for ranges without preparation. +5. Feed the corrected requirements into the existing preparation fingerprint + payload. Preserve its schema/version and hash algorithm: changed requirement + content already changes the digest for affected sessions. Keep analysis + fingerprint versions and unrelated preparation evidence unchanged. +6. Extend collector and composition tests for enabled-target/disabled-parent + and explicit-target cases, nested dependencies, required/optional merging, + and unrelated-branch exclusion. Existing exact-selection tests should still + prove narrowing, with prerequisites now included deliberately. +7. Add semantic-evidence coverage showing that a reachable prerequisite's + history requirement affects preparation reuse, while an unrelated definition + does not. Reuse existing validation tests for malformed dependency graphs. -Read `internal/app/session_readiness.go`, `runner_composition.go`, -`runner_preflight.go`, and `session_readiness_test.go`. Standalone preflight -already executes or reuses preparation under the session lock, which supplies -the store and performs the relevant S3 check. +Validation: `go test ./internal/artifacts ./internal/stage ./internal/app`. +Verify that force/publication callers still receive the original target set. -1. Exercise standalone preflight with prepared S3 audio using the existing - command dependencies and readiness test fixtures. Verify unchanged sources - reuse preparation and do not redownload verified prepared audio. -2. Change a selected remote object's identity and verify preflight prepares - current input, persists the normal preparation evidence, and invalidates - dependent success according to the existing rules. -3. Make source inspection persistently fail. Verify the preparation diagnostic - identifies the failed verification/access rather than proven content drift, - the eventual preparation error remains visible, and readiness fails. Keep - existing behavior for independent checks and retained progress. A downstream - provider failure after successful reuse remains a separate failure. -4. Cover cancellation at the remote inspection boundary with the existing - context/error conventions. Consolidate coverage already provided by Stage 2 - or existing tests rather than asserting the same behavior at every layer. -5. Fix only integration gaps these checks expose. Reuse the preparation and - composed-store paths; no separate S3 readiness probe, redundant listing - pass, or new preflight lifecycle is needed. Do not redefine preflight as - read-only or prohibit its existing downloads, manifest updates, and probes. +## Stage 3: Protect the real preparation-to-analysis workflow -Validation: `go test ./internal/app ./internal/stage ./internal/audio`. -Keep the tests offline and credential-free. Assert outcomes and evidence, -using transfer observations only to protect real reuse/read-only behavior; -avoid incidental exact call counts or ordering. +Status: Pending -## Stage 4: Document the boundary and close CAT-13 +Use `prepare_effective_artifacts_test.go`, `prepare_previous_test.go`, +`prepare_test.go`, and `analyze_incremental_execution_test.go` as fixture +references. Replace the missing combination identified by TE-03 with a focused +assembled regression. -Status: Complete +1. Run real preparation and analysis against the same resolved configuration, + manifest, and temporary workspace. Use the existing fake object store and + Scriptorium runner only at external boundaries. Supply valid transcript + evidence where the fixture needs it. +2. Cover both default enabled-target selection and an explicit child selection. + Give the child a disabled prerequisite with a previous-session input and add + unrelated work. For explicit selection, include an otherwise enabled + unrelated artifact to prove explicit narrowing is preserved. +3. Exercise required-present and optional-present history. Assert the canonical + previous source and checksum in preparation's input records, the actual + history bytes/path passed in the prerequisite's generation request, and + prerequisite-before-child execution. Unrelated history is neither required + nor fetched and unrelated artifact generation is excluded. +4. Exercise optional absence through the same workflow: preparation records the + existing missing-optional outcome and generation omits that binding. Verify + required absence fails preparation and prevents analysis from proceeding; + reuse narrow existing absence tests where they already cover the same risk. +5. Include explicit and inferred configured-artifact edges across the selected + fixtures, using normal domain catalog derivation for inferred edges. +6. Verify that a previously successful preparation with a different history + requirement set is reconsidered by normal semantic resume. An unchanged + requirement set retains normal reuse. Retain existing forced-target/current- + prerequisite coverage rather than broadening force to every closure member. -1. Update [CLI planning semantics](../cli.md#session-plan) to explain read-only - remote source inspection, existing action/reason reporting for unverified - inputs, and the observation-time limitation. Distinguish object-storage - composition from executing stage adapters and downstream inspection. -2. Update [operations](../operations.md#prompt-requirements-preflight) for the - operator-facing difference between planning and preflight where necessary. - Keep command syntax in the CLI reference and operational workflows in - operations; link rather than repeat their contracts. -3. Update the focused planning description in - [Internal Overview](../internal/overview.md), - [Preparation Internals](../internal/stage-prepare.md), and - [Preflight Internals](../internal/preflight.md) only where their owned - explanations need the new collaborator or diagnostic distinction. -4. Run the repository checks with the maintained Go toolchain: +Validation: `go test ./internal/stage ./internal/artifacts ./internal/previouscache`. +The principal regression must fail with the original target-only collector. +Do not manually supply the expected requirements list or pre-populate the +missing prepared history to bypass the collection/hydration path. + +## Stage 4: Verify restore and operator readiness use the same requirements + +Status: Pending + +Read `internal/app/restore_plan.go`, `restore_plan_test.go`, +`restore_execution_test.go`, `restore_workflow_test.go`, +`session_state_command.go`, and `session_readiness_test.go`. + +1. Extend previous-cache restore coverage to an enabled child with a disabled + prerequisite consuming history. Restore uses its current default target + selection; this work adds no artifact-selection option to restore. +2. Verify the dry-run action set includes the required prerequisite history, + excludes unrelated history, and leaves durable session files unchanged. + Verify actual restore installs the selected declared product at the existing + canonical cache path. Cover optional-present history and retain existing + missing-required/missing-optional behavior. +3. Exercise restored history reaching prerequisite analysis through the existing + local resolver. Seed valid matching committed manifest/input evidence before + restore; do not repair missing authority records after restore to make the + test pass. Synthesizing a new execution baseline or reconciling a changed + remote history with historical manifest evidence belongs to the separate + session-restore roadmap. +4. Verify status/readiness includes the prerequisite's previous requirement and + preserves required/optional classifications. Exercise standalone preflight + through its real preparation flow so it hydrates prerequisite history using + normal storage composition. Reuse Stage 3's data-selection coverage. +5. Preserve existing reports and failure conventions, restore transfer/conflict + handling, and analysis's local-only previous-input resolution. Keep S3 + planning/preflight behavior established by CAT-13 intact. + +Validation: `go test ./internal/app ./internal/previouscache ./internal/stage`. +Use committed remote fixtures and fake adapters; no live services or credentials +are required. + +## Stage 5: Document the corrected scope and close CAT-10 + +Status: Pending + +1. Update [Artifact Internals](../internal/artifacts.md#previous-requirement-collection) + to define targets versus prerequisite-inclusive requirements and shared + closure ownership. Update [Preparation Internals](../internal/stage-prepare.md), + [Analysis Internals](../internal/stage-analyze.md), and + [Restore Internals](../internal/command-restore.md) where their descriptions + currently imply target-only collection or stage-owned closure mechanics. +2. Update [operations](../operations.md#artifact-development-workflows) and its + restore workflow only where operator guidance needs the corrected history + scope. Keep current force/publication and required/optional policies intact. + Link to canonical contracts rather than duplicating them. +3. Run the repository checks with the maintained toolchain: ```sh GOTOOLCHAIN=go1.27.4 go test ./... @@ -187,14 +235,16 @@ Status: Complete GOTOOLCHAIN=go1.27.4 go build ./... ``` -5. Review the final diff against the selected behavior above. Confirm no new - remote-resume protocol, audio-selection rules, freshness guarantee, or - access-failure prohibition was added. -6. After successful validation, mark CAT-13 closed in the audit catalog and - record completion in discussion topic 3, linking to the implementing commits - and relevant regression coverage. Mark the implementation stages complete. - Leave unrelated audit statuses and pending roadmaps unchanged. +4. Review the diff for duplicated dependency algorithms, expanded target sets, + blanket fingerprint invalidation, and changes to optional-error semantics. + Confirm the new shared operations remain proportionate to CAT-10. +5. After successful validation, close CAT-10 in the audit catalog with links to + implementation commits and regression coverage; update its summary counts. + Note the implemented collector for future session-restore work and the narrow + shared-closure extraction under CAT-17 without closing that broader finding. + Leave original audit reports and unrelated statuses unchanged. +6. Mark these stages complete. Preserve pending roadmap work. -Completion means unchanged S3 preparation is truthfully reusable in plans and -preflight; observed changes schedule the existing replacement path; unavailable -evidence is identified accurately; and planning leaves session state untouched. +Completion means every consumer derives history needs from the same selected +prerequisite closure, history reaches actual prerequisite generation, and target, +force, publication, and existing acquisition/restore policies remain intact.