Complete pipeline preflight verification

This commit is contained in:
2026-11-28 04:45:29 +00:00
parent d5056d77b6
commit c08e5ab670
9 changed files with 114 additions and 29 deletions

View File

@@ -132,7 +132,7 @@ incur inference costs; see [Operations](operations.md#preflight-lifecycle).
The assessment contains `pipeline`, `ready`, `checks`, and an optional The assessment contains `pipeline`, `ready`, `checks`, and an optional
`debug_directory`. Each check has a stable class `id`, a structured `scope`, a `debug_directory`. Each check has a stable class `id`, a structured `scope`, a
`result` (`passed`, `failed`, or `warning`), a `message`, and sometimes a `code`. `result` (`passed`, `failed`, or `warning`), a `message`, and sometimes a `code`.
Scopes may identify a path, profile, backend, pipeline, or associated bindings. Scopes may identify a path, reference, profile, backend, pipeline, or associated bindings.
Cache access problems warn without making readiness false. A failed or incomplete Cache access problems warn without making readiness false. A failed or incomplete
required check makes readiness false. Default text shows the summary, failures, required check makes readiness false. Default text shows the summary, failures,
and warnings; verbose visibility adds successful details. JSON and YAML serialize and warnings; verbose visibility adds successful details. JSON and YAML serialize

View File

@@ -5,10 +5,11 @@ configuration, operations, internal, and integration docs. This backlog records
proposed extensions to that implementation. Items below are ordered roughly by proposed extensions to that implementation. Items below are ordered roughly by
value and specificity, not as committed release dates. value and specificity, not as committed release dates.
## Active Implementation Roadmaps ## Feature Context And Implementation
- [Pipeline Preflight](preflight.md): accepted design and staged implementation - [Pipeline Preflight](preflight.md): accepted feature context for invocation
plan for invocation preparation, native provider checks, and readiness reporting. preparation, native provider checks, and readiness reporting; its
[implementation plan](implementation.md) records sequencing and completion.
## Near-Term D&D Pipeline ## Near-Term D&D Pipeline

View File

@@ -510,6 +510,8 @@ narrow cross-document edits, not a rewrite of the documentation suite.
## Stage 11: Verify End-To-End Completion ## Stage 11: Verify End-To-End Completion
**Status:** Complete.
**Goal:** Complete the sprint with full code, documentation, and scope verification. **Goal:** Complete the sprint with full code, documentation, and scope verification.
Review every requirement in `preflight.md` against implementation and test Review every requirement in `preflight.md` against implementation and test

View File

@@ -2,7 +2,7 @@
## Purpose And Status ## Purpose And Status
**Status:** Accepted design; implementation not started. **Status:** Implemented and verified.
This roadmap defines the target behavior and accepted product decisions for This roadmap defines the target behavior and accepted product decisions for
pipeline-aware preflight. There are no remaining open product decisions. pipeline-aware preflight. There are no remaining open product decisions.
@@ -13,7 +13,8 @@ The accepted design here governs implementation where it refines that request,
including the simpler treatment of native capabilities and readiness reporting. including the simpler treatment of native capabilities and readiness reporting.
Current behavior remains documented in [CLI Reference](../cli.md), Current behavior remains documented in [CLI Reference](../cli.md),
[CLI Internals](../internal/cli.md), and [Operations](../operations.md); this [CLI Internals](../internal/cli.md), and [Operations](../operations.md); this
roadmap does not claim that the new command is implemented. roadmap records the accepted feature context; those canonical documents describe
the implemented command.
Private helper types, observer wiring, debug filenames, and exact check Private helper types, observer wiring, debug filenames, and exact check
identifiers remain implementation choices within the accepted contracts. identifiers remain implementation choices within the accepted contracts.

View File

@@ -101,33 +101,34 @@ type preparedPipelineInvocation struct {
raw []byte raw []byte
sessionID string sessionID string
diagnostics []contracts.ProducerDiagnostic diagnostics []contracts.ProducerDiagnostic
failureTarget string
} }
func preparePipelineInvocation(loaded loadedPipelineInvocation, selected selectedPipelineInvocation, input pipelineRunInput) (preparedPipelineInvocation, *commandkit.Outcome) { func preparePipelineInvocation(loaded loadedPipelineInvocation, selected selectedPipelineInvocation, input pipelineRunInput) (preparedPipelineInvocation, *commandkit.Outcome) {
workingDirectory, err := os.Getwd() workingDirectory, err := os.Getwd()
if err != nil { if err != nil {
outcome := commandkit.Failure(err.Error()).WithCause(err) outcome := commandkit.Failure(err.Error()).WithCause(err)
return preparedPipelineInvocation{}, &outcome return preparedPipelineInvocation{failureTarget: "preparation"}, &outcome
} }
materialized, diagnostics, err := pipeline.MaterializeReferences(selected.effective.ResolvedPipeline, selected.catalog, pipeline.ReferenceMaterializationOptions{ConfigPath: loaded.loaded.MainSourcePath(), WorkingDir: workingDirectory}) materialized, diagnostics, err := pipeline.MaterializeReferences(selected.effective.ResolvedPipeline, selected.catalog, pipeline.ReferenceMaterializationOptions{ConfigPath: loaded.loaded.MainSourcePath(), WorkingDir: workingDirectory})
if err != nil { if err != nil {
outcome := commandkit.Failure(err.Error()).WithCause(err) outcome := commandkit.Failure(err.Error()).WithCause(err)
return preparedPipelineInvocation{}, &outcome return preparedPipelineInvocation{failureTarget: "references"}, &outcome
} }
prepared, err := pipeline.Prepare(materialized, selected.registries, pipeline.ModuleDependencies{Engine: selected.engine}) prepared, err := pipeline.Prepare(materialized, selected.registries, pipeline.ModuleDependencies{Engine: selected.engine})
if err != nil { if err != nil {
outcome := commandkit.Failure(err.Error()).WithCause(err) outcome := commandkit.Failure(err.Error()).WithCause(err)
return preparedPipelineInvocation{}, &outcome return preparedPipelineInvocation{resolved: materialized, diagnostics: diagnostics, failureTarget: "modules"}, &outcome
} }
raw, err := os.ReadFile(input.InputFile.Value) raw, err := os.ReadFile(input.InputFile.Value)
if err != nil { if err != nil {
outcome := commandkit.Failure(fmt.Sprintf("Read input %q: %v", input.InputFile.Value, err)).WithCause(err) outcome := commandkit.Failure(fmt.Sprintf("Read input %q: %v", input.InputFile.Value, err)).WithCause(err)
return preparedPipelineInvocation{}, &outcome return preparedPipelineInvocation{resolved: materialized, diagnostics: diagnostics, failureTarget: "input"}, &outcome
} }
sessionID, err := runSessionID(input.Overrides.Resources.SessionID, materialized.Input.Module, raw) sessionID, err := runSessionID(input.Overrides.Resources.SessionID, materialized.Input.Module, raw)
if err != nil { if err != nil {
outcome := commandkit.Failure(err.Error()).WithCause(err) outcome := commandkit.Failure(err.Error()).WithCause(err)
return preparedPipelineInvocation{}, &outcome return preparedPipelineInvocation{resolved: materialized, diagnostics: diagnostics, failureTarget: "input"}, &outcome
} }
return preparedPipelineInvocation{resolved: materialized, prepared: prepared, raw: raw, sessionID: sessionID, diagnostics: diagnostics}, nil return preparedPipelineInvocation{resolved: materialized, prepared: prepared, raw: raw, sessionID: sessionID, diagnostics: diagnostics}, nil
} }

