From 5ee049bb8667971d9bfac6b91b2027ae65c53513 Mon Sep 17 00:00:00 2001 From: Quinn Klassen Date: Mon, 6 Apr 2026 14:09:27 -0700 Subject: [PATCH 1/3] Add namespace to Nexus operation info --- temporalio/nexus/_operation_context.py | 3 ++ temporalio/worker/_nexus.py | 4 +-- tests/nexus/test_workflow_caller.py | 45 ++++++++++++++++++++++++++ 3 files changed, 50 insertions(+), 2 deletions(-) diff --git a/temporalio/nexus/_operation_context.py b/temporalio/nexus/_operation_context.py index 66e675d27..ae310f070 100644 --- a/temporalio/nexus/_operation_context.py +++ b/temporalio/nexus/_operation_context.py @@ -79,6 +79,9 @@ class Info: Retrieved inside a Nexus operation handler via :py:func:`info`. """ + namespace: str + """The namespace of the worker handling this Nexus operation.""" + task_queue: str """The task queue of the worker handling this Nexus operation.""" diff --git a/temporalio/worker/_nexus.py b/temporalio/worker/_nexus.py index 278337746..9e1086a4d 100644 --- a/temporalio/worker/_nexus.py +++ b/temporalio/worker/_nexus.py @@ -242,7 +242,7 @@ async def _handle_cancel_operation_task( request_deadline=request_deadline, ) temporalio.nexus._operation_context._TemporalCancelOperationContext( - info=lambda: Info(task_queue=self._task_queue), + info=lambda: Info(namespace=self._client.namespace, task_queue=self._task_queue), nexus_context=ctx, client=self._client, _runtime_metric_meter=self._metric_meter, @@ -373,7 +373,7 @@ async def _start_operation( temporalio.nexus._operation_context._TemporalStartOperationContext( nexus_context=ctx, client=self._client, - info=lambda: Info(task_queue=self._task_queue), + info=lambda: Info(namespace=self._client.namespace, task_queue=self._task_queue), _runtime_metric_meter=self._metric_meter, _worker_shutdown_event=self._worker_shutdown_event, ).set() diff --git a/tests/nexus/test_workflow_caller.py b/tests/nexus/test_workflow_caller.py index ca9e2e145..a1e685947 100644 --- a/tests/nexus/test_workflow_caller.py +++ b/tests/nexus/test_workflow_caller.py @@ -696,6 +696,51 @@ async def test_sync_operation_happy_path(client: Client, env: WorkflowEnvironmen assert wf_output.op_output.value == "sync response" +@service_handler +class NexusInfoService: + @sync_operation + async def get_info( + self, _ctx: StartOperationContext, _input: None + ) -> dict[str, str]: + info = nexus.info() + return {"namespace": info.namespace, "task_queue": info.task_queue} + + +@workflow.defn +class NexusInfoCallerWorkflow: + @workflow.run + async def run(self, task_queue: str) -> dict[str, str]: + nexus_client = workflow.create_nexus_client( + service=NexusInfoService, + endpoint=make_nexus_endpoint_name(task_queue), + ) + return await nexus_client.execute_operation( + NexusInfoService.get_info, None + ) + + +async def test_nexus_info_includes_namespace( + client: Client, env: WorkflowEnvironment +): + task_queue = str(uuid.uuid4()) + async with Worker( + client, + nexus_service_handlers=[NexusInfoService()], + workflows=[NexusInfoCallerWorkflow], + task_queue=task_queue, + ): + endpoint_name = make_nexus_endpoint_name(task_queue) + await env.create_nexus_endpoint(endpoint_name, task_queue) + result = await client.execute_workflow( + NexusInfoCallerWorkflow.run, + task_queue, + id=str(uuid.uuid4()), + task_queue=task_queue, + ) + assert result["namespace"] == client.namespace + assert result["task_queue"] == task_queue + + async def test_workflow_run_operation_happy_path( client: Client, env: WorkflowEnvironment ): From cc0c64d3aa4a7eeb07f67a0ddd8d5443762b9b4a Mon Sep 17 00:00:00 2001 From: Quinn Klassen Date: Mon, 6 Apr 2026 14:11:49 -0700 Subject: [PATCH 2/3] Make more consistent with task queue info --- temporalio/worker/_nexus.py | 6 ++++-- temporalio/worker/_worker.py | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/temporalio/worker/_nexus.py b/temporalio/worker/_nexus.py index 9e1086a4d..d324a0c4c 100644 --- a/temporalio/worker/_nexus.py +++ b/temporalio/worker/_nexus.py @@ -67,6 +67,7 @@ def __init__( *, bridge_worker: Callable[[], temporalio.bridge.worker.Worker], client: temporalio.client.Client, + namespace: str, task_queue: str, service_handlers: Sequence[Any], data_converter: temporalio.converter.DataConverter, @@ -76,6 +77,7 @@ def __init__( ) -> None: self._bridge_worker = bridge_worker self._client = client + self._namespace = namespace self._task_queue = task_queue self._metric_meter = metric_meter @@ -242,7 +244,7 @@ async def _handle_cancel_operation_task( request_deadline=request_deadline, ) temporalio.nexus._operation_context._TemporalCancelOperationContext( - info=lambda: Info(namespace=self._client.namespace, task_queue=self._task_queue), + info=lambda: Info(namespace=self._namespace, task_queue=self._task_queue), nexus_context=ctx, client=self._client, _runtime_metric_meter=self._metric_meter, @@ -373,7 +375,7 @@ async def _start_operation( temporalio.nexus._operation_context._TemporalStartOperationContext( nexus_context=ctx, client=self._client, - info=lambda: Info(namespace=self._client.namespace, task_queue=self._task_queue), + info=lambda: Info(namespace=self._namespace, task_queue=self._task_queue), _runtime_metric_meter=self._metric_meter, _worker_shutdown_event=self._worker_shutdown_event, ).set() diff --git a/temporalio/worker/_worker.py b/temporalio/worker/_worker.py index 332e2ead7..2ad1d42c6 100644 --- a/temporalio/worker/_worker.py +++ b/temporalio/worker/_worker.py @@ -485,6 +485,7 @@ def _init_from_config(self, client: temporalio.client.Client, config: WorkerConf self._nexus_worker = _NexusWorker( bridge_worker=lambda: self._bridge_worker, client=config["client"], # type: ignore[reportTypedDictNotRequiredAccess] + namespace=client_config["namespace"], task_queue=config["task_queue"], # type: ignore[reportTypedDictNotRequiredAccess] service_handlers=nexus_service_handlers, data_converter=client_config["data_converter"], From 3413168779a33a0cd19f47ca49d16af2791ef10d Mon Sep 17 00:00:00 2001 From: Quinn Klassen Date: Mon, 6 Apr 2026 14:29:29 -0700 Subject: [PATCH 3/3] run format --- tests/nexus/test_workflow_caller.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/tests/nexus/test_workflow_caller.py b/tests/nexus/test_workflow_caller.py index a1e685947..2b9699089 100644 --- a/tests/nexus/test_workflow_caller.py +++ b/tests/nexus/test_workflow_caller.py @@ -714,14 +714,10 @@ async def run(self, task_queue: str) -> dict[str, str]: service=NexusInfoService, endpoint=make_nexus_endpoint_name(task_queue), ) - return await nexus_client.execute_operation( - NexusInfoService.get_info, None - ) + return await nexus_client.execute_operation(NexusInfoService.get_info, None) -async def test_nexus_info_includes_namespace( - client: Client, env: WorkflowEnvironment -): +async def test_nexus_info_includes_namespace(client: Client, env: WorkflowEnvironment): task_queue = str(uuid.uuid4()) async with Worker( client,