fix(orchestrator): catch WorkflowExecutionAlreadyStartedError to prevent retry loop#1323
fix(orchestrator): catch WorkflowExecutionAlreadyStartedError to prevent retry loop#1323DarinLevesque wants to merge 7 commits into
Conversation
…ak workflow to prevent retry loops
|
@DarinLevesque is attempting to deploy a commit to the Listinai Team on Vercel. A member of the Team first needs to authorize it. |
| `[Ignored] streakWorkflow already started for org: ${integration.organizationId}`, | ||
| ); | ||
| } else { | ||
| // Re-throw any genuine infrastructure errors so Temporal can retry appropriately | ||
| throw error; | ||
| } |
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
There was a problem hiding this comment.
The AI agent makes a great catch regarding the root cause of the streak failing to reset, but it misses the architectural priority.
The Root Cause: The bot is correct that 'TERMINATE_EXISTING' was originally passed as an invalid string literal, causing Temporal to silently default to FAIL_EXISTING. I will push an update to this PR to use the proper WorkflowIdConflictPolicy enum so the streak-reset gamification works as intended.
Why the try/catch MUST stay: The bot suggests fixing the root cause instead of catching the error. However, secondary gamification logic must have an error boundary. If the streak timer fails to start for any reason (e.g., Temporal server race conditions, network blips), it currently crashes postSocial after the payload is published to the social network, triggering an infinite double-posting loop.
The try/catch is a mandatory idempotency boundary to decouple external side-effects from internal metrics. I will push the enum fix to this branch to resolve both issues perfectly.
…enum for streak resets
| (error as Error)?.name === 'WorkflowExecutionAlreadyStartedError' | ||
| ) { | ||
| // Safely catch the idempotency collision so the social post activity succeeds | ||
| console.warn( | ||
| `[Ignored] streakWorkflow already started for org: ${integration.organizationId}`, | ||
| ); | ||
| } else { | ||
| // Re-throw any genuine infrastructure errors so Temporal can retry appropriately | ||
| throw error; | ||
| } |
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
There was a problem hiding this comment.
Excellent catch by the Sentry bot. The original implementation passed a string ('TERMINATE_EXISTING') which caused Temporal to silently default to FAIL, throwing the WorkflowExecutionAlreadyStartedError and triggering the infinite retry loop.
Sentry is correct that WorkflowIdConflictPolicy.USE_EXISTING is the proper business logic for a streak timer (preventing the 24-hour clock from resetting on every post). By using the correct Enum, Temporal natively handles the idempotency collision without throwing an error, rendering the try/catch block unnecessary.
I am pushing an update to remove the try/catch and apply the USE_EXISTING policy. This provides a much cleaner, Temporal-native fix.
…remove redundant error handling
|
Hi @DarinLevesque! Thanks for the PR. Contributions to Postiz are gated behind an application. Please apply at https://contribute.postiz.com/p/postiz and we'll reopen this PR once you're approved. This project also requires a signed Contributor License Agreement. You can sign it now at https://contribute.postiz.com/p/postiz/cla so you're ready as soon as your application is approved. |
|
I'm trying to apply to contribute at the link above: https://contribute.postiz.com/p/postiz But it's not letting me finish the form, it just spins and never loads the page. Is there another way to get added as a contributor? |
Hi @DarinLevesque , |
|
Hi @DarinLevesque! Your application for Postiz is awaiting review. We'll reopen this PR once it's approved. Status: https://contribute.postiz.com/p/postiz This project also requires a signed Contributor License Agreement. You can sign it now at https://contribute.postiz.com/p/postiz/cla so you're ready as soon as your application is approved. |
|
@DarinLevesque's application for Postiz was approved. Reopening this PR. |
|
Contribution-checker quality warning Heuristics that flagged:
If this is a genuine contribution, please add detail to your PR description and tighten the diff scope before reviewers look at it. |
Fixes #1321
What kind of change does this PR introduce?
Fixes a critical bug where the
postSocialactivity enters an infinite retry loop if astreakWorkflowis already active for a given organization.Why was this change needed?
When
postSocialsuccessfully posts to a social network, it attempts to start thestreakWorkflow. If that streak timer is already running (e.g., from a previous post that day), Temporal throws aWorkflowExecutionAlreadyStartedError. Because this error was unhandled, the entire activity fails after the post goes live, causing Temporal to retry the activity and endlessly duplicate the post on the user's social feeds.The Fix:
Wrapped the
streakWorkflowstart call in atry/catchblock withinpost.activity.ts. It now specifically catchesWorkflowExecutionAlreadyStartedError(idempotency collision) and safely ignores it, allowing thepostSocialactivity to return a success signal to Temporal without triggering a double-post loop.Checklist:
Put a "X" in the boxes below to indicate you have followed the checklist;