From 004177f0fb8318a3110fa2ea8a27b8c6e14ea46b Mon Sep 17 00:00:00 2001 From: Sam Catlow Date: Sat, 24 Oct 2026 11:32:16 +1100 Subject: [PATCH] refactor(daemon): name a taskrun failure's cause in one place --- internal/daemon/daemon.go | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/internal/daemon/daemon.go b/internal/daemon/daemon.go index 1ea1bb8ea..fb7b91e5a 100644 --- a/internal/daemon/daemon.go +++ b/internal/daemon/daemon.go @@ -1899,14 +1899,12 @@ func (d *Daemon) runViaAgent(ctx context.Context, task *workflow.Task, repo conf } reply, err := d.requestTaskRun(ctx, task.ID, data) - if err != nil && stoppingOnly(ctx) { - d.Log.Info("daemon stopping; task left running for the next daemon to re-queue", "task", task.ID) - return - } - if cause := context.Cause(ctx); err != nil && (errors.Is(cause, errContainerExited) || errors.Is(cause, errTaskTimeLimit)) { - err = cause - } if err != nil { + if stoppingOnly(ctx) { + d.Log.Info("daemon stopping; task left running for the next daemon to re-queue", "task", task.ID) + return + } + err = runFailure(ctx, err) d.Log.Error("taskrun request failed", "task", task.ID, "err", err) d.parkRunningTask(ctx, task, "taskrun request failed: "+err.Error(), taskstate.ParkTransient) return @@ -2499,6 +2497,15 @@ func (d *Daemon) markPoll(loop string) { // stops before answering its taskrun request. var errContainerExited = errors.New("agent container exited before the task finished") +// runFailure names why a taskrun request failed: the container's exit or the +// time limit when either cancelled it, else the request's own error. +func runFailure(ctx context.Context, err error) error { + if cause := context.Cause(ctx); errors.Is(cause, errContainerExited) || errors.Is(cause, errTaskTimeLimit) { + return cause + } + return err +} + // exitWatcher is a running agent container, seen only for how it ends. type exitWatcher interface { Exited() <-chan struct{}