Files
narratio/docs/roadmap/implementation.md

251 lines
14 KiB
Markdown
Raw Normal View History

2026-12-02 13:42:03 +00:00
# CAT-10: Prerequisite-History Hydration
2026-12-02 13:42:03 +00:00
Status: Pending
## Purpose and scope
2026-12-02 13:42:03 +00:00
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.
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.
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 and boundaries
Keep two concepts distinct:
- 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.
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](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.
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: Pending
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.
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.
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: Pending
Read `internal/artifacts/previous_requirements.go`, `effective_set.go`,
`internal/stage/prepare.go`, `semantic_contracts_initial.go`, and the callers
listed below.
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:
- `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.
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: Pending
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.
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.
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 ./...
GOTOOLCHAIN=go1.27.4 go test -race ./...
GOTOOLCHAIN=go1.27.4 go vet ./...
GOTOOLCHAIN=go1.27.4 go build ./...
```
2026-12-02 13:42:03 +00:00
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 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.