2026-11-21 23:48:51 +00:00
|
|
|
package pipeline
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
|
|
"gitea.maximumdirect.net/eric/notarius/internal/core/source"
|
|
|
|
|
"gitea.maximumdirect.net/eric/notarius/internal/framework/contracts"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// completeProducerOperation assesses deterministic work once. LLM modules have
|
|
|
|
|
// already used their operation's assessor through RunProducer and must return
|
|
|
|
|
// its disposition; the runner never assesses those results a second time.
|
|
|
|
|
func completeProducerOperation[T any](ctx context.Context, class contracts.ExecutionClass, operation contracts.ProducerOperation[T], value T, outcome contracts.ProducerOutcome, fallback func(context.Context) (T, error)) (T, contracts.ProducerOutcome, error) {
|
|
|
|
|
var zero T
|
|
|
|
|
if err := ctx.Err(); err != nil {
|
|
|
|
|
return zero, contracts.ProducerOutcome{}, err
|
|
|
|
|
}
|
|
|
|
|
if class == contracts.ExecutionClassDeterministic {
|
2026-11-22 00:17:58 +00:00
|
|
|
return AssessProducer(ctx, operation, value, fallback)
|
2026-11-21 23:48:51 +00:00
|
|
|
} else if class != contracts.ExecutionClassLLMBacked {
|
|
|
|
|
return zero, contracts.ProducerOutcome{}, fmt.Errorf("unsupported producer execution class %q", class)
|
|
|
|
|
}
|
|
|
|
|
switch outcome.Disposition {
|
|
|
|
|
case contracts.ProducerAccepted:
|
|
|
|
|
outcome.ReuseEligible = operation.ReuseEligible && outcome.ReuseEligible
|
|
|
|
|
case contracts.ProducerFallback:
|
|
|
|
|
if operation.Controls.Mode != contracts.ModePermissive {
|
|
|
|
|
return zero, contracts.ProducerOutcome{}, fmt.Errorf("producer returned fallback without permissive mode")
|
|
|
|
|
}
|
|
|
|
|
if outcome.FallbackReason == "" {
|
|
|
|
|
return zero, contracts.ProducerOutcome{}, fmt.Errorf("producer fallback has no reason")
|
|
|
|
|
}
|
|
|
|
|
outcome.ReuseEligible = false
|
|
|
|
|
default:
|
|
|
|
|
return zero, contracts.ProducerOutcome{}, fmt.Errorf("producer did not return an acceptance or fallback outcome")
|
|
|
|
|
}
|
|
|
|
|
return value, outcome, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func operationDiagnosticGroups(diagnostics []contracts.ProducerDiagnostic, assessment contracts.CandidateAssessment, outcome contracts.ProducerOutcome, origin contracts.DiagnosticOrigin, chunk *source.Chunk) ([]contracts.DiagnosticGroup, error) {
|
|
|
|
|
groups, err := promoteProducerDiagnostics(diagnostics, origin, chunk)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
if outcome.Disposition == contracts.ProducerFallback {
|
|
|
|
|
warning := contracts.ProducerDiagnostic{
|
|
|
|
|
Disposition: contracts.DiagnosticDispositionWarning, Category: contracts.DiagnosticCategoryFallback,
|
|
|
|
|
ReasonCode: "producer_fallback", OccurrenceCount: 1,
|
|
|
|
|
Samples: []contracts.DiagnosticSample{{Scope: origin.ModuleKey, Message: outcome.FallbackReason}},
|
|
|
|
|
}
|
|
|
|
|
fallbackGroups, err := promoteProducerDiagnostics([]contracts.ProducerDiagnostic{warning}, origin, chunk)
|
|
|
|
|
return append(groups, fallbackGroups...), err
|
|
|
|
|
}
|
|
|
|
|
for _, finding := range assessment.Validators {
|
|
|
|
|
if finding.Decision != contracts.AssessmentApproved {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
validatorOrigin := origin
|
|
|
|
|
validatorOrigin.ValidatorKey = finding.ValidatorName
|
|
|
|
|
validatorGroups, err := promoteProducerDiagnostics(finding.Result.Diagnostics, validatorOrigin, chunk)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
groups = append(groups, validatorGroups...)
|
|
|
|
|
}
|
|
|
|
|
return groups, nil
|
|
|
|
|
}
|