Honor cancellation after recording native evaluation evidence

This commit is contained in:
2026-11-25 17:18:32 +00:00
parent feb83b29b3
commit 6caefe9447
3 changed files with 73 additions and 3 deletions

View File

@@ -16,18 +16,25 @@ usability correction and test-oracle repair are present. No additional required
architecture/documentation gap or inadvertently strengthened requirement was architecture/documentation gap or inadvertently strengthened requirement was
identified. Unrelated outstanding audit findings remain separate work. identified. Unrelated outstanding audit findings remain separate work.
One correctness regression needs remediation before closing this work set. The correctness regression below has been addressed. The review evidence is
retained as the historical explanation of the fix.
## Finding 1 — Recheck Cancellation After Native Evaluation Evidence ## Finding 1 — Recheck Cancellation After Native Evaluation Evidence
**Status:** Resolved. Core rechecks caller cancellation after initial evaluation
and deferred recording, retaining any concurrent capture failure. The focused
`TestNativeProducerOperationCancellationDuringEvaluationCapture` regression
covers both successful recording and recording failure, without cache writes,
correction, fallback, or an accepted result. Both cases failed before the fix.
**Priority:** P2, correctness; a narrow capture-enabled cancellation edge case. **Priority:** P2, correctness; a narrow capture-enabled cancellation edge case.
**Affected stages:** 4, 6, 21, and 24. **Affected stages:** 4, 6, 21, and 24.
**Location:** [executeNative](../../internal/framework/pipeline/operation_native.go), **Location:** [executeNative](../../internal/framework/pipeline/operation_native.go),
particularly its deferred `captureEvaluation` call, the initial particularly its deferred `captureEvaluation` call, the initial
`evaluate(result)` return boundary (currently lines 191–196), and the accepted `evaluate(result)` return boundary (lines 191–196 at the reviewed baseline), and
return (currently lines 277–284). the accepted return (lines 277–284 at that baseline).
### Defect And Evidence ### Defect And Evidence
@@ -102,3 +109,10 @@ cached results where applicable. The additional temporary cancellation regressio
failed as described; it is diagnostic evidence, not a committed test or a code failed as described; it is diagnostic evidence, not a committed test or a code
fix. No production inference or API credentials were used, and no application fix. No production inference or API credentials were used, and no application
code was changed during this review. code was changed during this review.
## Remediation Validation
Both permanent regression cases failed before the fix and pass afterward. The
focused operation/capture/cancellation tests, full offline test suite, vet,
build, and focused race command above passed after the fix. `git diff --check`
also passed. No production inference or API credentials were used.

View File

@@ -191,6 +191,9 @@ func executeNative[T any](ctx context.Context, execution ExecutionContext[T], op
} else { } else {
evaluate(result) evaluate(result)
} }
if canceled := ctx.Err(); canceled != nil {
return empty, errors.Join(canceled, fatal)
}
if fatal != nil { if fatal != nil {
return empty, fatal return empty, fatal
} }

View File

@@ -253,3 +253,56 @@ func TestNativeProducerOperationCancellationStopsDelivery(t *testing.T) {
t.Fatalf("result=%#v err=%v calls=%d", result, err, calls) t.Fatalf("result=%#v err=%v calls=%d", result, err, calls)
} }
} }
func TestNativeProducerOperationCancellationDuringEvaluationCapture(t *testing.T) {
for _, failCapture := range []bool{false, true} {
t.Run(fmt.Sprintf("capture_failure=%t", failCapture), func(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
captureErr := errors.New("evaluation capture failed")
evidence := &nativeEvidence{fail: func(name string) error {
if strings.HasPrefix(name, "interpretations/") {
cancel()
if failCapture {
return captureErr
}
}
return nil
}}
calls, assessments := 0, 0
engine := nativeProducerEngine(t, producerClientFunc(func(context.Context, promptkit.GenerateRequest) (*promptkit.GenerateResponse, error) {
calls++
return &promptkit.GenerateResponse{Content: `{"value":1}`}, nil
}))
result, err := ExecuteOperation(ctx, ExecutionContext[int]{
Engine: engine,
// No cache write can provide an incidental cancellation check.
Controls: contracts.ProducerControls{Mode: contracts.ModePermissive, Cache: contracts.CacheBypass, MaxAdditionalTurns: 1},
Execution: contracts.ExecutionOptions{Capture: evidence},
Assess: func(ctx context.Context, value int) (contracts.CandidateAssessment, error) {
assessments++
return acceptedProducerAssessment(ctx, value)
},
}, func(context.Context) (contracts.PreparedOperation[int], error) {
return contracts.NativeOperation[int]{Initial: nativeProducerInitial(), Interpret: interpretNumberEvaluation,
Correction: func(context.Context, []string) (promptkit.RunRequest, error) {
t.Fatal("cancellation invoked correction")
return promptkit.RunRequest{}, nil
},
Fallback: func(context.Context, contracts.Evaluation[int]) (int, error) {
t.Fatal("cancellation invoked fallback")
return 0, nil
}}, nil
})
if !errors.Is(err, context.Canceled) || result.Outcome.Disposition != "" || result.Evaluation != nil || result.Value != 0 || calls != 1 || assessments != 1 {
t.Fatalf("result=%#v err=%v calls=%d assessments=%d", result, err, calls, assessments)
}
if failCapture {
var captured *contracts.CaptureError
if !errors.Is(err, captureErr) || !errors.As(err, &captured) {
t.Fatalf("capture failure was not retained: %v", err)
}
}
})
}
}