From 19de8cc04af3fd8005cd4c587e974456b96b8323 Mon Sep 17 00:00:00 2001 From: Alex Mazzeo Date: Fri, 24 Apr 2026 10:14:19 -0700 Subject: [PATCH] Nexus samples: use business IDs for workflow IDs. Stop using the Nexus request ID (nexus_cancel) or bare uuid4 (hello_nexus, nexus_multiple_args) as the backing workflow ID. Build a meaningful business ID from the operation input and append a uuid4 suffix for uniqueness. Co-Authored-By: Claude Opus 4.7 (1M context) --- hello_nexus/handler/service_handler.py | 2 +- nexus_cancel/handler/service_handler.py | 9 ++++++--- nexus_multiple_args/handler/service_handler.py | 2 +- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/hello_nexus/handler/service_handler.py b/hello_nexus/handler/service_handler.py index 1295abd1..241ae8e4 100644 --- a/hello_nexus/handler/service_handler.py +++ b/hello_nexus/handler/service_handler.py @@ -33,7 +33,7 @@ async def my_workflow_run_operation( return await ctx.start_workflow( WorkflowStartedByNexusOperation.run, input, - id=str(uuid.uuid4()), + id=f"hello-nexus-workflow-{input.name}-{uuid.uuid4()}", ) # This is a Nexus operation that responds synchronously to all requests. That means diff --git a/nexus_cancel/handler/service_handler.py b/nexus_cancel/handler/service_handler.py index 92868510..b40452b1 100644 --- a/nexus_cancel/handler/service_handler.py +++ b/nexus_cancel/handler/service_handler.py @@ -1,12 +1,15 @@ """ Nexus service handler for the cancellation sample. -The hello operation is backed by a workflow, using the Nexus request ID as the -workflow ID for idempotency across retries. +The hello operation is backed by a workflow whose ID is derived from the +operation input (name + language), giving each fan-out branch a distinct, +meaningful business ID. """ from __future__ import annotations +import uuid + import nexusrpc from temporalio import nexus @@ -23,5 +26,5 @@ async def hello( return await ctx.start_workflow( HelloHandlerWorkflow.run, input, - id=ctx.request_id, + id=f"hello-handler-{input.name}-{input.language.name}-{uuid.uuid4()}", ) diff --git a/nexus_multiple_args/handler/service_handler.py b/nexus_multiple_args/handler/service_handler.py index c2ddfb92..2998da17 100644 --- a/nexus_multiple_args/handler/service_handler.py +++ b/nexus_multiple_args/handler/service_handler.py @@ -32,7 +32,7 @@ async def hello( input.name, # First argument: name input.language, # Second argument: language ], - id=str(uuid.uuid4()), + id=f"hello-multi-args-{input.name}-{input.language}-{uuid.uuid4()}", )