Skip to content

Remove failing workflow when already started#16301

Merged
charlesBochet merged 1 commit intomainfrom
fix-workflow-run-already-ended
Dec 3, 2025
Merged

Remove failing workflow when already started#16301
charlesBochet merged 1 commit intomainfrom
fix-workflow-run-already-ended

Conversation

@charlesBochet
Copy link
Copy Markdown
Member

@charlesBochet charlesBochet commented Dec 3, 2025

This is a temporary fix that needs to be revisited.

It seems that with the new enqueue system we are enqueuing jobs multiple times due to race condition. We likely want to only consider job that have been created more than x secs ago

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Dec 3, 2025

Greptile Overview

Greptile Summary

Removed a redundant exception-throwing check in startWorkflowRun that was throwing a WorkflowRunException when attempting to start an already-completed or failed workflow run.

  • The check for COMPLETED or FAILED statuses was unnecessary because the subsequent condition (lines 153-158) already handles all non-startable states by returning early
  • This change makes the behavior more graceful: instead of throwing an exception that would fail the calling job, it now silently returns, making the operation idempotent
  • The remaining status check correctly handles all seven workflow states: only NOT_STARTED and ENQUEUED states proceed to transition to RUNNING

Confidence Score: 5/5

  • This PR is safe to merge - it removes redundant code while maintaining correct behavior.
  • The change removes a redundant check that was already handled by the subsequent condition. The functional behavior is preserved (workflows in terminal states cannot be started), but the handling is now more graceful (early return vs exception). The code is simple and the change is minimal.
  • No files require special attention.

Important Files Changed

File Analysis

Filename Score Overview
packages/twenty-server/src/modules/workflow/workflow-runner/workflow-run/workflow-run.workspace-service.ts 5/5 Removed redundant exception-throwing check for already ended workflows. The remaining early-return check adequately handles all non-startable states.

Sequence Diagram

sequenceDiagram
    participant Job as RunWorkflowJob
    participant Service as WorkflowRunWorkspaceService
    participant DB as Database
    
    Job->>Service: startWorkflowRun(workflowRunId, workspaceId)
    Service->>DB: getWorkflowRunOrFail()
    DB-->>Service: workflowRun
    
    alt status is COMPLETED, FAILED, RUNNING, STOPPING, or STOPPED
        Note over Service: Early return (no-op)<br/>Previously threw exception for COMPLETED/FAILED
        Service-->>Job: return (silent)
    else status is ENQUEUED or NOT_STARTED
        Service->>DB: updateWorkflowRun(status: RUNNING)
        Service-->>Job: return
    end
Loading

Copy link
Copy Markdown
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

1 file reviewed, no comments

Edit Code Review Agent Settings | Greptile

@charlesBochet charlesBochet merged commit f1c2ac3 into main Dec 3, 2025
53 of 55 checks passed
@charlesBochet charlesBochet deleted the fix-workflow-run-already-ended branch December 3, 2025 19:49
@twenty-eng-sync
Copy link
Copy Markdown

Hey @charlesBochet! After you've done the QA of your Pull Request, you can mark it as done here. Thank you!

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Dec 3, 2025

🚀 Preview Environment Ready!

Your preview environment is available at: http://bore.pub:15833

This environment will automatically shut down when the PR is closed or after 5 hours.

NotYen pushed a commit to NotYen/twenty-ym that referenced this pull request Dec 9, 2025
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.

1 participant