@@ -63,6 +63,7 @@ class OrchestrationStatus(Enum):
6363 RUNNING = pb .ORCHESTRATION_STATUS_RUNNING
6464 COMPLETED = pb .ORCHESTRATION_STATUS_COMPLETED
6565 FAILED = pb .ORCHESTRATION_STATUS_FAILED
66+ CANCELED = pb .ORCHESTRATION_STATUS_CANCELED
6667 TERMINATED = pb .ORCHESTRATION_STATUS_TERMINATED
6768 CONTINUED_AS_NEW = pb .ORCHESTRATION_STATUS_CONTINUED_AS_NEW
6869 PENDING = pb .ORCHESTRATION_STATUS_PENDING
@@ -72,6 +73,23 @@ def __str__(self) -> str:
7273 return cast (str , helpers .get_orchestration_status_str (self .value ))
7374
7475
76+ @dataclass
77+ class OrchestrationIdReusePolicy :
78+ """Control duplicate instance IDs when scheduling an orchestration.
79+
80+ ``dedupe_statuses`` lists existing-instance statuses that must not be
81+ replaced. Other stable statuses permit replacement if supported by the
82+ backend. ``None`` preserves backend defaults; an empty sequence permits
83+ replacement in every stable status. ``CONTINUED_AS_NEW`` is a transition,
84+ not a configurable instance status.
85+
86+ This policy does not provide an atomic no-op/ignore action. Replacement
87+ behavior and support are determined by the backend.
88+ """
89+
90+ dedupe_statuses : Sequence [OrchestrationStatus ] | None = None
91+
92+
7593@dataclass
7694class OrchestrationState :
7795 instance_id : str
@@ -631,13 +649,18 @@ def schedule_new_orchestration(self, orchestrator: task.Orchestrator[TInput, TOu
631649 input : TInput | None = None ,
632650 instance_id : str | None = None ,
633651 start_at : datetime | None = None ,
634- reuse_id_policy : pb .OrchestrationIdReusePolicy | None = None ,
652+ reuse_id_policy : OrchestrationIdReusePolicy | pb .OrchestrationIdReusePolicy | None = None ,
635653 tags : dict [str , str ] | None = None ,
636654 version : str | None = None ) -> str :
637655 """Schedule a new orchestration instance for execution.
638656
639657 If instance_id is not specified, a random UUID hex string is generated upfront
640658 and shared across both the OpenTelemetry producer span and the CreateInstanceRequest.
659+
660+ ``reuse_id_policy`` controls which existing-instance statuses reject
661+ duplicate IDs. Omission preserves backend defaults. Existing protobuf
662+ policies remain supported and retain their replaceable-status semantics.
663+ Invalid public policy statuses raise ``ValueError`` before sending the request.
641664 """
642665 name = orchestrator if isinstance (orchestrator , str ) else task .get_name (orchestrator )
643666 resolved_instance_id = instance_id if instance_id else uuid .uuid4 ().hex
@@ -1183,13 +1206,18 @@ async def schedule_new_orchestration(self, orchestrator: task.Orchestrator[TInpu
11831206 input : TInput | None = None ,
11841207 instance_id : str | None = None ,
11851208 start_at : datetime | None = None ,
1186- reuse_id_policy : pb .OrchestrationIdReusePolicy | None = None ,
1209+ reuse_id_policy : OrchestrationIdReusePolicy | pb .OrchestrationIdReusePolicy | None = None ,
11871210 tags : dict [str , str ] | None = None ,
11881211 version : str | None = None ) -> str :
11891212 """Schedule a new orchestration instance for execution asynchronously.
11901213
11911214 If instance_id is not specified, a random UUID hex string is generated upfront
11921215 and shared across both the OpenTelemetry producer span and the CreateInstanceRequest.
1216+
1217+ ``reuse_id_policy`` controls which existing-instance statuses reject
1218+ duplicate IDs. Omission preserves backend defaults. Existing protobuf
1219+ policies remain supported and retain their replaceable-status semantics.
1220+ Invalid public policy statuses raise ``ValueError`` before sending the request.
11931221 """
11941222 name = orchestrator if isinstance (orchestrator , str ) else task .get_name (orchestrator )
11951223 resolved_instance_id = instance_id if instance_id else uuid .uuid4 ().hex
0 commit comments