fix: ignore duplicate action results during execution updates

This commit is contained in:
yashsinghcodes
2026-05-01 13:12:48 +05:30
parent c6ed733151
commit fb4c1edb7b
+35
View File
@@ -593,6 +593,15 @@ func runWorkflowExecutionTransaction(ctx context.Context, attempts int64, workfl
return return
} }
if hasEquivalentActionResult(*workflowExecution, actionResult) {
log.Printf("[DEBUG][%s] Ignoring duplicate action result for action %s with status %s", workflowExecutionId, actionResult.Action.ID, actionResult.Status)
if resp != nil {
resp.WriteHeader(http.StatusOK)
resp.Write([]byte(`{"success": true, "reason": "duplicate result ignored"}`))
}
return
}
workflowExecution, dbSave, err := shuffle.ParsedExecutionResult(ctx, *workflowExecution, actionResult, false, 0) workflowExecution, dbSave, err := shuffle.ParsedExecutionResult(ctx, *workflowExecution, actionResult, false, 0)
if err != nil { if err != nil {
b, suberr := json.Marshal(actionResult) b, suberr := json.Marshal(actionResult)
@@ -628,6 +637,32 @@ func runWorkflowExecutionTransaction(ctx context.Context, attempts int64, workfl
} }
func hasEquivalentActionResult(workflowExecution shuffle.WorkflowExecution, incoming shuffle.ActionResult) bool {
for _, existing := range workflowExecution.Results {
if existing.Action.ID != incoming.Action.ID {
continue
}
if existing.Status != incoming.Status {
continue
}
if existing.CompletedAt > 0 && incoming.CompletedAt > 0 && existing.CompletedAt == incoming.CompletedAt {
return true
}
if existing.StartedAt > 0 && incoming.StartedAt > 0 && existing.StartedAt == incoming.StartedAt {
return true
}
if len(existing.Result) > 0 && existing.Result == incoming.Result {
return true
}
}
return false
}
func JSONCheck(str string) bool { func JSONCheck(str string) bool {
var jsonStr interface{} var jsonStr interface{}
return json.Unmarshal([]byte(str), &jsonStr) == nil return json.Unmarshal([]byte(str), &jsonStr) == nil