Skip to content

[FEAT] Gracefully handle missing ids in bulk_delete_scheduled #3269

@toliv

Description

@toliv

Problem Summary

In our hatchet usage, we rely on scheduled runs + bulk deleting as a means of implementing "dedupe+debounce" workflows. For example, we have a chat product that schedules a Hatchet workflow 15 minutes in the future keyed on a user id. If the user engages with chat again, we'll use bulk_delete_scheduled to delete (cancel) scheduled workflows keyed on that user id via additional_metadata and reschedule for 15 minutes in the future.

When we call bulk_delete_scheduled with this user id in additional_metadata and no matching workflow IDs are found, the engine returns a 400 error with message Provide scheduledWorkflowRunIds or filter.
link

if len(ids) == 0 {
	return gen.WorkflowScheduledBulkDelete400JSONResponse(apierrors.NewAPIErrors("Provide scheduledWorkflowRunIds or filter.")), nil
}

Potential Solutions
There are a few solutions that come to mind, and I'm open to hearing the maintainers' feedback.

  1. At minimum, the error message is a bit misleading. It seems to indicate a malformed request payload (no scheduledWorkflowRunIds or filter) but is actually a runtime condition.
  2. Rather than a 400, this condition could actually result in a 200 response, that is, "You wanted to delete something that doesn't exist, and it doesn't exist, so voila". This could be coupled with a deleted_ids response payload for clients to validate their own behavior.
  3. Perhaps there's a request level flag tolerate_missing_ids which allows a client to explicitly opt-in to this behavior.

It's worth noting that the API technically does offer a pathway here to

  1. List scheduled workflows based on filter
  2. Cancel based on ID if filter match
    This is also reasonable, but could be subject to race conditions (net of other client application-level changes) in a concurrent execution environment where a separate thread creates workflows in between steps 1 and 2.

My personal lean is towards option 2 (don't treat this as a 400 error), although not too strongly held.

Happy to hear the maintainers' thoughts, and should be able to contribute a PR based on feedback.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions