Preserve operational timeouts when selecting run failures
This commit is contained in:
25
internal/framework/pipeline/error_selection_test.go
Normal file
25
internal/framework/pipeline/error_selection_test.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package pipeline
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"go.maximumdirect.net/promptkit"
|
||||
)
|
||||
|
||||
func TestRunErrorSelectionPreservesOperationalDeadlines(t *testing.T) {
|
||||
for _, first := range []error{context.DeadlineExceeded, fmt.Errorf("%w: %w", promptkit.ErrOperationTimeout, context.DeadlineExceeded)} {
|
||||
later := errors.New("later failure")
|
||||
got := selectRunError(context.Background(), []orderedRunError{{lane: 1, err: later}, {lane: 0, err: first}, {lane: -1, err: context.Canceled}})
|
||||
if got != first {
|
||||
t.Fatalf("selected %v, want %v", got, first)
|
||||
}
|
||||
}
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
cancel()
|
||||
if got := selectRunError(ctx, []orderedRunError{{err: errors.New("operation")}}); got != context.Canceled {
|
||||
t.Fatal(got)
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,8 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"go.maximumdirect.net/promptkit"
|
||||
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/core/fileio"
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/core/source"
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/framework/contracts"
|
||||
@@ -404,28 +406,27 @@ func selectRunError(parent context.Context, values []orderedRunError) error {
|
||||
}
|
||||
hasReal := false
|
||||
for _, value := range values {
|
||||
if !errors.Is(value.err, context.Canceled) && !errors.Is(value.err, context.DeadlineExceeded) {
|
||||
if !isSiblingCancellation(value.err) {
|
||||
hasReal = true
|
||||
break
|
||||
}
|
||||
}
|
||||
filtered := values[:0]
|
||||
var best *orderedRunError
|
||||
for _, value := range values {
|
||||
if hasReal && (errors.Is(value.err, context.Canceled) || errors.Is(value.err, context.DeadlineExceeded)) {
|
||||
if hasReal && isSiblingCancellation(value.err) {
|
||||
continue
|
||||
}
|
||||
filtered = append(filtered, value)
|
||||
if best == nil || value.stage < best.stage || value.stage == best.stage && (value.lane < best.lane || value.lane == best.lane && value.chunk < best.chunk) {
|
||||
best = &value
|
||||
}
|
||||
}
|
||||
sort.SliceStable(filtered, func(i, j int) bool {
|
||||
if filtered[i].stage != filtered[j].stage {
|
||||
return filtered[i].stage < filtered[j].stage
|
||||
}
|
||||
if filtered[i].lane != filtered[j].lane {
|
||||
return filtered[i].lane < filtered[j].lane
|
||||
}
|
||||
return filtered[i].chunk < filtered[j].chunk
|
||||
})
|
||||
return filtered[0].err
|
||||
return best.err
|
||||
}
|
||||
|
||||
// The runner cancels siblings, but does not give them a separate deadline.
|
||||
// Deadline-shaped provider/native failures remain real when the caller is active.
|
||||
func isSiblingCancellation(err error) bool {
|
||||
return errors.Is(err, context.Canceled) && !errors.Is(err, promptkit.ErrOperationTimeout)
|
||||
}
|
||||
|
||||
func mergeLaneOutput(dst *RunOutput, src RunOutput) {
|
||||
|
||||
Reference in New Issue
Block a user