Skip to content

Add enforceUniqueInstanceId option when scheduling workflows #1801

Description

@javier-aliaga

Expected Behavior

The Java workflow client can require an instance ID to be unique when scheduling a workflow. When enabled, scheduling a workflow whose instance ID already exists fails with a gRPC ALREADY_EXISTS error, whether the existing instance is running or completed. The caller then decides what to do instead of the runtime silently restarting a completed instance.

Actual Behavior

The Java SDK has no way to request this. Scheduling a workflow with an instance ID that belongs to a completed instance restarts that instance. The runtime already supports the flag: the enforceUniqueInstanceId field on CreateInstanceRequest was merged in durabletask-protobuf #55, durabletask-go #116, and dapr #10379, and is released in durabletask-go v0.14.0. The Java SDK never sets it.

Steps to Reproduce the Problem

  1. Schedule a workflow with a fixed instance ID and wait for it to complete.
  2. Schedule a workflow again with the same instance ID.
  3. The completed instance is restarted. There is no option on NewWorkflowOptions to reject the duplicate instead.

Proposed Implementation

The proto field is already available at build time — durabletask.proto.baseurl in pom.xml tracks dapr/durabletask-protobuf/main, which contains the field. Four layers need the option plumbed through:

  1. durabletask-client/.../NewOrchestrationInstanceOptions.java — add an enforceUniqueInstanceId field with setter and getter, alongside the existing startTime/appID fields.
  2. durabletask-client/.../DurableTaskGrpcClient.java (around line 204) — call builder.setEnforceUniqueInstanceId(...) on the CreateInstanceRequest.Builder, mirroring how setScheduledStartTimestamp is set.
  3. sdk-workflows/.../client/NewWorkflowOptions.java — add the same enforceUniqueInstanceId field with setter and getter.
  4. sdk-workflows/.../client/DaprWorkflowClient.java fromNewWorkflowOptions() (around line 517) — map the option onto NewOrchestrationInstanceOptions.

The error surfacing is already handled: DaprWorkflowClient.mapAlreadyExists() maps the gRPC ALREADY_EXISTS status to a typed exception.

Scope also includes unit tests for the option mapping and the request builder. An example update is optional.

Requires a Dapr runtime that includes the feature (built with durabletask-go v0.14.0 or later).

Release Note

RELEASE NOTE: ADD enforceUniqueInstanceId option to fail workflow scheduling when the instance ID already exists.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions