Derive a plain-language verdict for every completed stage visit
Each completed step now exposes a verdict: the chosen option (outcome -> target), a bounded one-line reason with model/fallback/absent provenance, and the recorded artifacts the reason refers to. The store persists only the model-generated line in a new step_verdicts table and derives the fallback at read time (no backfill); the server generates the line once at completion, best-effort; the TUI renders it in the stage progress summary. The packaged debugging reference documents it.
This commit is contained in:
@@ -315,3 +315,110 @@ func TestRunnerRoutingPersistenceAndIdempotency(t *testing.T) {
|
||||
t.Fatalf("cycle not bounded: %+v", detail)
|
||||
}
|
||||
}
|
||||
|
||||
// TestStepVerdictGeneratedOnceAtCompletion proves the wired seam runs exactly
|
||||
// once per completed stage visit, from the step's own output, and the generated
|
||||
// line is stored with model provenance.
|
||||
func TestStepVerdictGeneratedOnceAtCompletion(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
store, err := pipeline.Open(filepath.Join(t.TempDir(), "verdict.db"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer store.Close()
|
||||
if _, err := store.Submit(ctx, "verdict", pipeline.Template([]string{"one"}, true)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
items, _ := store.List(ctx)
|
||||
r, err := newRunner(ctx, store)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
r.execute = func(context.Context, stage.Definition, stage.Values) (stage.Result, error) {
|
||||
return stage.Result{Outcome: "success", Output: stage.Values{"summary": "ran the checks"}}, nil
|
||||
}
|
||||
calls := 0
|
||||
r.verdict = func(_ context.Context, output map[string]any) string {
|
||||
calls++
|
||||
if output["summary"] != "ran the checks" {
|
||||
t.Errorf("verdict seam got output %v", output)
|
||||
}
|
||||
return "chosen because every check passed"
|
||||
}
|
||||
run, err := r.start(protocol.Message{PipelineID: items[0].ID, Version: 1, RequestKey: "verdict-once", Workspace: t.TempDir(), Input: map[string]any{"prompt": "task"}})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
r.wg.Wait()
|
||||
if calls != 1 {
|
||||
t.Fatalf("verdict seam ran %d times, want exactly once for one step", calls)
|
||||
}
|
||||
detail, err := store.GetRun(ctx, run.ID)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
verdict := detail.Steps[0].Verdict
|
||||
if verdict == nil || verdict.Reason != "chosen because every check passed" || verdict.ReasonSource != protocol.VerdictReasonModel {
|
||||
t.Fatalf("stored verdict = %+v", verdict)
|
||||
}
|
||||
}
|
||||
|
||||
// TestStepVerdictFailureNeverFailsStage proves a best-effort failure (the
|
||||
// NoSummary sentinel) still lets the run reach its normal terminal status, with
|
||||
// the verdict derived at read time from the step's output.
|
||||
func TestStepVerdictFailureNeverFailsStage(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
store, err := pipeline.Open(filepath.Join(t.TempDir(), "verdict-fail.db"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer store.Close()
|
||||
if _, err := store.Submit(ctx, "verdict-fail", pipeline.Template([]string{"one"}, true)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
items, _ := store.List(ctx)
|
||||
r, err := newRunner(ctx, store)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
r.execute = func(context.Context, stage.Definition, stage.Values) (stage.Result, error) {
|
||||
return stage.Result{Outcome: "success", Output: stage.Values{"summary": "ran the checks"}}, nil
|
||||
}
|
||||
r.verdict = func(context.Context, map[string]any) string { return summarise.NoSummary }
|
||||
run, err := r.start(protocol.Message{PipelineID: items[0].ID, Version: 1, RequestKey: "verdict-fail", Workspace: t.TempDir(), Input: map[string]any{"prompt": "task"}})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
r.wg.Wait()
|
||||
detail, err := store.GetRun(ctx, run.ID)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if detail.Status != "succeeded" {
|
||||
t.Fatalf("summariser failure changed the run status: %+v", detail)
|
||||
}
|
||||
verdict := detail.Steps[0].Verdict
|
||||
if verdict == nil || verdict.Reason != "ran the checks" || verdict.ReasonSource != protocol.VerdictReasonFallback {
|
||||
t.Fatalf("read-time verdict after a summariser failure = %+v", verdict)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHandlerWiresStepVerdictGenerator(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
store, err := pipeline.Open(filepath.Join(t.TempDir(), "verdict-wire.db"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer store.Close()
|
||||
configured := HandlerWithOptions(ctx, Options{StepVerdicts: summarise.GenerateVerdictReason}, store).(*runHandler)
|
||||
bare := HandlerWithOptions(ctx, Options{}, store).(*runHandler)
|
||||
defer func() { cancel(); WaitRuns(configured); WaitRuns(bare) }()
|
||||
if configured.runner.verdict == nil {
|
||||
t.Fatal("configured StepVerdicts was not applied to the runner")
|
||||
}
|
||||
if bare.runner.verdict != nil {
|
||||
t.Fatal("unconfigured StepVerdicts must keep deterministic read-time derivation")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user