Merge branch 'pipelines/run-20261112-1047-notify-only-on-unexpected-run-failures-64a9'

This commit is contained in:
2026-11-12 11:24:12 +00:00
15 changed files with 184 additions and 21 deletions
+11
View File
@@ -207,6 +207,9 @@ func (r *runner) notifyTerminalStep(id int64, status string) {
if err != nil || len(detail.Steps) == 0 {
return
}
if status == "failed" && detail.FailureKind == "expected" {
return
}
step := detail.Steps[len(detail.Steps)-1]
stepStatus, _, _, terminal := terminalFinish(step.Target, step.Stage, step.Outcome, step.Diagnostic)
if !terminal || stepStatus != status {
@@ -375,6 +378,14 @@ func (r *runner) notifyRun(id int64, name, status string, sequence int, currentS
if event == "" {
return
}
if status == "failed" {
if detail, err := r.store.GetRun(r.ctx, id); err == nil && detail.FailureKind == "expected" {
settings, settingsErr := r.store.NotificationSettings(r.ctx)
if settingsErr != nil || (r.notifyMode(id) != "on" && !settings.RunFinished) {
return
}
}
}
// Failed or interrupted runs always notify; successful runs notify only when
// marked "on" or when the operator opted into every run end (run_finished).
if event == "succeeded" || (event != protocol.NotifyWaiting && event != "failed" && event != "interrupted") {
+12 -8
View File
@@ -158,13 +158,14 @@ func TestTerminalNotificationRecipe(t *testing.T) {
for index, test := range []struct {
name, stage, outcome, status string
executionError, deliveryError bool
notify bool
}{
{"success", "report", "success", "succeeded", false, false},
{"research blocked", "research", "blocked", "failed", false, false},
{"research execution error", "research", "error", "failed", true, false},
{"report blocked", "report", "blocked", "failed", false, false},
{"report execution error", "report", "error", "failed", true, false},
{"delivery error preserves success", "report", "success", "succeeded", false, true},
{"success", "report", "success", "succeeded", false, false, true},
{"research blocked", "research", "blocked", "failed", false, false, false},
{"research execution error", "research", "error", "failed", true, false, true},
{"report blocked", "report", "blocked", "failed", false, false, false},
{"report execution error", "report", "error", "failed", true, false, true},
{"delivery error preserves success", "report", "success", "succeeded", false, true, true},
} {
t.Run(test.name, func(t *testing.T) {
deliveryFailure.Store(test.deliveryError)
@@ -187,13 +188,16 @@ func TestTerminalNotificationRecipe(t *testing.T) {
if err != nil {
t.Fatal(err)
}
if detail.Status != test.status || calls.Load()-before != 1 {
if detail.Status != test.status || (calls.Load()-before == 1) != test.notify {
t.Fatal("wrong verdict or duplicate/missing terminal alert", detail.Status, calls.Load()-before)
}
last := detail.Steps[len(detail.Steps)-1]
if last.Stage != test.stage || len(last.Notifications) != 1 {
if last.Stage != test.stage || (len(last.Notifications) == 1) != test.notify {
t.Fatal("notification not retained on terminal stage", last)
}
if !test.notify {
return
}
for _, step := range detail.Steps[:len(detail.Steps)-1] {
if len(step.Notifications) != 0 {
t.Fatal("intermediate success alerted", step)
+2
View File
@@ -568,6 +568,8 @@ func handleRunEvents(request protocol.Message, events *runEventHub, runs *runner
CompletedSteps: summary.CompletedSteps,
CreatedAt: summary.CreatedAt,
FinishedAt: summary.FinishedAt,
FailureKind: summary.FailureKind,
FailureReason: summary.FailureReason,
CancelRequested: summary.CancelRequested,
CleanupUnconfirmed: summary.CleanupUnconfirmed,
ExportPendingSequence: summary.ExportPendingSequence,
+2
View File
@@ -1496,6 +1496,8 @@ func (r *runner) finishRunState(id int64, name, workspace, status, outcome, diag
CurrentStage: currentStage,
CompletedSteps: completed,
FinishedAt: detail.FinishedAt,
FailureKind: detail.FailureKind,
FailureReason: detail.FailureReason,
SizeBytes: size,
}, true)
r.kickSizes()