Skip to content

Use Status.IsTerminal for every terminal run check - #3970

Merged
yohamta0 merged 1 commit into
dagucloud:mainfrom
RyoKusnadi:refactor/use-status-isterminal
Nov 19, 2026
Merged

yohamta0 merged 1 commit into
dagucloud:mainfrom
RyoKusnadi:refactor/use-status-isterminal

Conversation

@RyoKusnadi

@RyoKusnadi RyoKusnadi commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

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: drop isTerminalRunStatus and call Status.IsTerminal() at its callers (distributed_attempts.go, handler.go, remote_attempt.go). Also replace the five inline !IsActive() && != NotStarted checks in handler.go.
  • internal/cmd/retry.go: retrySourceMayStillBeFinalizing uses IsTerminal().
  • internal/runtime/agent/agent.go: pushStatus picks the terminal push timeout with IsTerminal().
  • internal/service/worker/coordreport/status_pusher.go: the final-delivery retry check uses IsTerminal().
  • internal/service/coordinator/subflow/runner.go and internal/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 vet on the touched packages. internal/runtime/agent reports a lostcancel warning at agent.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/main on the touched packages: 0 issues.

Not run: make test (race), make check, conformance, Windows.

Environment: main @ 395de48, 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) in internal/service/scheduler/restart_scanner.go lists the same five statuses, but it matches event status strings, so switching it means parsing the string first. Left as is.
  • handler.go:2268 keeps latestStatus.Status != ir.NotStarted && !...IsTerminal(). That NotStarted check 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 isTerminalRunStatus helper in internal/service/coordinator and calls Status.IsTerminal() at its call sites.
  • Swaps the inline checks in handler.go, retry.go, agent.go, coordreport/status_pusher.go, subflow/runner.go, and service_dags.go for IsTerminal().
  • 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.

Written for commit 9b5d968. Summary will update on new commits.

View guided diff

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.

Several call sites inferred the terminal set as status != NotStarted && !IsActive(). Use ir.Status.IsTerminal() instead so there is one definition. Follow-up from dagucloud#3676.
@coderabbitai

coderabbitai Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Status checks across command retry, runtime reporting, coordinator, subflow, and frontend code now use Status.IsTerminal() instead of treating statuses outside the active and NotStarted states as terminal.

Changes: Terminal status handling

Layer / File(s) Summary
Coordinator status decisions
internal/service/coordinator/distributed_attempts.go, internal/service/coordinator/handler.go, internal/service/coordinator/remote_attempt.go
Coordinator admission, lease, attempt, reconciliation, and failure checks now use IsTerminal(). The local isTerminalRunStatus helper was removed.
Retry and status reporting
internal/cmd/retry.go, internal/runtime/agent/agent.go, internal/service/worker/coordreport/status_pusher.go
Retry finalization and status reporting now use IsTerminal() to select terminal-run handling.
Subflow and frontend status checks
internal/service/coordinator/subflow/runner.go, internal/service/frontend/api/v1/service_dags.go
Child-workflow cancellation waiting and frontend run-ended detection now use IsTerminal().

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: Minimal · up to 9b5d9

This change replaces duplicated terminal-status checks with a single IsTerminal() definition and should not alter behavior for any defined run status. No concrete merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: replacing duplicated terminal-run checks with Status.IsTerminal(). The changeset matches it: the coordinator, retry, agent, worker, subflow, and frontend call sites no…
Description check Passed The description follows the repository template closely. It has a Summary with the problem and motivation (follow-up to #3676, duplicated 'ended' logic that could drift from IsTerminal()), a Changes l…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: replacing duplicated terminal-run checks with Status.IsTerminal(). The changeset matches it: the coordinator, retry, agent, worker, subflow, and frontend call sites now call IsTerminal() instead of inline status comparisons or the removed isTerminalRunStatus helper. It is specific and concise and needs no more context.

Full details: Description check

Explanation

The description follows the repository template closely. It has a Summary with the problem and motivation (follow-up to #3676, duplicated 'ended' logic that could drift from IsTerminal()), a Changes list by file, a Core change section with the mechanism and file/line snippets, a Testing section with commands run and results, and a Performance section with a no-risk reason. It also includes Out of scope notes. Minor gaps: there is no Related Issues entry (it references #3676 in prose only), no Checklist ticks, and no explicit statement on whether the value-outside-the-enum behavior change matters for compatibility. The description states that behavior difference, so the gap is small.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 87963ea2-9cee-4a5a-876f-dd49a51eb188
Commits

Reviewing files that changed from the base of the PR and between 395de48 and 9b5d968.

Files selected for processing: 8

  • internal/cmd/retry.go
  • internal/runtime/agent/agent.go
  • internal/service/coordinator/distributed_attempts.go
  • internal/service/coordinator/handler.go
  • internal/service/coordinator/remote_attempt.go
  • internal/service/coordinator/subflow/runner.go
  • internal/service/frontend/api/v1/service_dags.go
  • internal/service/worker/coordreport/status_pusher.go

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

@yohamta0 yohamta0 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for following up on this! LGTM.

@yohamta0
yohamta0 merged commit 9bfabc3 into dagucloud:main Nov 19, 2026
13 checks passed
@RyoKusnadi
RyoKusnadi deleted the refactor/use-status-isterminal branch November 19, 2026 13:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants