Move chunk planning into core operation execution
This commit is contained in:
@@ -1,43 +1,10 @@
|
||||
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 {
|
||||
return AssessProducer(ctx, operation, value, fallback)
|
||||
} 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, cacheDiagnostics []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 {
|
||||
|
||||
Reference in New Issue
Block a user