Tell the next stage what failed when an error edge leads onward
A failed visit was recorded on its step only, so a landing gate that sent the run back to implement gave the implementer nothing about which checks failed. The diagnostic (bounded) is now the next stage's previous output and a memory entry.
This commit is contained in:
@@ -2193,6 +2193,10 @@ func (r *runner) runLoop(ctx context.Context, id int64, graph protocol.Graph, na
|
||||
if artifactsDir != "" {
|
||||
state.artifactDirs = append(state.artifactDirs, strconv.Itoa(sequence))
|
||||
}
|
||||
} else if step.Status == "failed" && step.Target != "" &&
|
||||
step.Target != protocol.FailureEnd && step.Target != protocol.SuccessEnd {
|
||||
// The error edge leads to another stage: tell it what failed.
|
||||
state.recordFailure(step)
|
||||
}
|
||||
// Step finished: report its outcome, routing target, diagnostic and the
|
||||
// artifacts recorded for the visit, plus the run's running step count.
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"git.a-wan.net/alan/pipelines/internal/protocol"
|
||||
)
|
||||
|
||||
// A failed stage whose error edge leads to another stage (a landing gate that
|
||||
// sends the run back to implement) must tell that stage what failed.
|
||||
func TestRecordFailureCarriesTheDiagnosticToTheNextStage(t *testing.T) {
|
||||
state := &runState{prompt: "Do the task", visits: map[string]int{"land": 1}}
|
||||
state.recordFailure(protocol.RunStep{
|
||||
Stage: "land",
|
||||
Outcome: "error",
|
||||
Status: "failed",
|
||||
Diagnostic: "delivery check \"tool/test\" failed: exit status 1: FAILED test/a_test.dart: reads the row",
|
||||
})
|
||||
if len(state.turns) != 1 || state.turns[0].Stage != "land" || state.turns[0].Outcome != "error" || state.turns[0].Visit != 1 {
|
||||
t.Fatalf("turns = %+v", state.turns)
|
||||
}
|
||||
input := state.turnInput()
|
||||
for _, want := range []string{"Do the task", "The land stage failed", "FAILED test/a_test.dart: reads the row"} {
|
||||
if !strings.Contains(input, want) {
|
||||
t.Errorf("next input lacks %q:\n%s", want, input)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestRecordFailureBoundsTheDiagnostic(t *testing.T) {
|
||||
state := &runState{visits: map[string]int{}}
|
||||
state.recordFailure(protocol.RunStep{Stage: "land", Outcome: "error", Diagnostic: "first failure\n" + strings.Repeat("x", 3*maxFailureDetail)})
|
||||
output := state.turns[0].Output
|
||||
if len(output) > maxFailureDetail+400 {
|
||||
t.Fatalf("output is %d bytes", len(output))
|
||||
}
|
||||
if !strings.Contains(output, "first failure") || !strings.Contains(output, "[truncated]") {
|
||||
t.Fatalf("output = %.200s", output)
|
||||
}
|
||||
}
|
||||
@@ -146,6 +146,31 @@ func (s *runState) recordTurn(step protocol.RunStep, publicFiles []string) {
|
||||
s.lastOutput = output
|
||||
}
|
||||
|
||||
// maxFailureDetail bounds the failure text carried to the next stage. A
|
||||
// delivery check's quiet output lists its failures first, so the head is kept.
|
||||
const maxFailureDetail = 6000
|
||||
|
||||
// recordFailure makes a failed visit that routes onward (an error edge to
|
||||
// another stage) visible to that stage. Without it the diagnostic exists only
|
||||
// on the stored step: a landing gate that fails its checks would send the run
|
||||
// back to the implementer with nothing saying which checks failed.
|
||||
func (s *runState) recordFailure(step protocol.RunStep) {
|
||||
detail := strings.TrimSpace(step.Diagnostic)
|
||||
if len(detail) > maxFailureDetail {
|
||||
detail = strings.ToValidUTF8(detail[:maxFailureDetail], "") + "\n[truncated]"
|
||||
}
|
||||
output := "# outcome\n\nerror\n\n# handoff\n\nThe " + step.Stage +
|
||||
" stage failed and sent the run back. Fix the cause below; keep the work already done.\n\n~~~\n" +
|
||||
detail + "\n~~~\n"
|
||||
s.turns = append(s.turns, turn.MemoryEntry{
|
||||
Stage: step.Stage,
|
||||
Visit: s.visits[step.Stage],
|
||||
Outcome: step.Outcome,
|
||||
Output: output,
|
||||
})
|
||||
s.lastOutput = output
|
||||
}
|
||||
|
||||
// publicFileSet lists regular files below the run's public directory as paths
|
||||
// relative to the run directory, retaining the "public/" prefix.
|
||||
func publicFileSet(runRoot string) map[string]bool {
|
||||
|
||||
Reference in New Issue
Block a user