Project typed failure origins and join correction evidence by identity
This commit is contained in:
@@ -11,6 +11,7 @@ import (
|
||||
"gitea.maximumdirect.net/eric/audita/v3/internal/core/schema"
|
||||
"gitea.maximumdirect.net/eric/audita/v3/internal/framework/llm"
|
||||
"gitea.maximumdirect.net/eric/audita/v3/internal/framework/preflight"
|
||||
"gitea.maximumdirect.net/eric/audita/v3/internal/framework/runner"
|
||||
"go.maximumdirect.net/ckconfig"
|
||||
commandkit "go.maximumdirect.net/commandkit"
|
||||
ck "go.maximumdirect.net/configkit"
|
||||
@@ -71,7 +72,7 @@ func runProcess(inv commandkit.Invocation, input processInput) commandkit.Outcom
|
||||
warn(debug.WriteNormalizationSummary(summary))
|
||||
}
|
||||
if err := inv.Context.Err(); err != nil {
|
||||
return finishProcess(inv, input, prepared, reporting.Snapshot{}, nil, err)
|
||||
return finishProcess(inv, input, prepared, reporting.Snapshot{}, nil, &runner.ExecutionFailure{Phase: "normalization", Cause: err})
|
||||
}
|
||||
result, runErr := executePipeline(inv.Context, loaded, prepared, normalized, warn)
|
||||
if runErr != nil {
|
||||
@@ -79,14 +80,14 @@ func runProcess(inv commandkit.Invocation, input processInput) commandkit.Outcom
|
||||
}
|
||||
encoder, err := outputschema.Resolve(cfg.Output.Schema)
|
||||
if err != nil {
|
||||
return finishProcess(inv, input, prepared, result.Snapshot, nil, err)
|
||||
return finishProcess(inv, input, prepared, result.Snapshot, nil, &runner.ExecutionFailure{Phase: "encoding", Cause: err})
|
||||
}
|
||||
if result.Transcript == nil {
|
||||
return finishProcess(inv, input, prepared, result.Snapshot, nil, fmt.Errorf("processing returned no transcript"))
|
||||
return finishProcess(inv, input, prepared, result.Snapshot, nil, &runner.ExecutionFailure{Phase: "encoding", Cause: fmt.Errorf("processing returned no transcript")})
|
||||
}
|
||||
payload, err := encoder.Encoder(result.Transcript)
|
||||
if err != nil {
|
||||
return finishProcess(inv, input, prepared, result.Snapshot, nil, err)
|
||||
return finishProcess(inv, input, prepared, result.Snapshot, nil, &runner.ExecutionFailure{Phase: "encoding", Cause: err})
|
||||
}
|
||||
return finishProcess(inv, input, prepared, result.Snapshot, payload, nil)
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ import (
|
||||
"gitea.maximumdirect.net/eric/audita/v3/internal/core/schema"
|
||||
"gitea.maximumdirect.net/eric/audita/v3/internal/framework/llm"
|
||||
"gitea.maximumdirect.net/eric/audita/v3/internal/framework/preflight"
|
||||
"gitea.maximumdirect.net/eric/audita/v3/internal/framework/processreport"
|
||||
"go.maximumdirect.net/ckconfig"
|
||||
commandkit "go.maximumdirect.net/commandkit"
|
||||
ck "go.maximumdirect.net/configkit"
|
||||
@@ -116,10 +117,7 @@ func prepareProcess(ctx context.Context, input processInput, loaded *processInpu
|
||||
failedSnapshot := snapshot
|
||||
completed := time.Now().UTC()
|
||||
failedSnapshot.CompletedAt = &completed
|
||||
if primary != nil {
|
||||
failedSnapshot.Errors = []reporting.ErrorRecord{{Scope: "run", Phase: "initialization", Reason: "canceled", Message: "Processing was canceled."}}
|
||||
}
|
||||
return renderReportBundle(failedOutputSnapshot(failedSnapshot, failures))
|
||||
return renderReportBundle(processreport.Failed(failedSnapshot, primary, "initialization", failures))
|
||||
}
|
||||
}
|
||||
var debug *preflight.DebugInput
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
@@ -9,7 +8,7 @@ import (
|
||||
"gitea.maximumdirect.net/eric/audita/v3/internal/core/chunking"
|
||||
"gitea.maximumdirect.net/eric/audita/v3/internal/core/diagnostics"
|
||||
"gitea.maximumdirect.net/eric/audita/v3/internal/core/reporting"
|
||||
"gitea.maximumdirect.net/eric/audita/v3/internal/framework/outcomes"
|
||||
"gitea.maximumdirect.net/eric/audita/v3/internal/framework/processreport"
|
||||
commandkit "go.maximumdirect.net/commandkit"
|
||||
)
|
||||
|
||||
@@ -28,11 +27,12 @@ func finishProcess(inv commandkit.Invocation, input processInput, prepared *prep
|
||||
if len(reportPaths) > 0 {
|
||||
render = func(cause error, failures []diagnostics.FileFailure) (diagnostics.ReportBundle, error) {
|
||||
report := snapshot
|
||||
if cause != nil {
|
||||
report = failedProcessingSnapshot(report, cause, inv.Context.Err())
|
||||
}
|
||||
if len(failures) > 0 {
|
||||
report = failedOutputSnapshot(report, failures)
|
||||
if cause != nil || len(failures) > 0 {
|
||||
phase := "processing"
|
||||
if primary == nil {
|
||||
phase = "publication"
|
||||
}
|
||||
report = processreport.Failed(snapshot, cause, phase, failures)
|
||||
}
|
||||
return renderReportBundle(report)
|
||||
}
|
||||
@@ -55,43 +55,3 @@ func finishProcess(inv commandkit.Invocation, input processInput, prepared *prep
|
||||
}
|
||||
return commandkit.Success()
|
||||
}
|
||||
|
||||
func failedProcessingSnapshot(snapshot reporting.Snapshot, primary, contextErr error) reporting.Snapshot {
|
||||
for _, record := range snapshot.Errors {
|
||||
if record.Scope == "run" {
|
||||
return failedOutputSnapshot(snapshot, nil)
|
||||
}
|
||||
}
|
||||
record := reporting.ErrorRecord{Scope: "run", Reason: "processing_failure", Message: "Processing failed"}
|
||||
if errors.Is(primary, context.Canceled) || (contextErr != nil && errors.Is(primary, contextErr)) {
|
||||
record.Phase = "processing"
|
||||
record.Reason = string(outcomes.ReasonCanceled)
|
||||
record.Message = "Processing was canceled."
|
||||
}
|
||||
snapshot.Errors = append(snapshot.Errors, record)
|
||||
return failedOutputSnapshot(snapshot, nil)
|
||||
}
|
||||
|
||||
// failedOutputSnapshot derives the count from the same run records sent to each report.
|
||||
func failedOutputSnapshot(snapshot reporting.Snapshot, failures []diagnostics.FileFailure) reporting.Snapshot {
|
||||
snapshot.Status = reporting.StatusFailed
|
||||
if len(failures) > 0 {
|
||||
snapshot.Errors = append([]reporting.ErrorRecord(nil), snapshot.Errors...)
|
||||
}
|
||||
for _, failure := range failures {
|
||||
record := reporting.ErrorRecord{Scope: "run", Reason: "output_failure", Message: "Required output delivery failed", OutputPath: failure.Path}
|
||||
if failure.Kind == "report initialization" {
|
||||
record.Phase = "initialization"
|
||||
record.Message = "Required report initialization failed"
|
||||
}
|
||||
snapshot.Errors = append(snapshot.Errors, record)
|
||||
}
|
||||
count := 0
|
||||
for _, record := range snapshot.Errors {
|
||||
if record.Scope == "run" {
|
||||
count++
|
||||
}
|
||||
}
|
||||
snapshot.Summary.RunErrors = &count
|
||||
return snapshot
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package cli
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"gitea.maximumdirect.net/eric/audita/v3/internal/core/diagnostics"
|
||||
@@ -28,19 +27,24 @@ func executePipeline(ctx context.Context, loaded *processInputs, prepared *prepa
|
||||
}
|
||||
for i := range specs {
|
||||
item := &specs[i]
|
||||
setupFailure := func(role string, cause error) error {
|
||||
return &runner.ExecutionFailure{Phase: "setup", Origin: &outcomes.Reference{
|
||||
StageIndex: &item.Index, StageID: item.ID, ModuleKey: item.ModuleKey, ModuleInstance: item.InstanceName,
|
||||
}, Cause: fmt.Errorf("%s %s client: %w", item.InstanceName, role, cause)}
|
||||
}
|
||||
proposal, err := loaded.Runtime.NewRoleClient("proposal", *item.Settings.LLM.ProposalProfile, item.Settings.LLM, hooks)
|
||||
if err != nil {
|
||||
return processResult{}, fmt.Errorf("%s proposal client: %w", item.InstanceName, err)
|
||||
return processResult{}, setupFailure("proposal", err)
|
||||
}
|
||||
validation, err := loaded.Runtime.NewRoleClient("validation", *item.Settings.LLM.ValidationProfile, item.Settings.LLM, hooks)
|
||||
if err != nil {
|
||||
return processResult{}, fmt.Errorf("%s validation client: %w", item.InstanceName, err)
|
||||
return processResult{}, setupFailure("validation", err)
|
||||
}
|
||||
item.ProposalClient, item.ValidationClient = proposal, validation
|
||||
if item.Settings.LLM.CorrectionRepairAttempts > 0 {
|
||||
repair, err := loaded.Runtime.NewRoleClient("correction_repair", *item.Settings.LLM.CorrectionRepairProfile, item.Settings.LLM, hooks)
|
||||
if err != nil {
|
||||
return processResult{}, fmt.Errorf("%s correction repair client: %w", item.InstanceName, err)
|
||||
return processResult{}, setupFailure("correction repair", err)
|
||||
}
|
||||
item.RepairCoordinator = repair
|
||||
}
|
||||
@@ -63,27 +67,7 @@ func executePipeline(ctx context.Context, loaded *processInputs, prepared *prepa
|
||||
warn(debug.WriteJSONArtifact(diagnostics.ArtifactLLMExecution, processreport.BuildLLMExecution(observations)))
|
||||
warn(debug.WriteJSONArtifact(diagnostics.ArtifactCorrectionLedger, processreport.BuildCorrectionLedger(processreport.CorrectionLedgerInput{RunDirectoryPath: debug.Path(), RunOutput: &output})))
|
||||
}
|
||||
var failures []processreport.RunFailure
|
||||
if runErr != nil {
|
||||
failure := processreport.RunFailure{Phase: "processing", Reason: outcomes.ReasonInternalFailure}
|
||||
var cause *structuredoutput.Failure
|
||||
if errors.As(runErr, &cause) {
|
||||
if cause.Reason != "" {
|
||||
failure.Reason = cause.Reason
|
||||
}
|
||||
} else if errors.Is(runErr, context.Canceled) || (ctx.Err() != nil && errors.Is(runErr, ctx.Err())) {
|
||||
failure.Reason = outcomes.ReasonCanceled
|
||||
}
|
||||
if len(output.ModuleResults) > 0 {
|
||||
last := output.ModuleResults[len(output.ModuleResults)-1]
|
||||
if last.Status == runner.ModuleStatusFailed {
|
||||
index := last.StageIndex
|
||||
failure.Origin = &outcomes.Reference{StageIndex: &index, StageID: last.StageID, ModuleKey: last.ModuleKey, ModuleInstance: last.ModuleInstance}
|
||||
}
|
||||
}
|
||||
failures = append(failures, failure)
|
||||
}
|
||||
snapshot := processreport.Build(processreport.BuildInput{RunID: prepared.RunID, Status: reporting.StatusInProgress, StartedAt: prepared.Started,
|
||||
ModuleSpecs: specs, RunOutput: &output, RunFailures: failures, SummaryOnly: !cfg.Reporting.Enabled})
|
||||
ModuleSpecs: specs, RunOutput: &output, ProcessingError: runErr, SummaryOnly: !cfg.Reporting.Enabled})
|
||||
return processResult{Transcript: output.FinalTranscript, Snapshot: snapshot}, runErr
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user