Project typed failure origins and join correction evidence by identity
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package processreport
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"sort"
|
||||
"time"
|
||||
|
||||
@@ -17,19 +18,21 @@ type RunFailure struct {
|
||||
OutputPath string
|
||||
Origin *outcomes.Reference
|
||||
StageIndex *int
|
||||
HasSection bool
|
||||
}
|
||||
|
||||
type BuildInput struct {
|
||||
RunID string
|
||||
Status string
|
||||
StartedAt time.Time
|
||||
CompletedAt *time.Time
|
||||
TranscriptPath string
|
||||
OutputPath string
|
||||
ModuleSpecs []contracts.ModuleRunSpec
|
||||
RunOutput *runner.RunOutput
|
||||
RunFailures []RunFailure
|
||||
SummaryOnly bool
|
||||
RunID string
|
||||
Status string
|
||||
StartedAt time.Time
|
||||
CompletedAt *time.Time
|
||||
TranscriptPath string
|
||||
OutputPath string
|
||||
ModuleSpecs []contracts.ModuleRunSpec
|
||||
RunOutput *runner.RunOutput
|
||||
ProcessingError error
|
||||
RunFailures []RunFailure
|
||||
SummaryOnly bool
|
||||
}
|
||||
|
||||
// Build maps processing facts once into an immutable presentation snapshot.
|
||||
@@ -38,6 +41,10 @@ func Build(input BuildInput) reporting.Snapshot {
|
||||
RunID: input.RunID, Status: input.Status, StartedAt: input.StartedAt.UTC(), CompletedAt: input.CompletedAt,
|
||||
TranscriptPath: input.TranscriptPath, OutputPath: input.OutputPath,
|
||||
}
|
||||
failures := input.RunFailures
|
||||
if input.ProcessingError != nil {
|
||||
failures = append([]RunFailure{processingFailure(input.ProcessingError, "processing")}, failures...)
|
||||
}
|
||||
details := !input.SummaryOnly
|
||||
if details {
|
||||
snapshot.StageNames = make([]string, len(input.ModuleSpecs))
|
||||
@@ -99,7 +106,7 @@ func Build(input BuildInput) reporting.Snapshot {
|
||||
snapshot.Recoveries = append(snapshot.Recoveries, mapRecovery(unit, operation))
|
||||
}
|
||||
}
|
||||
if operation.FailureReason != "" && isRecoverableReason(operation.FailureReason) {
|
||||
if operation.FailureClass == outcomes.FailureRecoverable {
|
||||
unitHasError = true
|
||||
if details {
|
||||
failures = append(failures, mapFailure(operation))
|
||||
@@ -122,6 +129,11 @@ func Build(input BuildInput) reporting.Snapshot {
|
||||
ModuleKey: unit.ModuleKey, ModuleInstance: unit.ModuleInstance, ChunkIndex: &chunk,
|
||||
StartSegmentID: &start, EndSegmentID: &end, CorrectionsApplied: &applied, Failures: failures})
|
||||
}
|
||||
if unit.Failure != nil && !errors.Is(input.ProcessingError, unit.Failure) {
|
||||
record := failureRecord(processingFailure(unit.Failure, "processing"))
|
||||
record.Scope = "interrupted"
|
||||
snapshot.Errors = append(snapshot.Errors, record)
|
||||
}
|
||||
snapshot.WorkUnits = append(snapshot.WorkUnits, row)
|
||||
for _, repair := range unit.Repairs {
|
||||
if repair.AttemptCount == 0 {
|
||||
@@ -140,7 +152,7 @@ func Build(input BuildInput) reporting.Snapshot {
|
||||
}
|
||||
return a.ProposalIndex < b.ProposalIndex
|
||||
})
|
||||
runErrors := len(input.RunFailures)
|
||||
runErrors := len(failures)
|
||||
snapshot.Summary = reporting.Summary{
|
||||
WorkUnitsTotal: &total, WorkUnitsStarted: &started, WorkUnitsCompleted: &completed,
|
||||
WorkUnitsInterrupted: &interrupted, WorkUnitsNotStarted: ¬Started, WorkUnitsWithErrors: &withErrors,
|
||||
@@ -148,32 +160,38 @@ func Build(input BuildInput) reporting.Snapshot {
|
||||
ProposalResponses: &proposalResponses, Recoveries: &recoveryCount,
|
||||
ProposalResponsesWithFiltering: &filteringResponses,
|
||||
}
|
||||
} else if len(input.RunFailures) > 0 {
|
||||
runErrors := len(input.RunFailures)
|
||||
} else if len(failures) > 0 {
|
||||
runErrors := len(failures)
|
||||
snapshot.Summary.RunErrors = &runErrors
|
||||
}
|
||||
for _, failure := range sortedRunFailures(input.RunFailures) {
|
||||
record := reporting.ErrorRecord{Scope: "run", Phase: failure.Phase, Reason: string(failure.Reason),
|
||||
Message: safeMessage(failure.Reason), OutputPath: failure.OutputPath, StageIndex: failure.StageIndex}
|
||||
if failure.Origin != nil {
|
||||
record.ModuleKey, record.ModuleInstance = failure.Origin.ModuleKey, failure.Origin.ModuleInstance
|
||||
record.StageID = failure.Origin.StageID
|
||||
if record.StageIndex == nil {
|
||||
record.StageIndex = failure.Origin.StageIndex
|
||||
}
|
||||
if failure.Origin.Kind != "" {
|
||||
chunk := failure.Origin.SectionIndex
|
||||
record.ChunkIndex = &chunk
|
||||
}
|
||||
record.Operation = string(failure.Origin.Kind)
|
||||
record.Validator = failure.Origin.ValidatorName
|
||||
record.BatchIndex = failure.Origin.BatchIndex
|
||||
}
|
||||
snapshot.Errors = append(snapshot.Errors, record)
|
||||
for _, failure := range sortedRunFailures(failures) {
|
||||
snapshot.Errors = append(snapshot.Errors, failureRecord(failure))
|
||||
}
|
||||
return snapshot
|
||||
}
|
||||
|
||||
func failureRecord(failure RunFailure) reporting.ErrorRecord {
|
||||
record := reporting.ErrorRecord{Scope: "run", Phase: failure.Phase, Reason: string(failure.Reason),
|
||||
Message: safeMessage(failure.Reason), OutputPath: failure.OutputPath, StageIndex: failure.StageIndex}
|
||||
if failure.Origin != nil {
|
||||
record.ModuleKey, record.ModuleInstance = failure.Origin.ModuleKey, failure.Origin.ModuleInstance
|
||||
record.StageID = failure.Origin.StageID
|
||||
if record.StageIndex == nil {
|
||||
record.StageIndex = failure.Origin.StageIndex
|
||||
}
|
||||
if failure.HasSection {
|
||||
chunk := failure.Origin.SectionIndex
|
||||
record.ChunkIndex = &chunk
|
||||
}
|
||||
record.Operation = string(failure.Origin.Kind)
|
||||
record.Validator = failure.Origin.ValidatorName
|
||||
record.BatchIndex = failure.Origin.BatchIndex
|
||||
record.ProposalIndex = failure.Origin.ProposalIndex
|
||||
record.RepairAttempt = failure.Origin.RepairAttempt
|
||||
}
|
||||
return record
|
||||
}
|
||||
|
||||
func mapFailure(operation outcomes.Operation) reporting.Failure {
|
||||
indices := append([]int(nil), operation.ProposalIndices...)
|
||||
sort.Ints(indices)
|
||||
@@ -209,18 +227,6 @@ func mapCounts(counts outcomes.ExecutionCounts) reporting.ExecutionCounts {
|
||||
StructuralRepairs: &repairs, RetriesExhausted: &exhausted, HTTPStatus: counts.HTTPStatus}
|
||||
}
|
||||
|
||||
func isRecoverableReason(reason outcomes.ReasonCode) bool {
|
||||
switch reason {
|
||||
case outcomes.ReasonOperationTimeout, outcomes.ReasonCapacityExceeded, outcomes.ReasonTransportFailed,
|
||||
outcomes.ReasonProviderResponseInvalid, outcomes.ReasonProviderFailed,
|
||||
outcomes.ReasonInvalidOutputExhausted, outcomes.ReasonInvalidOutput,
|
||||
outcomes.ReasonValidationInputTooLarge, outcomes.ReasonValidationDecisionsInvalid:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
func safeMessage(reason outcomes.ReasonCode) string {
|
||||
switch reason {
|
||||
case outcomes.ReasonOperationTimeout:
|
||||
@@ -247,6 +253,8 @@ func safeMessage(reason outcomes.ReasonCode) string {
|
||||
return "Processing setup failed."
|
||||
case outcomes.ReasonInputInvalid:
|
||||
return "Input was invalid."
|
||||
case "output_failure":
|
||||
return "Required output delivery failed."
|
||||
default:
|
||||
return "Processing failed."
|
||||
}
|
||||
@@ -296,7 +304,7 @@ func operationLess(a, b outcomes.Operation) bool {
|
||||
|
||||
func sortedRunFailures(in []RunFailure) []RunFailure {
|
||||
out := append([]RunFailure(nil), in...)
|
||||
phase := map[string]int{"configuration": 0, "destination": 1, "initialization": 2, "input": 3, "normalization": 4, "chunking": 5, "processing": 6, "encoding": 7, "transcript_write": 8, "report_write": 9, "debug": 10}
|
||||
phase := map[string]int{"configuration": 0, "destination": 1, "initialization": 2, "input": 3, "normalization": 4, "chunking": 5, "processing": 6, "setup": 6, "proposal": 6, "validation": 6, "correction_repair": 6, "application": 6, "encoding": 7, "transcript_write": 8, "report_write": 9, "debug": 10}
|
||||
sort.SliceStable(out, func(i, j int) bool {
|
||||
a, aok := phase[out[i].Phase]
|
||||
b, bok := phase[out[j].Phase]
|
||||
|
||||
Reference in New Issue
Block a user