Project typed failure origins and join correction evidence by identity
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"slices"
|
||||
"sort"
|
||||
"sync"
|
||||
|
||||
@@ -844,46 +845,42 @@ func validateSectionCandidates(ctx context.Context, input validateSectionCandida
|
||||
// mergeFilteredProposals attributes defective candidates to their originating
|
||||
// proposal response. Each response has at most one filtering recovery reason.
|
||||
func mergeFilteredProposals(unit *WorkUnitOutcome, filtered []outcomes.FilteredProposal) {
|
||||
if unit == nil || len(filtered) == 0 {
|
||||
if len(filtered) == 0 {
|
||||
return
|
||||
}
|
||||
for i := range unit.Operations {
|
||||
operation := &unit.Operations[i]
|
||||
if operation.Reference.Kind != outcomes.OperationProposal || !operation.Succeeded {
|
||||
if operation.Reference.Kind == outcomes.OperationProposal && operation.Succeeded {
|
||||
mergeOperationFiltering(operation, filtered)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func mergeOperationFiltering(operation *outcomes.Operation, filtered []outcomes.FilteredProposal) {
|
||||
seen := make(map[int]struct{}, len(operation.Filtered)+len(filtered))
|
||||
for _, existing := range operation.Filtered {
|
||||
seen[existing.ProposalIndex] = struct{}{}
|
||||
}
|
||||
for _, item := range filtered {
|
||||
if _, ok := seen[item.ProposalIndex]; ok {
|
||||
continue
|
||||
}
|
||||
seen := make(map[int]struct{}, len(operation.Filtered))
|
||||
for _, existing := range operation.Filtered {
|
||||
seen[existing.ProposalIndex] = struct{}{}
|
||||
}
|
||||
for _, item := range filtered {
|
||||
if _, ok := seen[item.ProposalIndex]; ok {
|
||||
continue
|
||||
}
|
||||
seen[item.ProposalIndex] = struct{}{}
|
||||
operation.Filtered = append(operation.Filtered, item)
|
||||
}
|
||||
if len(operation.Filtered) == 0 {
|
||||
continue
|
||||
}
|
||||
sort.Slice(operation.Filtered, func(a, b int) bool {
|
||||
return operation.Filtered[a].ProposalIndex < operation.Filtered[b].ProposalIndex
|
||||
})
|
||||
found := false
|
||||
for _, reason := range operation.RecoveryReasons {
|
||||
if reason == outcomes.RecoveryProposalsFiltered {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
operation.RecoveryReasons = append(operation.RecoveryReasons, outcomes.RecoveryProposalsFiltered)
|
||||
}
|
||||
return
|
||||
seen[item.ProposalIndex] = struct{}{}
|
||||
operation.Filtered = append(operation.Filtered, item)
|
||||
}
|
||||
sort.Slice(operation.Filtered, func(a, b int) bool {
|
||||
return operation.Filtered[a].ProposalIndex < operation.Filtered[b].ProposalIndex
|
||||
})
|
||||
if !slices.Contains(operation.RecoveryReasons, outcomes.RecoveryProposalsFiltered) {
|
||||
operation.RecoveryReasons = append(operation.RecoveryReasons, outcomes.RecoveryProposalsFiltered)
|
||||
}
|
||||
}
|
||||
|
||||
func attributeApplyFiltering(sections []chunking.Section, approved []proposals.EnrichedCorrectionProposal, skipped []proposals.SkippedChange, policy proposals.ReplacementPolicy, units []WorkUnitOutcome) {
|
||||
if len(skipped) == 0 {
|
||||
return
|
||||
}
|
||||
byIndex := make(map[int]proposals.EnrichedCorrectionProposal, len(approved))
|
||||
sectionPosition := make(map[int]int, len(sections))
|
||||
for pos, section := range sections {
|
||||
@@ -892,30 +889,52 @@ func attributeApplyFiltering(sections []chunking.Section, approved []proposals.E
|
||||
for _, proposal := range approved {
|
||||
byIndex[proposal.ProposalIndex] = proposal
|
||||
}
|
||||
lookups := make(map[int]*validators.SectionLookup)
|
||||
filtered := make(map[int][]outcomes.FilteredProposal)
|
||||
for _, skip := range skipped {
|
||||
reason, defective := validators.DefectiveProposalReason(string(skip.SkipReason))
|
||||
proposal, ok := byIndex[skip.ProposalIndex]
|
||||
if !ok || proposal.SectionIndex == nil {
|
||||
if !defective || !ok || proposal.SectionIndex == nil {
|
||||
continue
|
||||
}
|
||||
pos, ok := sectionPosition[*proposal.SectionIndex]
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
var segment *schema.Segment
|
||||
for i := range sections[pos].Segments {
|
||||
if sections[pos].Segments[i].ID == proposal.TargetSegmentID {
|
||||
segment = §ions[pos].Segments[i]
|
||||
break
|
||||
}
|
||||
lookup := lookups[pos]
|
||||
if lookup == nil {
|
||||
lookup = validators.NewSectionLookup(transcriptFromSection(sections[pos]))
|
||||
lookups[pos] = lookup
|
||||
}
|
||||
// A proposal applicable to the input was made stale by a previously
|
||||
// accepted correction. That conflict is not a response defect.
|
||||
var segment *schema.Segment
|
||||
if i, found := lookup.Position(proposal.TargetSegmentID); found {
|
||||
segment = §ions[pos].Segments[i]
|
||||
}
|
||||
// A previously applicable proposal can become stale during application.
|
||||
if proposals.PreviewProposalForSegment(segment, proposal.CorrectionProposal, policy).Applicable {
|
||||
continue
|
||||
}
|
||||
if reason, ok := validators.DefectiveProposalReason(string(skip.SkipReason)); ok {
|
||||
mergeFilteredProposals(&units[pos], []outcomes.FilteredProposal{{ProposalIndex: skip.ProposalIndex, Reason: reason, Count: 1}})
|
||||
filtered[pos] = append(filtered[pos], outcomes.FilteredProposal{ProposalIndex: skip.ProposalIndex, Reason: reason, Count: 1})
|
||||
}
|
||||
for pos, items := range filtered {
|
||||
unit := &units[pos]
|
||||
revisions := make(map[int]*outcomes.Operation)
|
||||
for i := range unit.Operations {
|
||||
op := &unit.Operations[i]
|
||||
if op.Reference.Kind == outcomes.OperationCorrectionRepair && op.Succeeded && op.Reference.ProposalIndex != nil &&
|
||||
slices.Contains(op.RecoveryReasons, outcomes.RecoveryCorrectionRevised) {
|
||||
revisions[*op.Reference.ProposalIndex] = op
|
||||
}
|
||||
}
|
||||
original := items[:0]
|
||||
for _, item := range items {
|
||||
if op := revisions[item.ProposalIndex]; op != nil {
|
||||
mergeOperationFiltering(op, []outcomes.FilteredProposal{item})
|
||||
} else {
|
||||
original = append(original, item)
|
||||
}
|
||||
}
|
||||
mergeFilteredProposals(unit, original)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user