Preserve operational timeouts when selecting run failures

This commit is contained in:
2026-11-22 09:32:16 +00:00
parent e823baf3af
commit 581229cd1f
3 changed files with 44 additions and 14 deletions

View File

@@ -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) {