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

@@ -25,6 +25,10 @@ execution abstraction. This document records findings, not implemented fixes.
## Finding 1: Retain Genuine Native Timeouts During Concurrent Error Selection
**Status: Complete.** Operational deadlines participate in linear minimum
selection; sibling cancellation noise and authoritative caller cancellation are
preserved. Pipeline tests and race checks pass.
Priority: P2. Relevant stages: 10, 25, 37, and 46.
### Evidence And Impact

View 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)
}
}

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