Preserve capture failures when a run is canceled
This commit is contained in:
@@ -6,7 +6,8 @@ Reviewed all 36 stages of [the implementation plan](implementation.md) against
|
|||||||
`c5d8697d9f645a7b3b9041769da02704bd495b7a`, including the changes since planning
|
`c5d8697d9f645a7b3b9041769da02704bd495b7a`, including the changes since planning
|
||||||
commit `cecd68f`, their tests, the accepted
|
commit `cecd68f`, their tests, the accepted
|
||||||
[feature roadmap](audit-remediation.md), and current canonical
|
[feature roadmap](audit-remediation.md), and current canonical
|
||||||
architecture/internal documentation. This is a review, not implementation.
|
architecture/internal documentation. The review below records that snapshot;
|
||||||
|
the remediation status records the subsequent correction.
|
||||||
|
|
||||||
The targeted architecture is substantially in place. Core retains typed operation
|
The targeted architecture is substantially in place. Core retains typed operation
|
||||||
execution; a separate capture package serves operations and one-shot validators.
|
execution; a separate capture package serves operations and one-shot validators.
|
||||||
@@ -17,14 +18,19 @@ layout, target selection, and pure copying. Families own scene rules, duplicate
|
|||||||
eligibility/identity, and prepared ordering keys. The executable owns cooperative
|
eligibility/identity, and prepared ordering keys. The executable owns cooperative
|
||||||
signals; embedded callers retain context ownership.
|
signals; embedded callers retain context ownership.
|
||||||
|
|
||||||
One required failure-cause retention gap remains. No other required correctness,
|
The one required failure-cause retention gap is now resolved. No other required
|
||||||
code-quality, architectural/documentation gap, or inadvertently strengthened
|
correctness, code-quality, architectural/documentation gap, or inadvertently
|
||||||
requirement was substantiated in the inspected changes. The previously resolved
|
strengthened requirement was substantiated in the inspected changes. The previously
|
||||||
standalone native-executor cancellation finding remains fixed; the issue below
|
resolved standalone native-executor cancellation finding remains fixed; the issue
|
||||||
is at the enclosing runner's error-selection boundary.
|
below is at the enclosing runner's error-selection boundary.
|
||||||
|
|
||||||
## Finding 1 — Retain Drained Capture Failures Alongside Caller Cancellation
|
## Finding 1 — Retain Drained Capture Failures Alongside Caller Cancellation
|
||||||
|
|
||||||
|
**Status:** Resolved. The runner now joins caller cancellation with capture-bearing
|
||||||
|
errors from drained jobs, preserving their scope and typed causes in canonical
|
||||||
|
stage/lane/chunk order. Unrelated sibling errors remain suppressed, and ordinary
|
||||||
|
uncanceled error selection is unchanged.
|
||||||
|
|
||||||
**Priority:** P2, error integrity; requires concurrent cancellation and a capture
|
**Priority:** P2, error integrity; requires concurrent cancellation and a capture
|
||||||
failure, not an ordinary successful run.
|
failure, not an ordinary successful run.
|
||||||
|
|
||||||
@@ -99,6 +105,23 @@ call. Ordinary cancellation still returns cancellation; uncanceled failures reta
|
|||||||
their established canonical selection. Available diagnostics and capture remain
|
their established canonical selection. Available diagnostics and capture remain
|
||||||
under the existing lifecycle.
|
under the existing lifecycle.
|
||||||
|
|
||||||
|
### Implemented Remediation
|
||||||
|
|
||||||
|
`selectRunError` retains drained job errors containing `contracts.CaptureError`
|
||||||
|
when caller cancellation takes precedence. It returns the caller context error
|
||||||
|
first in the joined chain, keeping every capture cause from those jobs without
|
||||||
|
changing retry, fallback, finalization, or publication behavior.
|
||||||
|
|
||||||
|
Permanent runner regressions cancel the caller and fail outcome capture at each
|
||||||
|
of extraction, merge, and normalization. They verify cancellation, capture cause
|
||||||
|
and type, one outcome write, no deliverables, and no fallback. Selection coverage
|
||||||
|
also checks multiple capture failures, canonical ordering, and suppression of an
|
||||||
|
unrelated ordinary sibling failure.
|
||||||
|
|
||||||
|
Post-remediation checks passed: the focused cancellation/capture/finalization
|
||||||
|
and error-selection tests (ten consecutive runs), `go test ./...`, `go vet ./...`,
|
||||||
|
`go build ./cmd/notarius`, and the five-package race command below.
|
||||||
|
|
||||||
## Stage-By-Stage Review Coverage
|
## Stage-By-Stage Review Coverage
|
||||||
|
|
||||||
| Stages | Evidence inspected / result |
|
| Stages | Evidence inspected / result |
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"gitea.maximumdirect.net/eric/notarius/internal/framework/contracts"
|
||||||
"go.maximumdirect.net/promptkit"
|
"go.maximumdirect.net/promptkit"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -23,3 +24,27 @@ func TestRunErrorSelectionPreservesOperationalDeadlines(t *testing.T) {
|
|||||||
t.Fatal(got)
|
t.Fatal(got)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestRunErrorSelectionRetainsOnlyCaptureBearingJobsOnCancellation(t *testing.T) {
|
||||||
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
|
cancel()
|
||||||
|
firstCause, extraCause, laterCause := errors.New("first capture"), errors.New("extra capture"), errors.New("later capture")
|
||||||
|
first := &contracts.CaptureError{Cause: firstCause}
|
||||||
|
later := &contracts.CaptureError{Cause: laterCause}
|
||||||
|
ordinary := errors.New("ordinary sibling failure")
|
||||||
|
got := selectRunError(ctx, []orderedRunError{
|
||||||
|
{stage: 2, lane: 0, err: later},
|
||||||
|
{stage: 0, lane: -1, err: ordinary},
|
||||||
|
{stage: 0, lane: 0, err: errors.Join(first, &contracts.CaptureError{Cause: extraCause})},
|
||||||
|
{stage: 0, lane: -2, err: context.Canceled},
|
||||||
|
})
|
||||||
|
for _, cause := range []error{context.Canceled, firstCause, extraCause, laterCause} {
|
||||||
|
if !errors.Is(got, cause) {
|
||||||
|
t.Fatalf("selected error %v lost cause %v", got, cause)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var captured *contracts.CaptureError
|
||||||
|
if !errors.As(got, &captured) || captured != first || errors.Is(got, ordinary) {
|
||||||
|
t.Fatalf("selected error %v changed canonical capture order or retained ordinary siblings", got)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,39 @@
|
|||||||
|
package pipeline
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"gitea.maximumdirect.net/eric/notarius/internal/framework/contracts"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestRunnerCancellationRetainsDrainedCaptureFailure(t *testing.T) {
|
||||||
|
for _, stage := range []string{"extract", "merge", "normalize"} {
|
||||||
|
t.Run(stage, func(t *testing.T) {
|
||||||
|
prepared := preparedConcurrentPipeline(t, 1)
|
||||||
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
|
defer cancel()
|
||||||
|
cause := errors.New("operation outcome capture failed")
|
||||||
|
writes := 0
|
||||||
|
writer := &nativeEvidence{fail: func(name string) error {
|
||||||
|
if strings.Contains(name, "/"+stage+"/") && strings.HasSuffix(name, "/outcome.json") {
|
||||||
|
writes++
|
||||||
|
cancel()
|
||||||
|
return cause
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}}
|
||||||
|
output, err := New().Run(ctx, RunInput{Prepared: prepared, RawInput: []byte("input"), Workers: 1,
|
||||||
|
Execution: contracts.ExecutionOptions{Capture: writer}})
|
||||||
|
var captured *contracts.CaptureError
|
||||||
|
if !errors.Is(err, context.Canceled) || !errors.Is(err, cause) || !errors.As(err, &captured) {
|
||||||
|
t.Fatalf("Run() error = %v, want cancellation and capture cause/type", err)
|
||||||
|
}
|
||||||
|
if writes != 1 || len(output.OutputFiles) != 0 || output.FallbackCount != 0 {
|
||||||
|
t.Fatalf("writes=%d files=%d fallbacks=%d", writes, len(output.OutputFiles), output.FallbackCount)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"path"
|
"path"
|
||||||
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
@@ -401,8 +402,28 @@ func classifyLaneError(lane, sentinel int, err error) orderedRunError {
|
|||||||
|
|
||||||
func selectRunError(parent context.Context, values []orderedRunError) error {
|
func selectRunError(parent context.Context, values []orderedRunError) error {
|
||||||
if err := parent.Err(); err != nil {
|
if err := parent.Err(); err != nil {
|
||||||
|
// Cancellation stays primary, but drained jobs can also have failed
|
||||||
|
// required capture. Retain those scoped errors, not ordinary siblings.
|
||||||
|
var captureFailures []orderedRunError
|
||||||
|
for _, value := range values {
|
||||||
|
var captured *contracts.CaptureError
|
||||||
|
if errors.As(value.err, &captured) {
|
||||||
|
captureFailures = append(captureFailures, value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(captureFailures) == 0 {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
sort.SliceStable(captureFailures, func(i, j int) bool {
|
||||||
|
left, right := captureFailures[i], captureFailures[j]
|
||||||
|
return left.stage < right.stage || left.stage == right.stage && (left.lane < right.lane || left.lane == right.lane && left.chunk < right.chunk)
|
||||||
|
})
|
||||||
|
causes := []error{err}
|
||||||
|
for _, failure := range captureFailures {
|
||||||
|
causes = append(causes, failure.err)
|
||||||
|
}
|
||||||
|
return errors.Join(causes...)
|
||||||
|
}
|
||||||
if len(values) == 0 {
|
if len(values) == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user