14 KiB
CAT-10: Prerequisite-History Hydration
Status: Pending
Purpose and scope
Implement CAT-10: 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.
Read the linked CAT-10 entry, FC-01, and TE-03. These sections supply the existing analysis and missing regression scenario. The original audit reports remain historical evidence.
Follow development guidance 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 and boundaries
Keep two concepts distinct:
- Targets are the enabled artifacts, or the exact normalized explicit selection
when supplied.
EffectiveArtifactSetretains that meaning. - The prerequisite closure contains those targets and all transitive configured prerequisites, including disabled prerequisites. History requirements are collected from this closure.
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.
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.
Preserve these existing policies:
- 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.
The shared dependency extraction below is the minimum needed for CAT-10. CAT-17 and CAT-18 retain broader graph ownership/indexing work. The pending session-restore roadmap retains its workflow and remote-authority changes. This plan corrects the existing previous-cache restore path while preserving its current protocol.
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.
Stage 1: Share the existing prerequisite closure below the stage boundary
Status: Complete
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.
- Move
AnalyzeTargetClosureintointernal/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. - 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.
- 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.
- Retain the target-selection behavior of
ResolveEffectiveArtifactSet. Clarify comments that currently equate this target set with all executed work. - 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.
Validation: go test ./internal/artifacts ./internal/stage ./internal/app.
This stage relocates shared mechanics; artifact selections and fingerprints
remain behaviorally unchanged.
Stage 2: Collect and consume prerequisite-inclusive history requirements
Status: Complete
Read internal/artifacts/previous_requirements.go, effective_set.go,
internal/stage/prepare.go, semantic_contracts_initial.go, and the callers
listed below.
-
Have
CollectPreviousArtifactRequirementsexpand 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. -
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
EffectiveArtifactSetor mutate configuration. -
Update every production collector caller:
collectPreparePreviousRequirements, used by preparation andbuildPrepareSemanticConfig;needsObjectStoreForRun, used bycomposeInvocation;buildPreviousCacheRestoreActions; andinspectSessionStatefor previous-input readiness.
-
Let
needsObjectStoreForRunreturn(bool, error)and propagate collection errors throughcomposeInvocation. 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. -
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.
-
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.
-
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.
Validation: go test ./internal/artifacts ./internal/stage ./internal/app.
Verify that force/publication callers still receive the original target set.
Stage 3: Protect the real preparation-to-analysis workflow
Status: Complete
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.
- 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.
- 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.
- 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.
- 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.
- Include explicit and inferred configured-artifact edges across the selected fixtures, using normal domain catalog derivation for inferred edges.
- 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.
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.
- 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.
- 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.
- 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.
- 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.
- 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
-
Update Artifact Internals to define targets versus prerequisite-inclusive requirements and shared closure ownership. Update Preparation Internals, Analysis Internals, and Restore Internals where their descriptions currently imply target-only collection or stage-owned closure mechanics.
-
Update operations 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.
-
Run the repository checks with the maintained toolchain:
GOTOOLCHAIN=go1.27.4 go test ./... GOTOOLCHAIN=go1.27.4 go test -race ./... GOTOOLCHAIN=go1.27.4 go vet ./... GOTOOLCHAIN=go1.27.4 go build ./... -
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.
-
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.
-
Mark these stages complete. Preserve pending roadmap work.
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.