Starting in Python 3.13, the monolithic worker was split into two independently versioned layers:
workers/proxy_worker, launched via workers/python/proxyV4/worker.py): A thin, stable transport shell that owns the grpcio EventStream, uvloop policy, console-to-RpcLog logging switch, 4-tier invocation_id correlation, WorkerStatusRequest fast-path, and DependencyManager sys.path isolation.runtimes/v2 → azure-functions-runtime and runtimes/v1 → azure-functions-runtime-v1): Independently PyPI-published execution engines invoked in-process across a narrow 5-verb WorkerRequest coroutine contract.Why inject
protosatWorkerInitRequest?proxy_workerpassesproperties={"protos": protos, "host": self._host}onworker_init_requestandfunction_environment_reload_request. The runtime cachesprotosin a module global, decoupling PyPI runtime releases from specificprotobufC-extension wheel builds.
reload_library_worker)During WorkerInitRequest (and again on FunctionEnvironmentReloadRequest), Dispatcher.reload_library_worker(directory) selects the execution engine in strict priority order:
PYTHON_ENABLE_AGENT_RUNTIME=1): Discovers importlib.metadata.entry_points(group="azurefunctions.runtimes") and loads the registered package via azurefunctions.extensions.base.RuntimeTrackerMeta.azure_functions_runtime): Selected when function_app.py (or PYTHON_SCRIPT_FILE_NAME) exists in the app directory. Indexes functions eagerly during WorkerInit / EnvironmentReload.azure_functions_runtime_v1): Selected when no V2 script file exists; relies on Host function.json scanning followed by per-function FunctionLoadRequest.flowchart TB
subgraph c313_host["Functions Host (.NET — azure-functions-host)"]
n313_host["Script Host (WorkerChannel)<br/>(functions-host)"]
end
subgraph c313_wire["Wire Contract (worker-protobuf)"]
n313_proto["FunctionRpc.proto Contract<br/>(worker-protobuf)"]
end
subgraph c313_worker["Python Worker Process (proxyV4/worker.py)"]
subgraph c313_proxy["Layer 1: proxy_worker (Transport Shell)"]
n313_grpc["start_worker + gRPC Pump<br/>(python-worker)"]
n313_router["Proxy Router & WorkerRequest<br/>(python-worker)"]
end
subgraph c313_rt["Layer 2: Pluggable Runtime Engine (runtimes/)"]
n313_rtv2["Runtime V2 (azure_functions_runtime)<br/>(python-worker)"]
n313_rtv1["Runtime V1 (azure_functions_runtime_v1)<br/>(python-worker)"]
end
end
subgraph c313_lib["Azure/azure-functions-python-library"]
n313_lib["azure-functions SDK & User App<br/>(python-library)"]
end
subgraph c313_ext["Azure/azure-functions-python-extensions"]
n313_ext["Agent Runtimes, WebApp & SdkType<br/>(python-extensions)"]
end
n313_host -->|"ServerDuplexChannel"| n313_proto
n313_proto -->|"EventStream (grpcio)"| n313_grpc
n313_grpc -->|"ContextEnabledTask / Queue"| n313_router
n313_router -->|"WorkerRequest (V2)"| n313_rtv2
n313_router -.->|"WorkerRequest (V1)"| n313_rtv1
n313_router -.->|"Agent Runtime EntryPoint"| n313_ext
n313_rtv2 -->|"WebApp HTTP-v2 / SdkType"| n313_ext
n313_rtv2 -->|"Datum decode + invoke"| n313_lib
n313_rtv1 -.->|"Datum decode + invoke"| n313_lib
| Component | Repository | Source Anchor | Responsibility |
|---|---|---|---|
| Script Host (WorkerChannel) | functions-host |
src/WebJobs.Script.Grpc/Channel/WorkerChannel.cs |
.NET Functions Host runtime spawning proxyV4/worker.py (python -m proxy_worker) for Python 3.13/3.14. |
| FunctionRpc.proto Contract | worker-protobuf |
src/proto/FunctionRpc.proto |
Canonical gRPC wire schema compiled into proxy_worker/protos and injected into PyPI runtimes. |
| start_worker + gRPC Pump | python-worker |
workers/proxy_worker/dispatcher.py:L278 |
Locks worker deps first, enables uvloop, opens grpcio stream, and switches console -> RpcLog. |
| Proxy Router & WorkerRequest | python-worker |
workers/proxy_worker/dispatcher.py:L326 |
Promotes customer deps, dynamically selects V2 / V1 / Agent runtime, and passes WorkerRequest + protos. |
| Runtime V2 (azure_functions_runtime) | python-worker |
runtimes/v2/azure_functions_runtime/handle_event.py:L69 |
PyPI V2 engine: decorator indexing, Datum bindings, HTTP v2 streaming, OpenTelemetry, threadpool. |
| Runtime V1 (azure_functions_runtime_v1) | python-worker |
runtimes/v1/azure_functions_runtime_v1/handle_event.py:L53 |
PyPI V1 engine supporting classic function.json apps across the exact same 5-verb contract. |
| azure-functions SDK & User App | python-library |
azure/functions/__init__.py |
Customer function_app.py + azure-functions SDK types invoked on asyncio loop or threadpool. |
| Agent Runtimes, WebApp & SdkType | python-extensions |
azurefunctions-extensions-base/azurefunctions/extensions/base/runtime.py |
Custom azurefunctions.runtimes entry points (PYTHON_ENABLE_AGENT_RUNTIME), FastAPI HTTP v2, and SDK bindings. |
StartStream → WorkerInitRequest → WorkerRequest(protos) → WorkerInitResponseproxyV4/worker.py starts proxy_worker with uvloop and worker-first deps (grpcio/protobuf). On WorkerInitRequest, proxy_worker promotes customer deps, runs reload_library_worker(dir) (resolving PYTHON_ENABLE_AGENT_RUNTIME entry_points → function_app.py V2 → V1), starts the runtime threadpool, and passes WorkerRequest(properties={'protos': protos, 'host': host}). Key change in 3.13+: Runtime V2 now indexes function_app.py and starts http_v2 during WorkerInit!
Bypassed / Idle Note: Only ONE runtime engine (Agent, V2, or V1) is imported and bound to
_library_worker.
sequenceDiagram
participant host as Functions Host
participant proxy as proxy_worker
participant ext as python-extensions
participant rt as Runtime (v2 / v1)
participant lib as python-library / App
host->>proxy: Spawn proxyV4 -> start_worker(uvloop) + StartStream
host->>proxy: WorkerInitRequest(function_app_directory)
proxy->>ext: reload_library_worker(): check AGENT_RUNTIME entry_points
proxy->>rt: start_threadpool_executor() + worker_init_request(WorkerRequest)
rt->>lib: [V2] Cache protos, load_binding_registry, index_function_app()
rt-->>host: WorkerInitResponse -> wrapped in StreamingMessage
flowchart TB
subgraph c313_host["Functions Host (.NET — azure-functions-host)"]
n313_host["Script Host (WorkerChannel)<br/>(functions-host)"]
end
subgraph c313_wire["Wire Contract (worker-protobuf)"]
n313_proto["FunctionRpc.proto Contract<br/>(worker-protobuf)"]
end
subgraph c313_worker["Python Worker Process (proxyV4/worker.py)"]
subgraph c313_proxy["Layer 1: proxy_worker (Transport Shell)"]
n313_grpc["start_worker + gRPC Pump<br/>(python-worker)"]
n313_router["Proxy Router & WorkerRequest<br/>(python-worker)"]
end
subgraph c313_rt["Layer 2: Pluggable Runtime Engine (runtimes/)"]
n313_rtv2["Runtime V2 (azure_functions_runtime)<br/>(python-worker)"]
n313_rtv1["Runtime V1 (azure_functions_runtime_v1)<br/>(python-worker)"]
end
end
subgraph c313_lib["Azure/azure-functions-python-library"]
n313_lib["azure-functions SDK & User App<br/>(python-library)"]
end
subgraph c313_ext["Azure/azure-functions-python-extensions"]
n313_ext["Agent Runtimes, WebApp & SdkType<br/>(python-extensions)"]
end
n313_host -->|"WorkerChannel"| n313_proto
n313_proto -->|"1. StartStream + WorkerInitRequest"| n313_grpc
n313_grpc -->|"2. call_soon_threadsafe"| n313_router
n313_router -.->|"3a. check Agent Runtime entry_points"| n313_ext
n313_router -->|"3b. V2: WorkerRequest(protos, host)"| n313_rtv2
n313_router -.->|"3c. V1: WorkerRequest(protos, host)"| n313_rtv1
n313_rtv2 -->|"4. V2 indexes function_app.py in Init!"| n313_lib
FunctionEnvironmentReloadRequest → reload_library_worker() → ReloadResponseDuring placeholder boot, the worker defaulted to bundled azure_functions_runtime. On FunctionEnvironmentReloadRequest, proxy_worker promotes the newly mounted customer .python_packages, re-runs reload_library_worker(directory) (so a V1 app switches to azure_functions_runtime_v1, an Agent app loads its custom runtime, or a customer-pinned PyPI azure-functions-runtime takes over!), re-injects protos, reloads os.environ + tzset(), and indexes the specialized app.
Bypassed / Idle Note: Only occurs when specializing warm Consumption standby containers.
sequenceDiagram
participant host as Functions Host
participant proxy as proxy_worker
participant rt as Selected Runtime
participant lib as Customer Env & App
host->>proxy: FunctionEnvironmentReloadRequest(app_dir, env_vars)
proxy->>proxy: DependencyManager.prioritize_customer_dependencies(dir)
proxy->>rt: reload_library_worker(dir) + start_threadpool_executor()
rt->>lib: function_environment_reload_request(WorkerRequest(protos))
rt-->>host: FunctionEnvironmentReloadResponse(capabilities)
flowchart TB
subgraph c313_host["Functions Host (.NET — azure-functions-host)"]
n313_host["Script Host (WorkerChannel)<br/>(functions-host)"]
end
subgraph c313_wire["Wire Contract (worker-protobuf)"]
n313_proto["FunctionRpc.proto Contract<br/>(worker-protobuf)"]
end
subgraph c313_worker["Python Worker Process (proxyV4/worker.py)"]
subgraph c313_proxy["Layer 1: proxy_worker (Transport Shell)"]
n313_grpc["start_worker + gRPC Pump<br/>(python-worker)"]
n313_router["Proxy Router & WorkerRequest<br/>(python-worker)"]
end
subgraph c313_rt["Layer 2: Pluggable Runtime Engine (runtimes/)"]
n313_rtv2["Runtime V2 (azure_functions_runtime)<br/>(python-worker)"]
n313_rtv1["Runtime V1 (azure_functions_runtime_v1)<br/>(python-worker)"]
end
end
subgraph c313_lib["Azure/azure-functions-python-library"]
n313_lib["azure-functions SDK & User App<br/>(python-library)"]
end
subgraph c313_ext["Azure/azure-functions-python-extensions"]
n313_ext["Agent Runtimes, WebApp & SdkType<br/>(python-extensions)"]
end
n313_host -->|"WorkerChannel"| n313_proto
n313_proto -->|"1. FunctionEnvironmentReloadRequest"| n313_grpc
n313_grpc -->|"2. prioritize_customer_deps(dir)"| n313_router
n313_router -.->|"3a. re-evaluate Agent Runtime"| n313_ext
n313_router -->|"3b. reload V2 + inject protos"| n313_rtv2
n313_router -.->|"3c. or switch to V1!"| n313_rtv1
n313_rtv2 -->|"4. reset_host_config + env + index"| n313_lib
FunctionsMetadataRequest → WorkerRequest → FunctionMetadataResponseproxy_worker forwards WorkerRequest(name='WorkerMetadataRequest') (no protos needed — already cached in runtime!). In Runtime V2, functions_metadata_request immediately returns the _metadata_result indexed during Init/Specialization (use_default_metadata_indexing=False). In Runtime V1, it returns use_default_metadata_indexing=True, results=None so the Host reads function.json files.
Bypassed / Idle Note: V2 already indexed
function_app.pyduring Init/Specialization, so Phase 3 is an O(1) cached return!
sequenceDiagram
participant host as Functions Host
participant proxy as proxy_worker
participant rtv2 as Runtime V2
participant rtv1 as Runtime V1
host->>proxy: FunctionsMetadataRequest(function_app_directory)
proxy->>rtv2: [If V2] await rtv2.functions_metadata_request(req)
proxy->>rtv1: [If V1] await rtv1.functions_metadata_request(req)
proxy-->>host: StreamingMessage(function_metadata_response)
flowchart TB
subgraph c313_host["Functions Host (.NET — azure-functions-host)"]
n313_host["Script Host (WorkerChannel)<br/>(functions-host)"]
end
subgraph c313_wire["Wire Contract (worker-protobuf)"]
n313_proto["FunctionRpc.proto Contract<br/>(worker-protobuf)"]
end
subgraph c313_worker["Python Worker Process (proxyV4/worker.py)"]
subgraph c313_proxy["Layer 1: proxy_worker (Transport Shell)"]
n313_grpc["start_worker + gRPC Pump<br/>(python-worker)"]
n313_router["Proxy Router & WorkerRequest<br/>(python-worker)"]
end
subgraph c313_rt["Layer 2: Pluggable Runtime Engine (runtimes/)"]
n313_rtv2["Runtime V2 (azure_functions_runtime)<br/>(python-worker)"]
n313_rtv1["Runtime V1 (azure_functions_runtime_v1)<br/>(python-worker)"]
end
end
subgraph c313_lib["Azure/azure-functions-python-library"]
n313_lib["azure-functions SDK & User App<br/>(python-library)"]
end
subgraph c313_ext["Azure/azure-functions-python-extensions"]
n313_ext["Agent Runtimes, WebApp & SdkType<br/>(python-extensions)"]
end
n313_host -->|"WorkerChannel"| n313_proto
n313_proto -->|"1. FunctionsMetadataRequest"| n313_grpc
n313_grpc -->|"2. _handle__functions_metadata_request"| n313_router
n313_router -->|"3a. V2: return cached _metadata_result"| n313_rtv2
n313_router -.->|"3b. V1: use_default_indexing=True"| n313_rtv1
FunctionLoadRequest → WorkerRequest → FunctionLoadResponseruntimes/v1); Immediate No-Op Ack for V2The split makes V1 vs V2 load behavior explicit: runtimes/v1/handle_event.py implements real load_function() + _functions.add_function(function_id, func, metadata, protos) to import each function.json script; runtimes/v2/handle_event.py (L160) is a 6-line immediate FunctionLoadResponse(Success) because V2 functions were already loaded during indexing!
Bypassed / Idle Note: In Runtime V2,
function_load_requestis a pure no-op acknowledgment.
sequenceDiagram
participant host as Functions Host
participant proxy as proxy_worker
participant rtv1 as Runtime V1
participant app as V1 __init__.py
host->>proxy: FunctionLoadRequest(function_id, metadata)
proxy->>rtv1: [V1] await rtv1.function_load_request(WorkerRequest)
rtv1->>app: loader.load_function() imports script_file & entry_point
rtv1-->>host: FunctionLoadResponse(function_id, Success)
flowchart TB
subgraph c313_host["Functions Host (.NET — azure-functions-host)"]
n313_host["Script Host (WorkerChannel)<br/>(functions-host)"]
end
subgraph c313_wire["Wire Contract (worker-protobuf)"]
n313_proto["FunctionRpc.proto Contract<br/>(worker-protobuf)"]
end
subgraph c313_worker["Python Worker Process (proxyV4/worker.py)"]
subgraph c313_proxy["Layer 1: proxy_worker (Transport Shell)"]
n313_grpc["start_worker + gRPC Pump<br/>(python-worker)"]
n313_router["Proxy Router & WorkerRequest<br/>(python-worker)"]
end
subgraph c313_rt["Layer 2: Pluggable Runtime Engine (runtimes/)"]
n313_rtv2["Runtime V2 (azure_functions_runtime)<br/>(python-worker)"]
n313_rtv1["Runtime V1 (azure_functions_runtime_v1)<br/>(python-worker)"]
end
end
subgraph c313_lib["Azure/azure-functions-python-library"]
n313_lib["azure-functions SDK & User App<br/>(python-library)"]
end
subgraph c313_ext["Azure/azure-functions-python-extensions"]
n313_ext["Agent Runtimes, WebApp & SdkType<br/>(python-extensions)"]
end
n313_host -->|"WorkerChannel"| n313_proto
n313_proto -->|"1. FunctionLoadRequest"| n313_grpc
n313_grpc -->|"2. WorkerRequest"| n313_router
n313_router -->|"3a. V1: load_function + add_function"| n313_rtv1
n313_rtv1 -->|"4. V1 imports __init__.py & SDK hints"| n313_lib
n313_router -.->|"3b. V2: immediate Success ack"| n313_rtv2
InvocationRequest → WorkerRequest → Runtime v2/v1 → InvocationResponseproxy_worker stamps the ContextEnabledTask with invocation_id and awaits _library_worker.invocation_request(WorkerRequest). The runtime decodes inputs using its cached protos, coordinates http_v2 streaming or SdkType bindings (python-extensions), executes async on uvloop or sync on the runtime’s ThreadPoolExecutor, and returns InvocationResponse.
Bypassed / Idle Note: Runtime discovery and
protosinjection do NOT run per-invocation — cached from Phase 1/2.
sequenceDiagram
participant host as Functions Host
participant proxy as proxy_worker
participant rt as Runtime Engine
participant app as SDK / Extensions / App
host->>proxy: InvocationRequest(invocation_id, function_id)
proxy->>rt: await _library_worker.invocation_request(WorkerRequest)
rt->>app: from_incoming_proto -> http_v2/SdkType -> run handler
app-->>host: to_outgoing_proto -> InvocationResponse -> _grpc_resp_queue
flowchart TB
subgraph c313_host["Functions Host (.NET — azure-functions-host)"]
n313_host["Script Host (WorkerChannel)<br/>(functions-host)"]
end
subgraph c313_wire["Wire Contract (worker-protobuf)"]
n313_proto["FunctionRpc.proto Contract<br/>(worker-protobuf)"]
end
subgraph c313_worker["Python Worker Process (proxyV4/worker.py)"]
subgraph c313_proxy["Layer 1: proxy_worker (Transport Shell)"]
n313_grpc["start_worker + gRPC Pump<br/>(python-worker)"]
n313_router["Proxy Router & WorkerRequest<br/>(python-worker)"]
end
subgraph c313_rt["Layer 2: Pluggable Runtime Engine (runtimes/)"]
n313_rtv2["Runtime V2 (azure_functions_runtime)<br/>(python-worker)"]
n313_rtv1["Runtime V1 (azure_functions_runtime_v1)<br/>(python-worker)"]
end
end
subgraph c313_lib["Azure/azure-functions-python-library"]
n313_lib["azure-functions SDK & User App<br/>(python-library)"]
end
subgraph c313_ext["Azure/azure-functions-python-extensions"]
n313_ext["Agent Runtimes, WebApp & SdkType<br/>(python-extensions)"]
end
n313_host -->|"WorkerChannel"| n313_proto
n313_proto -->|"1. InvocationRequest"| n313_grpc
n313_grpc -->|"2. ContextEnabledTask"| n313_router
n313_router -->|"3. WorkerRequest (no protos copy)"| n313_rtv2
n313_rtv2 -.->|"4a. http_v2 / SdkType / Settlement"| n313_ext
n313_rtv2 -->|"4b. execute_async / run_sync_func"| n313_lib
WorkerStatusRequest → proxy_worker → WorkerStatusResponseIn 3.13 – 3.14, _handle__worker_status_request is the only message handler in proxy_worker/dispatcher.py that does NOT delegate to _library_worker! It short-circuits inside proxy_worker and returns WorkerStatusResponse immediately—though it still runs on the shared CPython interpreter’s uvloop and GIL.
Bypassed / Idle Note: Runtime V2, Runtime V1, SDK, Extensions, and Customer App are 100% bypassed!
sequenceDiagram
participant host as Host Scale Controller
participant grpc as Proxy gRPC Thread
participant proxy as Proxy Dispatcher
host->>grpc: WorkerStatusRequest()
grpc->>proxy: _handle__worker_status_request (short-circuit)
proxy-->>host: WorkerStatusResponse()
flowchart TB
subgraph c313_host["Functions Host (.NET — azure-functions-host)"]
n313_host["Script Host (WorkerChannel)<br/>(functions-host)"]
end
subgraph c313_wire["Wire Contract (worker-protobuf)"]
n313_proto["FunctionRpc.proto Contract<br/>(worker-protobuf)"]
end
subgraph c313_worker["Python Worker Process (proxyV4/worker.py)"]
subgraph c313_proxy["Layer 1: proxy_worker (Transport Shell)"]
n313_grpc["start_worker + gRPC Pump<br/>(python-worker)"]
n313_router["Proxy Router & WorkerRequest<br/>(python-worker)"]
end
subgraph c313_rt["Layer 2: Pluggable Runtime Engine (runtimes/)"]
n313_rtv2["Runtime V2 (azure_functions_runtime)<br/>(python-worker)"]
n313_rtv1["Runtime V1 (azure_functions_runtime_v1)<br/>(python-worker)"]
end
end
subgraph c313_lib["Azure/azure-functions-python-library"]
n313_lib["azure-functions SDK & User App<br/>(python-library)"]
end
subgraph c313_ext["Azure/azure-functions-python-extensions"]
n313_ext["Agent Runtimes, WebApp & SdkType<br/>(python-extensions)"]
end
n313_host -->|"WorkerChannel"| n313_proto
n313_proto -->|"1. WorkerStatusRequest"| n313_grpc
n313_grpc -->|"2. proxy short-circuit (still GIL)"| n313_router
n313_router -->|"3. WorkerStatusResponse"| n313_grpc
n313_grpc -->|"4. EventStream reply"| n313_proto
LogRecord → 4-Tier ID Resolver → StreamingMessage(RpcLog) → HostBecause execution lives in a separate PyPI runtime package (or custom Agent Runtime), proxy_worker’s AsyncLoggingHandler resolves invocation_id across 4 fallback tiers: 1) global tracker (for custom runtimes without cv), 2) ContextEnabledTask attribute, 3) _library_worker.invocation_id_cv (ContextVar), and 4) _thread_invocation_registry—then streams RpcLog frames back to the Host.
Bypassed / Idle Note: Flows RIGHT → LEFT from User App / Runtime loggers through proxy_worker’s AsyncLoggingHandler to the Host.
sequenceDiagram
participant app as User Code / Thread
participant rt as Runtime (invocation_id_cv)
participant proxy as Proxy AsyncLoggingHandler
participant host as Host (AppInsights / Kusto)
app->>proxy: logging.info(...) from async task, threadpool, or user thread
proxy->>rt: get_current_invocation_id() 4-tier lookup
proxy-->>host: Tag System vs User -> protos.RpcLog -> EventStream
flowchart TB
subgraph c313_host["Functions Host (.NET — azure-functions-host)"]
n313_host["Script Host (WorkerChannel)<br/>(functions-host)"]
end
subgraph c313_wire["Wire Contract (worker-protobuf)"]
n313_proto["FunctionRpc.proto Contract<br/>(worker-protobuf)"]
end
subgraph c313_worker["Python Worker Process (proxyV4/worker.py)"]
subgraph c313_proxy["Layer 1: proxy_worker (Transport Shell)"]
n313_grpc["start_worker + gRPC Pump<br/>(python-worker)"]
n313_router["Proxy Router & WorkerRequest<br/>(python-worker)"]
end
subgraph c313_rt["Layer 2: Pluggable Runtime Engine (runtimes/)"]
n313_rtv2["Runtime V2 (azure_functions_runtime)<br/>(python-worker)"]
n313_rtv1["Runtime V1 (azure_functions_runtime_v1)<br/>(python-worker)"]
end
end
subgraph c313_lib["Azure/azure-functions-python-library"]
n313_lib["azure-functions SDK & User App<br/>(python-library)"]
end
subgraph c313_ext["Azure/azure-functions-python-extensions"]
n313_ext["Agent Runtimes, WebApp & SdkType<br/>(python-extensions)"]
end
n313_proto -->|"AppInsights / Kusto"| n313_host
n313_lib -->|"1. user logging.info() (cv / TLS set)"| n313_rtv2
n313_rtv2 -->|"2. root AsyncLoggingHandler + 4-tier ID"| n313_router
n313_router -->|"3. protos.RpcLog -> _grpc_resp_queue"| n313_grpc
n313_grpc -->|"4. StreamingMessage(rpc_log) → Host"| n313_proto