What is the issue?
Importing the sandbox preview package eagerly imports both its client and worker runtime APIs.
What is the impact?
Callers that only declare profiles or use a subset of the sandbox API load the worker graph, Azure Identity, and gRPC-related dependencies during process startup. This adds avoidable cold-start work for sandbox control-plane and configuration workloads.
Details about the issue including code reference
Relevant code:
|
from durabletask.azuremanaged.preview.sandboxes.client import SandboxActivitiesClient |
|
from durabletask.azuremanaged.preview.sandboxes.helpers import SandboxActivity |
|
from durabletask.azuremanaged.preview.sandboxes.worker_profiles import SandboxWorkerProfile |
|
from durabletask.azuremanaged.preview.sandboxes.worker_profiles import SandboxWorkerProfileOptions |
|
from durabletask.azuremanaged.preview.sandboxes.worker_profiles import sandbox_worker_profile |
|
from durabletask.azuremanaged.preview.sandboxes.worker import SandboxWorker |
|
# Copyright (c) Microsoft Corporation. |
|
# Licensed under the MIT License. |
|
|
|
import os |
|
import random |
|
import threading |
|
|
|
from typing import Iterator, Optional |
|
|
|
import grpc |
|
from azure.core.credentials import TokenCredential |
|
from azure.identity import ManagedIdentityCredential |
|
|
|
from durabletask.azuremanaged.internal import sandbox_service_pb2 as pb |
|
from durabletask.azuremanaged.preview.sandboxes.helpers import SandboxActivity |
|
from durabletask.azuremanaged.preview.sandboxes.helpers import resolve_activities |
|
from durabletask.azuremanaged.preview.sandboxes.worker_profiles import ( |
|
DEFAULT_MAX_CONCURRENT_ACTIVITIES, |
|
) |
|
from durabletask.azuremanaged.preview.sandboxes.worker_messages import ( |
|
build_sandbox_worker_heartbeat, |
|
build_sandbox_worker_start, |
|
) |
|
from durabletask.azuremanaged.preview.sandboxes.transport import ( |
|
SandboxActivitiesGrpcTransport, |
|
) |
|
from durabletask.azuremanaged.worker import DurableTaskSchedulerWorker |
The package initializer imports SandboxActivitiesClient and SandboxWorker. Importing SandboxWorker loads the sandbox runtime and ManagedIdentityCredential even when that runtime is not used.
A potential or proposed solution
Use lazy package exports through module getattr and TYPE_CHECKING imports, or split profile-definition APIs into a lightweight module. Preserve the documented public names and import behavior.
What is the issue?
Importing the sandbox preview package eagerly imports both its client and worker runtime APIs.
What is the impact?
Callers that only declare profiles or use a subset of the sandbox API load the worker graph, Azure Identity, and gRPC-related dependencies during process startup. This adds avoidable cold-start work for sandbox control-plane and configuration workloads.
Details about the issue including code reference
Relevant code:
durabletask-python/durabletask-azuremanaged/durabletask/azuremanaged/preview/sandboxes/__init__.py
Lines 18 to 23 in 55d8e0b
durabletask-python/durabletask-azuremanaged/durabletask/azuremanaged/preview/sandboxes/worker.py
Lines 1 to 27 in 55d8e0b
The package initializer imports SandboxActivitiesClient and SandboxWorker. Importing SandboxWorker loads the sandbox runtime and ManagedIdentityCredential even when that runtime is not used.
A potential or proposed solution
Use lazy package exports through module getattr and TYPE_CHECKING imports, or split profile-definition APIs into a lightweight module. Preserve the documented public names and import behavior.