From 460d368d8e44075e1f81258428f64720f271dca4 Mon Sep 17 00:00:00 2001 From: Eric Rakestraw Date: Sat, 28 Nov 2026 16:15:57 +0000 Subject: [PATCH] Retain cancellation at the final readiness handoff --- docs/roadmap/remediation.md | 2 ++ internal/cli/pipeline_preflight.go | 3 +++ internal/preflight/smoke.go | 8 ++++++-- internal/preflight/smoke_test.go | 14 ++++++++++++++ 4 files changed, 25 insertions(+), 2 deletions(-) diff --git a/docs/roadmap/remediation.md b/docs/roadmap/remediation.md index 993f4b3f..95c1fd75 100644 --- a/docs/roadmap/remediation.md +++ b/docs/roadmap/remediation.md @@ -36,6 +36,8 @@ guarantees was found. Keep the accepted scope unchanged while remediating. readiness now follows completed native checks independently of recording failure. Focused smoke/preflight tests pass, including final/combined failures and stopping before an unchecked profile. +Cancellation during the final observation is also retained at both the smoke +boundary and the command's readiness handoff, without altering the native verdict. **Priority:** P2 — error handling and separation of responsibilities. diff --git a/internal/cli/pipeline_preflight.go b/internal/cli/pipeline_preflight.go index b4099692..faa4beb8 100644 --- a/internal/cli/pipeline_preflight.go +++ b/internal/cli/pipeline_preflight.go @@ -204,6 +204,9 @@ func executePreflight(invocation commandkit.Invocation, input pipelineRunInput, } } // Recording failure is independent of a completed diagnostic assessment. + if ctxErr := ctx.Err(); ctxErr != nil && !errors.Is(err, ctxErr) { + err = errors.Join(err, ctxErr) + } report.Ready = !failedCheck && len(observations) == 2*len(targets.Access)+len(targets.Profiles) && ctx.Err() == nil if err != nil { if !failedCheck && !report.Ready { diff --git a/internal/preflight/smoke.go b/internal/preflight/smoke.go index ec97fcd7..980bdbc5 100644 --- a/internal/preflight/smoke.go +++ b/internal/preflight/smoke.go @@ -39,10 +39,14 @@ func RunSmokeChecksObserved(ctx context.Context, engine *promptkit.Engine, targe observation := SmokeObservation{Kind: kind, ProfileID: profile, BackendID: backend, Bindings: bindings, Report: report} observation.Applicable, observation.Err = evaluateSmoke(kind, report, err) observations = append(observations, observation) + operationErr := observation.Err if observe != nil { - return errors.Join(observation.Err, observe(observation)) + operationErr = errors.Join(operationErr, observe(observation)) } - return observation.Err + if ctxErr := ctx.Err(); ctxErr != nil && !errors.Is(operationErr, ctxErr) { + operationErr = errors.Join(operationErr, ctxErr) + } + return operationErr } for _, target := range targets.Access { for _, kind := range []promptkit.SmokeTestKind{promptkit.SmokeTestReachability, promptkit.SmokeTestAuthentication} { diff --git a/internal/preflight/smoke_test.go b/internal/preflight/smoke_test.go index 58b0b76a..a952213c 100644 --- a/internal/preflight/smoke_test.go +++ b/internal/preflight/smoke_test.go @@ -136,3 +136,17 @@ func TestSmokeRetainsTerminalObserverAndDiagnosticErrors(t *testing.T) { } } } + +func TestSmokeRetainsCancellationDuringTerminalObservation(t *testing.T) { + input := configkit.Input{Destination: configkit.Keys("promptkit"), Source: configkit.Mapping("smoke", map[string]any{"profiles": []any{map[string]any{"id": "profile", "endpoint": "http://example.invalid/v1", "model": "fixture"}}})} + engine, err := promptkit.NewEngine(promptkit.Config{Sources: promptkit.ConfigurationSources{Main: &input}}, promptkit.WithBundledOpenRouter(false), promptkit.WithLLMClient(smokeResultClient{})) + if err != nil { + t.Fatal(err) + } + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + observations, err := RunSmokeChecksObserved(ctx, engine, Targets{Profiles: []ProfileTarget{{ID: "profile"}}}, nil, nil, func(SmokeObservation) error { cancel(); return nil }) + if !errors.Is(err, context.Canceled) || len(observations) != 1 || observations[0].Err != nil { + t.Fatalf("observations=%+v error=%v", observations, err) + } +}