From 9ae5443073e6d71115fce8f6f8d4751277f71dee Mon Sep 17 00:00:00 2001 From: Eric Rakestraw Date: Wed, 2 Dec 2026 21:20:37 +0000 Subject: [PATCH] Reuse artifact dependents during analysis --- docs/roadmap/audit/catalog.md | 9 ++++--- docs/roadmap/implementation.md | 2 +- internal/stage/analyze.go | 33 +++++------------------ internal/stage/analyze_execution_state.go | 4 +-- 4 files changed, 15 insertions(+), 33 deletions(-) diff --git a/docs/roadmap/audit/catalog.md b/docs/roadmap/audit/catalog.md index da9f933..eee193a 100644 --- a/docs/roadmap/audit/catalog.md +++ b/docs/roadmap/audit/catalog.md @@ -41,10 +41,10 @@ their scope. Unless assigned otherwise, a finding remains independent audit remediation. Shared code does not make a refactoring a prerequisite or assign the whole finding to a roadmap. -Twenty-eight entries are closed by the safety, transfer, audio discovery, S3 +Twenty-nine entries are closed by the safety, transfer, audio discovery, S3 planning, prerequisite-history, publication-import, CLI classification, inspection aggregation, test maintenance, dead-code removal, and associated -documentation work; 15 remain open. **Planned** identifies +documentation work; 14 remain open. **Planned** identifies an agreed remedy awaiting implementation. **Potentially eliminated** requires verification that the offending lifecycle is removed. **Coordinate** identifies shared changes, not a commitment that a related feature implements the entire finding. Findings close only after their @@ -559,7 +559,10 @@ Related: [CAT-10](#cat-10--p2-hydrate-previous-inputs-for-the-full-analysis-prer ### CAT-18 — P3: Reuse the analysis reverse-dependency index within an invocation -Status: Open +Status: Closed + +**Closure.** Analysis reuses its operation-owned graph for success and failure +invalidation, including eligibility barriers. Analyze and checkpoint tests pass. Original findings: [EF-02](02-efficiency.md#ef-02--p3-analysis-rebuilds-the-same-dependency-index-after-each-completion). diff --git a/docs/roadmap/implementation.md b/docs/roadmap/implementation.md index 31161e0..b2ad183 100644 --- a/docs/roadmap/implementation.md +++ b/docs/roadmap/implementation.md @@ -277,7 +277,7 @@ Validation: `go test ./internal/config ./internal/artifactdeps ./internal/artifa ## Stage 8: Reuse Reverse Dependencies Throughout Analysis -CAT IDs: CAT-18. Status: Pending. +CAT IDs: CAT-18. Status: Complete. Read [EF-02](audit/02-efficiency.md#ef-02--p3-analysis-rebuilds-the-same-dependency-index-after-each-completion) and `stage/analyze.go`, `analyze_execution_state.go`, and checkpoint tests. diff --git a/internal/stage/analyze.go b/internal/stage/analyze.go index 536e337..60a10e2 100644 --- a/internal/stage/analyze.go +++ b/internal/stage/analyze.go @@ -200,11 +200,11 @@ func artifactCfgMap(execution analyzeExecutionContext) map[string]config.Scripto } func staleAnalyzeDependents( - configured map[string]config.ScriptoriumArtifactConfig, + graph *artifactdeps.Graph, changed string, records map[string]manifest.AnalyzeArtifactRecord, ) { - staleAnalyzeDependentClosure(configured, changed, records, nil) + staleAnalyzeDependentClosure(graph, changed, records, nil) } func currentAnalyzeArtifactRecord( @@ -284,46 +284,25 @@ func sameAnalyzeOutputIdentity(left, right manifest.AnalyzeArtifactRecord) bool } func staleUnscheduledAnalyzeDependents( - configured map[string]config.ScriptoriumArtifactConfig, + graph *artifactdeps.Graph, changed string, currentKeys map[string]struct{}, records map[string]manifest.AnalyzeArtifactRecord, ) { - staleAnalyzeDependentClosure(configured, changed, records, func(key string) bool { + staleAnalyzeDependentClosure(graph, changed, records, func(key string) bool { _, evaluated := currentKeys[key] return !evaluated }) } func staleAnalyzeDependentClosure( - configured map[string]config.ScriptoriumArtifactConfig, + graph *artifactdeps.Graph, changed string, records map[string]manifest.AnalyzeArtifactRecord, eligible func(string) bool, ) { - reverse := make(map[string][]string, len(configured)) - for key, artifactCfg := range configured { - for _, dependency := range artifacts.NormalizedDependencyKeys(artifactCfg.DependsOn) { - reverse[dependency] = append(reverse[dependency], key) - } - } - for key := range reverse { - sort.Strings(reverse[key]) - } - queue := append([]string(nil), reverse[changed]...) - seen := make(map[string]struct{}, len(queue)) - for len(queue) > 0 { - key := queue[0] - queue = queue[1:] - if _, visited := seen[key]; visited { - continue - } - seen[key] = struct{}{} - if eligible != nil && !eligible(key) { - continue - } + for _, key := range graph.Dependents(changed, eligible) { staleAnalyzeRecord(records, key) - queue = append(queue, reverse[key]...) } } diff --git a/internal/stage/analyze_execution_state.go b/internal/stage/analyze_execution_state.go index b23cef9..72c500e 100644 --- a/internal/stage/analyze_execution_state.go +++ b/internal/stage/analyze_execution_state.go @@ -93,7 +93,7 @@ func (state *analyzeExecutionState) acceptArtifact( prior, hadPrior := state.priorCurrentRecords[plan.Name] if !hadPrior || !sameAnalyzeOutputIdentity(prior, record) { staleUnscheduledAnalyzeDependents( - artifactCfgMap(state.execution), + state.execution.Graph, plan.Name, state.evaluatedKeys, state.records, @@ -229,7 +229,7 @@ func (state *analyzeExecutionState) failedResult( } } state.records[item.Key] = record - staleAnalyzeDependents(artifactCfgMap(state.execution), item.Key, state.records) + staleAnalyzeDependents(state.execution.Graph, item.Key, state.records) state.installManifestCollection() return &StageResult{} }