diff --git a/docs/internal/preflight.md b/docs/internal/preflight.md index f456e69..45820ff 100644 --- a/docs/internal/preflight.md +++ b/docs/internal/preflight.md @@ -17,6 +17,10 @@ and remote-lock inspection while the context remains active. Preparation success is persisted even when later readiness fails; readiness itself creates no stage or reusable success record. +Shared finalization retains terminal manifest evidence while locked. Normal +pipeline execution projects that evidence into its run-artifact inventory; +standalone preflight returns its readiness report without building that inventory. + Audita receives verified prepared glossary files and production selections with an embedded synthetic transcript. Its adapter performs native provider smoke checks and retains failure causes. Notarius receives production controls and diff --git a/docs/roadmap/remediation.md b/docs/roadmap/remediation.md index 0b821bb..c250e9d 100644 --- a/docs/roadmap/remediation.md +++ b/docs/roadmap/remediation.md @@ -5,7 +5,8 @@ Reviewed baseline: `b2877c1`. Scope: the seven stages of [the implementation plan](implementation.md), with attention to algorithmic cost in their shared collaborators. The findings below are optimization opportunities for consideration, not demonstrated operational -failures or release blockers. No refactors were implemented in this audit. +failures or release blockers. The audit made no application changes; completion +notes below record subsequent remediation. Both findings are now complete. The selected prepare/resume machinery, pure transcript-work projection, enabled-versus-projected target selection, and independent native checks remain @@ -65,7 +66,16 @@ unchanged. Avoid timing thresholds or a new diagnostic-count limit. ## 2. Avoid Building A Discarded Run-Artifact Inventory -Status: Open for consideration. Priority: P3. +Status: Complete. Priority: P3. + +Completion: shared finalization now returns a lightweight invocation result with +terminal manifest evidence. Only normal pipeline execution builds the full run +summary and artifact inventory; standalone preflight does not traverse or sort +that inventory. Terminal persistence and durable-evidence recovery remain under +the session lock, and normal summary completion includes lock-release failures. +Updated lifecycle tests and internal documentation. Verified with Go 1.27.4: +`go test ./...`, `go test -race ./...`, `go vet ./...`, `go build ./...`, focused +application/preflight/documentation tests, and `git diff --check`. Evidence: [standalone lifecycle caller](../../internal/app/session_readiness.go), lines 79–90, and [finalization](../../internal/app/runner_finalization.go), diff --git a/internal/app/runner.go b/internal/app/runner.go index 25bbed3..b89f709 100644 --- a/internal/app/runner.go +++ b/internal/app/runner.go @@ -46,10 +46,14 @@ func executePlan(ctx context.Context, cfg *config.Config, plan BoundedPlan, opts } func executePlanWithDependencies(ctx context.Context, cfg *config.Config, plan BoundedPlan, opts RunOptions, dependencies invocationDependencies) (*RunSummary, error) { - return withLockedInvocation(ctx, cfg, plan, opts, dependencies, executeSelectedStages) + result, err := withLockedInvocation(ctx, cfg, plan, opts, dependencies, executeSelectedStages) + if result == nil { + return nil, err + } + return result.runSummary(err == nil), err } -func withLockedInvocation(ctx context.Context, cfg *config.Config, plan BoundedPlan, opts RunOptions, dependencies invocationDependencies, operation func(*invocationRuntime) error) (summary *RunSummary, resultErr error) { +func withLockedInvocation(ctx context.Context, cfg *config.Config, plan BoundedPlan, opts RunOptions, dependencies invocationDependencies, operation func(*invocationRuntime) error) (result *invocationResult, resultErr error) { dependencies = dependencies.normalized() runtime, err := prepareInvocation(ctx, cfg, plan, opts, dependencies) if err != nil { @@ -76,13 +80,10 @@ func withLockedInvocation(ctx context.Context, cfg *config.Config, plan BoundedP resultErr = errors.Join(resultErr, fmt.Errorf("release session lock: %w", releaseErr)) } } - if summary != nil { - summary.Complete = resultErr == nil - } }() defer func() { if runtime.started { - summary, resultErr = finalizeInvocation(runtime, resultErr) + result, resultErr = finalizeInvocation(runtime, resultErr) } }() diff --git a/internal/app/runner_finalization.go b/internal/app/runner_finalization.go index 618ccb6..293034b 100644 --- a/internal/app/runner_finalization.go +++ b/internal/app/runner_finalization.go @@ -28,7 +28,14 @@ type RunArtifact struct { Evidence string `json:"evidence"` } -func finalizeInvocation(runtime *invocationRuntime, operationErr error) (*RunSummary, error) { +// invocationResult retains terminal evidence without projecting a report-specific +// artifact inventory. Preflight needs only whether the lifecycle started. +type invocationResult struct { + runtime *invocationRuntime + evidence *manifest.Manifest +} + +func finalizeInvocation(runtime *invocationRuntime, operationErr error) (*invocationResult, error) { evidence := runtime.manifest resultErr := operationErr if operationErr != nil { @@ -42,13 +49,18 @@ func finalizeInvocation(runtime *invocationRuntime, operationErr error) (*RunSum evidence = nil } } + return &invocationResult{runtime: runtime, evidence: evidence}, resultErr +} + +func (result *invocationResult) runSummary(complete bool) *RunSummary { + runtime := result.runtime return &RunSummary{ SessionID: runtime.identity.SessionID, RunID: runtime.identity.RunID, ManifestPath: runtime.manifestPath, StageNames: runtime.stageNames, Executed: runtime.executed, Skipped: runtime.skipped, - StageResults: runtime.stageResults, AvailableArtifacts: durableRunArtifacts(evidence), - Complete: resultErr == nil, - }, resultErr + StageResults: runtime.stageResults, AvailableArtifacts: durableRunArtifacts(result.evidence), + Complete: complete, + } } func durableRunArtifacts(m *manifest.Manifest) []RunArtifact { diff --git a/internal/app/session_readiness.go b/internal/app/session_readiness.go index 8a04b04..a2d634b 100644 --- a/internal/app/session_readiness.go +++ b/internal/app/session_readiness.go @@ -76,11 +76,11 @@ func inspectConfiguredSessionReadiness(ctx context.Context, cfg *config.Config, newObjectStore: func(ctx context.Context, cfg *config.Config) (storage.ObjectStore, error) { return initializeObjectStoreBackend(ctx, cfg, deps.newObjectStore) }} - summary, err := withLockedInvocation(ctx, cfg, plan, RunOptions{Reporter: deps.reporter}, invocationDeps, func(runtime *invocationRuntime) error { + result, err := withLockedInvocation(ctx, cfg, plan, RunOptions{Reporter: deps.reporter}, invocationDeps, func(runtime *invocationRuntime) error { report.RunID = runtime.identity.RunID return assessSessionReadiness(runtime, report, deps) }) - if summary == nil && err != nil { + if result == nil && err != nil { report.Findings = append(report.Findings, errorFinding("workspace", err.Error())) report.Checks = append(report.Checks, readinessCheck{Group: "workspace/storage", Outcome: "failed", Message: err.Error()}) } else if err != nil { diff --git a/internal/app/session_readiness_test.go b/internal/app/session_readiness_test.go index 26c17c0..fad5a13 100644 --- a/internal/app/session_readiness_test.go +++ b/internal/app/session_readiness_test.go @@ -165,9 +165,9 @@ func TestPreflightReportsPreparationPersistenceAndFinalizationFailures(t *testin } report := &sessionReadinessReport{Preparation: preparationAssessment{Outcome: "not_attempted"}} invDeps := invocationDependencies{newAudita: deps.newAudita, newScriptorium: deps.newScriptorium, newNotarius: deps.newNotarius} - summary, err := withLockedInvocation(context.Background(), cfg, plan, RunOptions{Env: &Env{ManifestStore: mstore, ArtifactStore: local}}, invDeps, func(runtime *invocationRuntime) error { return assessSessionReadiness(runtime, report, deps) }) - if summary == nil || summary.Complete || !errors.Is(err, releaseFailure) { - t.Fatalf("summary=%+v report=%+v error=%v", summary, report, err) + result, err := withLockedInvocation(context.Background(), cfg, plan, RunOptions{Env: &Env{ManifestStore: mstore, ArtifactStore: local}}, invDeps, func(runtime *invocationRuntime) error { return assessSessionReadiness(runtime, report, deps) }) + if result == nil || !errors.Is(err, releaseFailure) { + t.Fatalf("result=%+v report=%+v error=%v", result, report, err) } if failureAt == "preparation" { if report.Preparation.Outcome != "failed" || len(provider.PreflightRequests) != 0 { @@ -204,11 +204,11 @@ func TestPreflightCannotSucceedWithoutPreparedEvidence(t *testing.T) { deps := normalizeCommandDependencies(fakeCommandDependencies(&storage.FakeBackend{}, nil)) report := &sessionReadinessReport{Preparation: preparationAssessment{Outcome: "not_attempted"}} plan := BoundedPlan{stages: []stage.Stage{resultStage{name: "prepare", result: &stage.StageResult{Disposition: stage.StageDispositionSkipped, SkipReason: "no inputs"}}}} - summary, err := withLockedInvocation(context.Background(), cfg, plan, RunOptions{}, invocationDependencies{newAudita: deps.newAudita, newScriptorium: deps.newScriptorium}, func(runtime *invocationRuntime) error { + result, err := withLockedInvocation(context.Background(), cfg, plan, RunOptions{}, invocationDependencies{newAudita: deps.newAudita, newScriptorium: deps.newScriptorium}, func(runtime *invocationRuntime) error { return assessSessionReadiness(runtime, report, deps) }) - if err == nil || summary == nil || summary.Complete || report.Preparation.Outcome != "failed" { - t.Fatalf("summary=%+v report=%+v error=%v", summary, report, err) + if err == nil || result == nil || report.Preparation.Outcome != "failed" { + t.Fatalf("result=%+v report=%+v error=%v", result, report, err) } }