View File

@@ -1,7 +1,9 @@
package cli package cli
import ( import (
"errors"
"fmt" "fmt"
"os"
"text/template" "text/template"
"gitea.maximumdirect.net/eric/notarius/internal/framework/contracts" "gitea.maximumdirect.net/eric/notarius/internal/framework/contracts"
@@ -14,6 +16,7 @@ import (
type preflightScope struct { type preflightScope struct {
Pipeline string `json:"pipeline,omitempty" yaml:"pipeline,omitempty"` Pipeline string `json:"pipeline,omitempty" yaml:"pipeline,omitempty"`
Path string `json:"path,omitempty" yaml:"path,omitempty"` Path string `json:"path,omitempty" yaml:"path,omitempty"`
Reference string `json:"reference,omitempty" yaml:"reference,omitempty"`
Profile string `json:"profile,omitempty" yaml:"profile,omitempty"` Profile string `json:"profile,omitempty" yaml:"profile,omitempty"`
Backend string `json:"backend,omitempty" yaml:"backend,omitempty"` Backend string `json:"backend,omitempty" yaml:"backend,omitempty"`
Bindings []preflight.BindingScope `json:"bindings,omitempty" yaml:"bindings,omitempty"` Bindings []preflight.BindingScope `json:"bindings,omitempty" yaml:"bindings,omitempty"`
@@ -118,20 +121,29 @@ func executePreflight(invocation commandkit.Invocation, input pipelineRunInput,
} }
add("selection", preflightScope{Pipeline: input.PipelineID}, "passed", "Pipeline selection and resources are valid.") add("selection", preflightScope{Pipeline: input.PipelineID}, "passed", "Pipeline selection and resources are valid.")
local, failure := preparePipelineInvocation(loaded, selected, input) local, failure := preparePipelineInvocation(loaded, selected, input)
if failure != nil {
add("preparation", preflightScope{Pipeline: input.PipelineID}, "failed", failure.Explanation.Message)
return finish(*failure)
}
for _, diagnostic := range local.diagnostics { for _, diagnostic := range local.diagnostics {
for _, sample := range diagnostic.Samples { for _, sample := range diagnostic.Samples {
message := sample.Message message := sample.Message
if diagnostic.Disposition == contracts.DiagnosticDispositionWarning { if diagnostic.Disposition == contracts.DiagnosticDispositionWarning {
report.Checks = append(report.Checks, preflightCheck{ID: "reference", Scope: preflightScope{Path: sample.Scope}, Result: "warning", Code: diagnostic.ReasonCode, Message: message}) report.Checks = append(report.Checks, preflightCheck{ID: "reference", Scope: preflightScope{Reference: sample.Scope}, Result: "warning", Code: diagnostic.ReasonCode, Message: message})
} else { } else {
_ = invocation.Reporter().Info(message) _ = invocation.Reporter().Info(message)
} }
} }
} }
if failure != nil {
scope := preflightScope{Pipeline: input.PipelineID}
if local.failureTarget == "input" {
scope.Path = input.InputFile.Value
} else if local.failureTarget == "references" {
var pathErr *os.PathError
if errors.As(failure.Cause, &pathErr) {
scope.Path = pathErr.Path
}
}
add(local.failureTarget, scope, "failed", failure.Explanation.Message)
return finish(*failure)
}
add("preparation", preflightScope{Pipeline: input.PipelineID}, "passed", "References and modules are prepared.") add("preparation", preflightScope{Pipeline: input.PipelineID}, "passed", "References and modules are prepared.")
if _, err := local.prepared.ParseSource(ctx, contracts.ParseRequest{Path: input.InputFile.Value, Raw: local.raw}); err != nil { if _, err := local.prepared.ParseSource(ctx, contracts.ParseRequest{Path: input.InputFile.Value, Raw: local.raw}); err != nil {
add("input", preflightScope{Path: input.InputFile.Value}, "failed", err.Error()) add("input", preflightScope{Path: input.InputFile.Value}, "failed", err.Error())
@@ -153,9 +165,18 @@ func executePreflight(invocation commandkit.Invocation, input pipelineRunInput,
} }
targets, err := preflight.DiscoverTargets(ctx, selected.effective.ResolvedPipeline, selected.catalog, selected.engine) targets, err := preflight.DiscoverTargets(ctx, selected.effective.ResolvedPipeline, selected.catalog, selected.engine)
if err != nil { if err != nil {
add("targets", preflightScope{Pipeline: input.PipelineID}, "failed", err.Error()) scope := preflightScope{Pipeline: input.PipelineID}
var targetErr *preflight.TargetError
if errors.As(err, &targetErr) {
scope.Bindings = []preflight.BindingScope{targetErr.Scope}
}
add("targets", scope, "failed", err.Error())
return finish(pipelineResourceFailure(err)) return finish(pipelineResourceFailure(err))
} }
if err := capture.WriteJSON("targets.json", targets); err != nil {
add("debug", preflightScope{Path: capture.Path()}, "failed", err.Error())
return finish(commandkit.Failure(err.Error()).WithCause(err))
}
evidence := newRunEvidenceRecorder(capture, loaded.result) evidence := newRunEvidenceRecorder(capture, loaded.result)
evidenceIndex := 0 evidenceIndex := 0
observations, err := preflight.RunSmokeChecksObserved(ctx, selected.engine, targets, input.Overrides.Execution.Execution, input.Overrides.Execution.TransientRetries, func(observation preflight.SmokeObservation) error { observations, err := preflight.RunSmokeChecksObserved(ctx, selected.engine, targets, input.Overrides.Execution.Execution, input.Overrides.Execution.TransientRetries, func(observation preflight.SmokeObservation) error {
@@ -181,7 +202,11 @@ func executePreflight(invocation commandkit.Invocation, input pipelineRunInput,
} }
if err != nil { if err != nil {
if !failedCheck { if !failedCheck {
if capture.Err() != nil {
add("debug", preflightScope{Path: capture.Path()}, "failed", err.Error()) add("debug", preflightScope{Path: capture.Path()}, "failed", err.Error())
} else {
add("diagnostics", preflightScope{Pipeline: input.PipelineID}, "failed", err.Error())
}
} }
return finish(commandkit.Failure(err.Error()).WithCause(err)) return finish(commandkit.Failure(err.Error()).WithCause(err))
} }

View File

@@ -90,11 +90,22 @@ func TestPreflightLocalFailureStopsBeforeProvider(t *testing.T) {
if err := json.Unmarshal(out.Bytes(), &report); err != nil || outcome.Status == 0 || report.Ready || client.calls != 0 { if err := json.Unmarshal(out.Bytes(), &report); err != nil || outcome.Status == 0 || report.Ready || client.calls != 0 {
t.Fatalf("outcome=%+v report=%+v error=%v calls=%d", outcome, report, err, client.calls) t.Fatalf("outcome=%+v report=%+v error=%v calls=%d", outcome, report, err, client.calls)
} }
if last := report.Checks[len(report.Checks)-1]; last.ID != "input" || last.Scope.Path != input+"-missing" {
t.Fatalf("input failure scope = %+v", last)
}
if !errors.Is(outcome.Cause, context.Canceled) && outcome.Cause == nil { if !errors.Is(outcome.Cause, context.Canceled) && outcome.Cause == nil {
t.Fatal("missing input cause") t.Fatal("missing input cause")
} }
out.Reset() out.Reset()
stderr.Reset() stderr.Reset()
missingReference := filepath.Join(t.TempDir(), "missing.txt")
outcome = app.Execute(context.Background(), []string{"preflight", "demo", "--config", config, "--input-file", input, "--reference", "context=" + missingReference, "--format", "json"}, commandkit.Streams{Out: &out, Err: &stderr})
report = preflightReport{}
if err := json.Unmarshal(out.Bytes(), &report); err != nil || outcome.Status == 0 || len(report.Checks) == 0 || report.Checks[len(report.Checks)-1].Scope.Path != missingReference || client.calls != 0 {
t.Fatalf("reference failure: outcome=%+v report=%+v err=%v calls=%d", outcome, report, err, client.calls)
}
out.Reset()
stderr.Reset()
outcome = app.Execute(context.Background(), []string{"preflight", "demo", "--config", config}, commandkit.Streams{Out: &out, Err: &stderr}) outcome = app.Execute(context.Background(), []string{"preflight", "demo", "--config", config}, commandkit.Streams{Out: &out, Err: &stderr})
if outcome.Status == 0 || out.Len() != 0 || client.calls != 0 { if outcome.Status == 0 || out.Len() != 0 || client.calls != 0 {
t.Fatalf("missing required flag: %+v %q", outcome, out.String()) t.Fatalf("missing required flag: %+v %q", outcome, out.String())
@@ -187,3 +198,28 @@ func TestPreflightCacheFailureWarnsWithoutPreventingReadiness(t *testing.T) {
t.Fatalf("missing cache warning: %+v", report) t.Fatalf("missing cache warning: %+v", report)
} }
} }
func TestPreflightRetainsReferenceWarningWhenInputReadFails(t *testing.T) {
probe := &runProbe{}
_, config, input, _ := runFixture(t, probe)
app, err := NewApplication("test", Options{Registries: runRegistries(t, probe), LLMClient: &readinessClient{content: `{"status":"ok"}`}})
if err != nil {
t.Fatal(err)
}
empty := filepath.Join(t.TempDir(), "empty.txt")
if err := os.WriteFile(empty, nil, 0o600); err != nil {
t.Fatal(err)
}
var out, stderr bytes.Buffer
outcome := app.Execute(context.Background(), []string{"preflight", "demo", "--config", config, "--input-file", input + "-missing", "--reference", "context=" + empty, "--format", "json"}, commandkit.Streams{Out: &out, Err: &stderr})
var report preflightReport
if err := json.Unmarshal(out.Bytes(), &report); err != nil || outcome.Status == 0 {
t.Fatalf("outcome=%+v report=%+v err=%v", outcome, report, err)
}
for _, check := range report.Checks {
if check.ID == "reference" && check.Result == "warning" && check.Code == "empty_reference" && check.Scope.Reference != "" {
return
}
}
t.Fatalf("reference warning lost: %+v", report.Checks)
}

View File

@@ -35,6 +35,15 @@ type Targets struct {
Access []AccessTarget Access []AccessTarget
} }
// TargetError identifies the binding whose initial target could not be selected.
type TargetError struct {
Scope BindingScope
Cause error
}
func (err *TargetError) Error() string { return err.Cause.Error() }
func (err *TargetError) Unwrap() error { return err.Cause }
// DiscoverTargets identifies initial request targets without invoking providers. // DiscoverTargets identifies initial request targets without invoking providers.
func DiscoverTargets(ctx context.Context, resolved pipeline.ResolvedPipeline, catalog pipeline.ModuleCatalog, engine *promptkit.Engine) (Targets, error) { func DiscoverTargets(ctx context.Context, resolved pipeline.ResolvedPipeline, catalog pipeline.ModuleCatalog, engine *promptkit.Engine) (Targets, error) {
var targets Targets var targets Targets
@@ -46,7 +55,12 @@ func DiscoverTargets(ctx context.Context, resolved pipeline.ResolvedPipeline, ca
} }
profiles := make(map[string]int) profiles := make(map[string]int)
access := make(map[string]int) access := make(map[string]int)
add := func(scope BindingScope, class contracts.ExecutionClass, profile string, prompts []string) error { add := func(scope BindingScope, class contracts.ExecutionClass, profile string, prompts []string) (failure error) {
defer func() {
if failure != nil {
failure = &TargetError{Scope: scope, Cause: failure}
}
}()
if class != contracts.ExecutionClassLLMBacked { if class != contracts.ExecutionClassLLMBacked {
return nil return nil
} }

View File

@@ -69,6 +69,11 @@ prompts:
resolved.Chunk.LLMProfile = "missing" resolved.Chunk.LLMProfile = "missing"
if _, err := DiscoverTargets(context.Background(), resolved, catalog, engine); !errors.Is(err, promptkit.ErrProfileNotFound) { if _, err := DiscoverTargets(context.Background(), resolved, catalog, engine); !errors.Is(err, promptkit.ErrProfileNotFound) {
t.Fatalf("missing profile cause = %v", err) t.Fatalf("missing profile cause = %v", err)
} else {
var targetErr *TargetError
if !errors.As(err, &targetErr) || targetErr.Scope.Module != "chunk" {
t.Fatalf("missing profile binding scope = %v", err)
}
} }
resolved.Chunk.LLMProfile = "" resolved.Chunk.LLMProfile = ""
resolved.Chunk.Module = "dynamic" resolved.Chunk.Module = "dynamic"