From 7874ea648b756fe83abb92854b8219e1c4f26aa5 Mon Sep 17 00:00:00 2001 From: Eric Rakestraw Date: Fri, 27 Nov 2026 01:26:07 +0000 Subject: [PATCH] Document and validate preflight readiness --- cmd/audita/main_integration_test.go | 6 ++- docs/cli.md | 40 ++++++++++++++++--- docs/integrations/subprocess.md | 19 ++++++++- docs/internal/cli-config.md | 7 +++- docs/internal/diagnostics-reporting.md | 10 +++-- docs/internal/overview.md | 7 ++-- docs/internal/pipeline.md | 16 +++++--- docs/operations.md | 20 ++++++++++ docs/roadmap/implementation.md | 4 +- examples/README.md | 4 ++ internal/cli/preflight.go | 8 ++-- internal/cli/preflight_test.go | 16 ++++++++ internal/cli/process_output.go | 7 ---- .../core/diagnostics/output_stream_test.go | 14 +++++++ 14 files changed, 143 insertions(+), 35 deletions(-) diff --git a/cmd/audita/main_integration_test.go b/cmd/audita/main_integration_test.go index bd54871..7ad5029 100644 --- a/cmd/audita/main_integration_test.go +++ b/cmd/audita/main_integration_test.go @@ -1278,8 +1278,10 @@ func TestSubprocessInfeasibleSectionTargetIsAnInputFailure(t *testing.T) { if _, err := os.Stat(f.output); !os.IsNotExist(err) { t.Fatalf("unexpected transcript output: %v", err) } - if document := f.errors(t); document.Status != reporting.StatusFailed { - t.Fatalf("report status: %+v", document) + for _, name := range []string{"errors.yml", "recoveries.yml", "report.md"} { + if _, err := os.Stat(filepath.Join(f.dir, name)); !os.IsNotExist(err) { + t.Fatalf("unexpected report %s: %v", name, err) + } } } diff --git a/docs/cli.md b/docs/cli.md index b9727f8..aea494e 100644 --- a/docs/cli.md +++ b/docs/cli.md @@ -14,6 +14,9 @@ do not load application or model configuration. audita process [flags] transcript.json ``` +`audita run` is an alias of `audita process` and uses the same arguments, +flags, and outcomes. + `--config` selects a main configuration and `--overlay` selects its overlay. `--output` writes the transcript to a file; omission selects stdout. The shared `--debug` flag enables retained debug artifacts, and `--quiet` suppresses optional @@ -50,17 +53,40 @@ commands. Configuration comparison applies the same ordered files to both sides. See the [input format](integrations/transcript-glossary-files.md) and native command help for the available operations. +## Preflight + +```sh +audita preflight --config config.yml --output corrected.json transcript.json +audita preflight --smoke=false --config config.yml --output corrected.json transcript.json +``` + +`preflight` accepts the same transcript argument and intended processing flags, +including overlays, runtime glossary files, output/report destinations, and debug +settings. It checks local preparation and destination readiness without producing +the corrected transcript, ordinary reports, or debug artifacts. The default +`--smoke=true` also checks structured output for each distinct selected profile; +`--smoke=false` limits the command to local readiness. An empty pipeline selects +no profiles. `process` and `run` do not run these smoke checks. Quiet mode requires +an intended output file or `/dev/null` and suppresses optional summaries. + +Provider checks can contact services. Success requires a completed supported +check with positive generation, JSON, and schema observations; it does not prove +compatibility with every prompt or provider-side schema enforcement. Per-profile +smoke usage preserves native unknown and incomplete values. See the +[PromptKit diagnostic guide](https://forge.maximumdirect.net/base-layer/promptkit/src/tag/v0.25.0/docs/consumers/pkg-promptkit.md) +and [operations](operations.md#preflight) for scope and side effects. + ## Inspection and outcomes The application configuration scope uses ConfigKit's native effective values, source evidence, explanation, comparison, and redaction. PromptKit supplies its own configuration and resource scopes and request preparation, validation, and explicit smoke diagnostics. Inspection does not require a processing-ready -pipeline or contact a provider. Processing preflight separately checks the selected -profiles and glossary entries. Smoke tests can contact providers and are run -only on explicit request. Request `--format yaml` or `--format json` for -machine-readable smoke results; their default is text. Shared loading can run -configured secrets bootstrap for inspection as well as processing. +pipeline or contact a provider. Processing and standalone preflight separately +check selected profiles and glossary entries. Native PromptKit smoke commands +can produce machine-readable results; standalone preflight presents human-readable +readiness diagnostics. Shared loading can run configured secrets bootstrap for +inspection as well as processing. Process stdout contains transcript JSON when no output file is selected. Ordinary reports may record recoverable model failures even when processing completes. @@ -68,5 +94,7 @@ Exit status `0` means success, `1` runtime or output failure, `2` invalid usage or input, and native comparison may return `3` for differences. ConfigKit classifies native configuration diagnostics; unclassified runtime preparation and bootstrap failures, and cancellation, are operational. A missing -processing profile or required glossary selection is an input failure. See the +processing profile, required glossary selection, or infeasible requested section +count is an input failure. A failed, unsupported, or inconclusive preflight +provider check is an operational failure. See the [output contract](integrations/output-files.md) and [subprocess contract](integrations/subprocess.md). diff --git a/docs/integrations/subprocess.md b/docs/integrations/subprocess.md index b5510c1..1468b2d 100644 --- a/docs/integrations/subprocess.md +++ b/docs/integrations/subprocess.md @@ -43,14 +43,29 @@ operations and completions. Debug enables progress by default, and `--progress=false` or quiet mode suppresses it. Consume progress as human-readable telemetry. Stdout remains the transcript stream. +## Readiness before processing + +A parent can invoke `audita preflight` with the same explicit configuration, +transcript, glossary selections, and intended output arguments it will later pass +to `process`. Use `--smoke=false` for local-only readiness; the default also +contacts selected providers. Interpret exit 0 as success for the checked scope, +2 as invalid usage or input, and 1 as an operational, output, cancellation, or +provider-verification failure. Diagnostics are human-readable, not a stable +machine report. See [preflight](../cli.md#preflight) and +[operations](../operations.md#preflight) for details and side effects. + +The subsequent invocation reacquires its inputs and resources. Files, credentials, +service availability, and write readiness can change between the two commands; +preflight does not reserve the destination or guarantee that processing succeeds. + ## Result Handling Interpret the exit result according to the [CLI output and exit contract](../cli.md#inspection-and-outcomes). Consume transcript/report data through the [output-file contract](output-files.md), and treat stderr as human-readable detail. -Audita loads configuration and parses the input transcript before report -initialization. Bootstrap failure also occurs before transcript and output +Audita loads configuration, parses and normalizes the transcript, and plans +chunks before report initialization. Bootstrap failure also occurs before transcript and output preparation and may leave no reports. Early destination failures can also leave no reports. After initialization, failed reports can describe partial processing or output failures and use the same report directory as successful runs. diff --git a/docs/internal/cli-config.md b/docs/internal/cli-config.md index 1a3a610..6bdaace 100644 --- a/docs/internal/cli-config.md +++ b/docs/internal/cli-config.md @@ -33,8 +33,11 @@ the [CLI contract](../cli.md) when changing the command; the adoption decision is recorded in [ADR 0001](../adr/0001-releasekit.md). Processing preflight checks glossary selections before inspecting proposal, -validation, and enabled repair profiles in pipeline order. The checked plan -carries the resolved module specs and glossary views into execution. It reuses +validation, and enabled repair profiles in pipeline order. The local plan +carries resolved module specs, glossary views, normalized content, and fixed +sections into execution; the prepared invocation also retains checked output +destinations and source evidence. The standalone route uses the same bindings +and local preparation, while `run` is a native alias of `process`. It reuses profile and backend inspections and equivalent glossary views within the invocation. Native inspection commands continue to inspect configuration without running processing readiness checks. diff --git a/docs/internal/diagnostics-reporting.md b/docs/internal/diagnostics-reporting.md index 6236443..fe0e76a 100644 --- a/docs/internal/diagnostics-reporting.md +++ b/docs/internal/diagnostics-reporting.md @@ -20,15 +20,17 @@ validator entries yield `validation_decisions_filtered` only for a successful operation; they do not count as filtered correction proposals. Failed operations retain their execution counts and never produce a recovery record. -`internal/core/diagnostics.OutputSession` owns destination selection, report -initialization, and publication. Transcript and report files share a staging +`internal/core/diagnostics` checks destinations without opening resources and +can probe regular-file targets with temporary siblings. `OutputSession` consumes +the checked paths and owns report initialization and publication. Transcript and report files share a staging primitive that writes beside the resolved destination. Streams are opened for delivery. Transcript input is protected from early report writes but may be the final transcript destination. The LLM runtime records consumed PromptKit sources and effective host message files and supplies those source paths to CLI; no second filename-based discovery rule is used. -CLI composes it after configuration, transcript acquisition, and preflight -readiness and before dispatching model work. It does not create ordinary report parents. +CLI constructs it after local plan and destination checks and before dispatching +model work. Standalone preflight uses the checker and probes without a session; +its provider observations remain in the LLM adapter. It does not create ordinary report parents. Final report rendering includes delivery and cleanup errors observed so far. When another failure becomes known, later writes use updated failed reports. One best-effort pass refreshes earlier reports with stale evidence. A published diff --git a/docs/internal/overview.md b/docs/internal/overview.md index 890c1a7..4d96e73 100644 --- a/docs/internal/overview.md +++ b/docs/internal/overview.md @@ -59,9 +59,10 @@ These are current implementation boundaries, not bans on future work. ## Main Execution Path (`audita process`) -The CLI inspects configuration and profiles, preflights and initializes active -outputs, optionally creates debug evidence, invokes the runner, and finalizes -transcript and reports. +The CLI prepares an invocation-local plan and checked destinations, initializes +active outputs, optionally creates debug evidence, invokes the runner, and +finalizes transcript and reports. Standalone preflight shares local preparation +and can perform provider diagnostics without creating a processing session. The [pipeline](pipeline.md) owns detailed state transitions; the [operations guide](../operations.md) owns the operator workflow and physical artifact lifecycle. diff --git a/docs/internal/pipeline.md b/docs/internal/pipeline.md index ec14ab2..0dd27ee 100644 --- a/docs/internal/pipeline.md +++ b/docs/internal/pipeline.md @@ -4,14 +4,14 @@ The [input contract](../integrations/transcript-glossary-files.md) owns input formats; [configuration](../config.md) owns settings; the [output contract](../integrations/output-files.md) owns serialized results. -1. CLI loads resolved configuration and transcript input. Preflight checks all - selected glossary views and roles before the output session prepares resources. - Transcript segments then enter canonical normalization. +1. CLI acquires configuration and transcript input. `framework/preflight` checks + selected glossary views and roles, normalizes the canonical transcript, and + returns an invocation-local plan with fixed sections and ordered profile IDs. 2. Normalization sorts segments by start time and preserves input order for ties. It evaluates merge limits using the later end time and the same token estimate as chunking, then reassigns IDs where needed. -3. The runner partitions the normalized transcript exactly once before its - module loop. Initial section identity, segment membership, and token +3. The core chunker partitions the normalized transcript during preparation. + The runner consumes those sections: initial identity, membership, and token estimates stay fixed while text evolves. 4. Module instances execute in configured order. Each section hands its decoded proposals and original local segment references to the runner along with @@ -64,3 +64,9 @@ for invariants. Key tests: `internal/framework/runner/*_test.go`, `internal/framework/validators/*_test.go`, and `cmd/audita/main_integration_test.go`. + +Standalone preflight uses the same local plan and checked destinations, probes +regular output parents, and optionally invokes native structured-output smoke +checks through `framework/llm`. It does not start the runner or an output +session. Processing does not invoke smoke checks. See the +[CLI contract](../cli.md#preflight) for the observable behavior. diff --git a/docs/operations.md b/docs/operations.md index da4b680..ed8ecc4 100644 --- a/docs/operations.md +++ b/docs/operations.md @@ -17,6 +17,24 @@ history to the selected repair provider. A provider rejection ends that branch as unavailable; other approved edits can still be applied. See [configuration](config.md#settings) for the attempt budget and profile selection. +## Preflight + +Standalone preflight shares processing's configuration acquisition, profile and +glossary checks, normalization, chunk planning, and destination checks. It +creates, closes, and removes a temporary file beside each active regular-file +output or report destination; it does not write the final destinations. Disabled +reports, stdout, pipes, and devices are not probed. Parents must already exist. +A successful probe describes current readiness and cannot guarantee a later write. +No ordinary report or debug run directory is created by preflight. + +Configuration acquisition can run secrets bootstrap. Default provider checks +send PromptKit's diagnostic request to each selected profile and can consume +service usage; they do not send the transcript. Local-only mode skips those +provider checks. Native smoke usage is reported per profile independently of the +ordinary execution-observer summary. See the [CLI reference](cli.md#preflight) +for invocation and [PromptKit diagnostics](https://forge.maximumdirect.net/base-layer/promptkit/src/tag/v0.25.0/docs/consumers/pkg-promptkit.md) +for native diagnostic behavior. + ## Configuration trust Treat the selected main file, imports, overlay, and automatically loaded @@ -56,6 +74,8 @@ choose separate report directories when retaining reports from multiple runs. The caller owns these directories and their retention. Later runs can replace ordinary report files at the same destination. +Local readiness, normalization, and chunk planning finish before a processing +reporting session begins. Failures at that boundary need not leave reports. Enabled reports are initialized as `in_progress` before processing. The transcript is published before final reports; the files do not form a single transaction. A late report failure may therefore leave a published transcript. diff --git a/docs/roadmap/implementation.md b/docs/roadmap/implementation.md index e072f64..4ad3ba7 100644 --- a/docs/roadmap/implementation.md +++ b/docs/roadmap/implementation.md @@ -1,6 +1,6 @@ # Dedicated Preflight Command: Implementation Plan -Status: Ready for implementation. +Status: Complete. Implement the target in [Dedicated Preflight Command](preflight-command.md). That roadmap owns the behavior and policy choices; this document defines the @@ -317,6 +317,8 @@ Acceptance: standalone preflight reports the checked scope truthfully and exits ## Stage 8: Complete documentation and final validation +**Completed.** + Work: 1. Update the canonical owners with implemented behavior: diff --git a/examples/README.md b/examples/README.md index 5111af3..211ca70 100644 --- a/examples/README.md +++ b/examples/README.md @@ -12,9 +12,13 @@ local service and its model. Then run: ```sh audita config validate --config config.yml +audita preflight --smoke=false --config config.yml --output corrected.json transcript.json audita process --config config.yml --output corrected.json transcript.json ``` +The local-only preflight checks the intended destination without contacting the +model. Omit `--smoke=false` to run the default live structured-output checks; +see [PromptKit diagnostics](https://forge.maximumdirect.net/base-layer/promptkit/src/tag/v0.25.0/docs/consumers/pkg-promptkit.md). Processing makes model requests. Reports are written beside the selected output unless disabled. For an offline validator preview, from the same directory: diff --git a/internal/cli/preflight.go b/internal/cli/preflight.go index 5bca100..54ea930 100644 --- a/internal/cli/preflight.go +++ b/internal/cli/preflight.go @@ -78,9 +78,11 @@ func verificationLine(result llm.ProfileVerification) string { value := "unknown" if count.count.Known { value = fmt.Sprintf("%d", count.count.Value) - if !count.count.Complete { - value += " (partial)" - } + } + if count.count.Complete { + value += " (complete)" + } else { + value += " (incomplete)" } parts = append(parts, count.name+"="+value) } diff --git a/internal/cli/preflight_test.go b/internal/cli/preflight_test.go index 3968310..4d6f456 100644 --- a/internal/cli/preflight_test.go +++ b/internal/cli/preflight_test.go @@ -15,7 +15,9 @@ import ( "strings" "testing" + "gitea.maximumdirect.net/eric/audita/v4/internal/framework/llm" commandkit "go.maximumdirect.net/commandkit" + pk "go.maximumdirect.net/promptkit" ) func TestPreflightBindingsAndRunAlias(t *testing.T) { @@ -181,3 +183,17 @@ func TestPreflightCancellationRetainsPartialProfileDiagnostics(t *testing.T) { t.Fatalf("status=%d calls=%d cause=%v stderr=%q", result.Status, calls, result.Cause, stderr.String()) } } + +func TestPreflightUsagePreservesUnknownAndCompleteness(t *testing.T) { + report := &pk.SmokeTestReport{Usage: pk.ObservedTokenUsage{ + PromptTokens: pk.ObservedTokenCount{Known: true, Complete: false, Value: 4}, + CompletionTokens: pk.ObservedTokenCount{Known: true, Complete: true, Value: 0}, + TotalTokens: pk.ObservedTokenCount{Known: false, Complete: true}, + }} + line := verificationLine(llm.ProfileVerification{ProfileID: "fixture", Status: llm.VerificationSuccess, Report: report}) + for _, want := range []string{"prompt=4 (incomplete)", "completion=0 (complete)", "total=unknown (complete)", "reasoning=unknown (incomplete)"} { + if !strings.Contains(line, want) { + t.Fatalf("missing %q in %q", want, line) + } + } +} diff --git a/internal/cli/process_output.go b/internal/cli/process_output.go index 93d8413..c5c2cff 100644 --- a/internal/cli/process_output.go +++ b/internal/cli/process_output.go @@ -1,11 +1,9 @@ package cli import ( - "errors" "fmt" "time" - "gitea.maximumdirect.net/eric/audita/v4/internal/core/chunking" "gitea.maximumdirect.net/eric/audita/v4/internal/core/diagnostics" "gitea.maximumdirect.net/eric/audita/v4/internal/core/reporting" "gitea.maximumdirect.net/eric/audita/v4/internal/framework/processreport" @@ -39,11 +37,6 @@ func finishProcess(inv commandkit.Invocation, input processInput, prepared *prep } result := prepared.Prepared.Output.Finish(inv.Context, primary, transcript, render) if result != nil { - var infeasible *chunking.InfeasibleTargetError - var outputFailure diagnostics.FileFailure - if inv.Context.Err() == nil && errors.As(result, &infeasible) && !errors.As(result, &outputFailure) { - return commandkit.Usage(infeasible.Error()).WithCause(result) - } return commandkit.Failure(result.Error()).WithCause(result) } _ = reporter.AtEnd().Info(reporting.CompletionLine(snapshot)) diff --git a/internal/core/diagnostics/output_stream_test.go b/internal/core/diagnostics/output_stream_test.go index a738bf4..f8cf602 100644 --- a/internal/core/diagnostics/output_stream_test.go +++ b/internal/core/diagnostics/output_stream_test.go @@ -68,3 +68,17 @@ func TestTranscriptStreamWriteFailure(t *testing.T) { t.Fatalf("write failure lost: %+v", failures) } } + +func TestProbeSkipsNamedPipeWithoutOpeningIt(t *testing.T) { + fifo := filepath.Join(t.TempDir(), "output.pipe") + if err := syscall.Mkfifo(fifo, 0600); err != nil { + t.Fatal(err) + } + checked, err := CheckOutput(OutputSelection{TranscriptPath: fifo}) + if err != nil { + t.Fatal(err) + } + if err := ProbeOutput(context.Background(), checked); err != nil { + t.Fatal(err) + } +}