From 6caefe9447b021a82c52539de5b30be6e6bb5792 Mon Sep 17 00:00:00 2001 From: Eric Rakestraw Date: Wed, 25 Nov 2026 17:18:32 +0000 Subject: [PATCH] Honor cancellation after recording native evaluation evidence --- docs/roadmap/remediation.md | 20 +++++-- .../framework/pipeline/operation_native.go | 3 ++ .../pipeline/operation_native_test.go | 53 +++++++++++++++++++ 3 files changed, 73 insertions(+), 3 deletions(-) diff --git a/docs/roadmap/remediation.md b/docs/roadmap/remediation.md index 90a876db..8c4a097c 100644 --- a/docs/roadmap/remediation.md +++ b/docs/roadmap/remediation.md @@ -16,18 +16,25 @@ usability correction and test-oracle repair are present. No additional required architecture/documentation gap or inadvertently strengthened requirement was 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 +**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. **Affected stages:** 4, 6, 21, and 24. **Location:** [executeNative](../../internal/framework/pipeline/operation_native.go), particularly its deferred `captureEvaluation` call, the initial -`evaluate(result)` return boundary (currently lines 191–196), and the accepted -return (currently lines 277–284). +`evaluate(result)` return boundary (lines 191–196 at the reviewed baseline), and +the accepted return (lines 277–284 at that baseline). ### 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 fix. No production inference or API credentials were used, and no application 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. diff --git a/internal/framework/pipeline/operation_native.go b/internal/framework/pipeline/operation_native.go index 87971218..146edcfb 100644 --- a/internal/framework/pipeline/operation_native.go +++ b/internal/framework/pipeline/operation_native.go @@ -191,6 +191,9 @@ func executeNative[T any](ctx context.Context, execution ExecutionContext[T], op } else { evaluate(result) } + if canceled := ctx.Err(); canceled != nil { + return empty, errors.Join(canceled, fatal) + } if fatal != nil { return empty, fatal } diff --git a/internal/framework/pipeline/operation_native_test.go b/internal/framework/pipeline/operation_native_test.go index 900192d3..83d78aac 100644 --- a/internal/framework/pipeline/operation_native_test.go +++ b/internal/framework/pipeline/operation_native_test.go @@ -253,3 +253,56 @@ func TestNativeProducerOperationCancellationStopsDelivery(t *testing.T) { 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) + } + } + }) + } +}