Use Status.IsTerminal for every terminal run check
Summary
Follow-up from #3676, where @yohamta0 pointed out that a few call sites still work out "the run has ended" on their own as status != NotStarted && !IsActive() instead of using ir.Status.IsTerminal(). If a status is added to ir.Status later, those copies and IsTerminal() would disagree. This switches them all to IsTerminal(), so there is one definition.
Changes
internal/service/coordinator: dropisTerminalRunStatusand callStatus.IsTerminal()at its callers (distributed_attempts.go,handler.go,remote_attempt.go). Also replace the five inline!IsActive() && != NotStartedchecks inhandler.go.internal/cmd/retry.go:retrySourceMayStillBeFinalizingusesIsTerminal().internal/runtime/agent/agent.go:pushStatuspicks the terminal push timeout withIsTerminal().internal/service/worker/coordreport/status_pusher.go: the final-delivery retry check usesIsTerminal().internal/service/coordinator/subflow/runner.goandinternal/service/frontend/api/v1/service_dags.go(runEnded): same.
No user-visible change.
Core change
For every defined status the old expression and IsTerminal() give the same answer: both are true for Failed, Aborted, Succeeded, PartiallySucceeded and Rejected, and false for NotStarted, Running, Queued and Waiting. The only difference is a value outside the enum: the old expression treated it as ended, IsTerminal() treats it as not ended (its default branch).
// internal/cmd/retry.go:706
return status.Status.IsTerminal()
// internal/runtime/agent/agent.go:2060
if status.Status.IsTerminal() {
// internal/service/coordinator/distributed_attempts.go:589
return status.IsTerminal() && !status.IsSuccess()
Testing
No new test. TestStatus_IsTerminal in internal/ir/status_test.go already pins the set, and the call sites keep their current tests.
go build ./...go veton the touched packages.internal/runtime/agentreports alostcancelwarning atagent.go:1224, which is on main too and not touched here.go test -count=1 ./internal/ir/ ./internal/cmd/ ./internal/runtime/agent/ ./internal/service/coordinator/... ./internal/service/frontend/api/v1/ ./internal/service/worker/coordreport/: all pass.golangci-lint run --new-from-rev=upstream/mainon the touched packages: 0 issues.
Not run: make test (race), make check, conformance, Windows.
Environment: main @ 395de48d2, go1.27.4, darwin/arm64.
Performance
No performance risk: each change swaps one in-memory status comparison for another, on the same paths.
Out of scope
runEnded(string)ininternal/service/scheduler/restart_scanner.golists the same five statuses, but it matches event status strings, so switching it means parsing the string first. Left as is.handler.go:2268keepslatestStatus.Status != ir.NotStarted && !...IsTerminal(). ThatNotStartedcheck isn't redundant (NotStarted isn't terminal), and the condition reads as "is active", so I didn't rewrite it.
Summary by cubic
Replaces every hand-rolled terminal-run check (status != ir.NotStarted && !status.IsActive()) with the centralized ir.Status.IsTerminal() so there is a single definition of a terminal status.
Refactors
- Removes the
isTerminalRunStatushelper ininternal/service/coordinatorand callsStatus.IsTerminal()at its call sites. - Swaps the inline checks in
handler.go,retry.go,agent.go,coordreport/status_pusher.go,subflow/runner.go, andservice_dags.goforIsTerminal(). - No behavior change for defined statuses; an out-of-enum value is now treated as not terminal, where the old expression treated it as terminal.
Summary by CodeRabbit
- Bug Fixes
- Run completion is now recognized consistently across workflow coordination and status reporting. This helps prevent non-terminal states from being treated as finished and ensures terminal states receive the appropriate final-status handling, including during cancellation and distributed-run updates.