Home / Azure

AzureRunbookAdvanced

Durable Functions orchestrations stuck in Pending or Running: a runbook for control queues, partitions and non-determinism

Find why Durable Functions instances stop moving, check control queues, partition ownership, task hub sharing and replay errors, then recover without losing work.

Deepak Bhardwaj7 min read

Applies toAzure Functions with Durable Functions extension 2.x or later, Azure Storage backend

Orchestrations were started, the HTTP starter returned 202, and nothing moves. Or thousands of instances have been in Running since the last deployment. This runbook covers the Azure Storage backend. Other backends have different internals, so confirm which one host.json selects first.

How the pieces map to symptoms

For a task hub called OrdersHub, the Azure Storage provider creates lowercase queues and blob containers:

Object Purpose What a backlog means
ordershub-control-00 to -NN Start messages, activity results, timers, external events Orchestrators are not being dispatched
ordershub-workitems Activity messages, shared by all workers Activities are slow or workers are too few
OrdersHubHistory table Event history that replay reads Large histories slow every replay
OrdersHubInstances table Status shown by the management API May lag the real state
ordershub-leases or OrdersHubPartitions Who owns each control queue Queues with no owner never drain
ordershub-largemessages Payloads too big for a queue message Big inputs, more storage latency

Each instance ID hashes to one control queue. One control queue is owned by one worker at a time, so workers beyond partitionCount add activity capacity but no orchestrator capacity. The default is 4 partitions and the maximum is 16.

Check 1: list the affected instances

Use the management API with the Durable system key. It grants control over every instance, so do not paste it into tickets.

RG=rg-orders; APP=func-orders; HUB=OrdersHub
KEY=$(az functionapp keys list -g $RG -n $APP \
  --query "systemKeys.durabletask_extension" -o tsv)
BASE="https://$APP.azurewebsites.net/runtime/webhooks/durabletask"

curl -s "$BASE/instances?taskHub=$HUB&runtimeStatus=Pending&top=50&code=$KEY"
curl -s "$BASE/instances?taskHub=$HUB&runtimeStatus=Running&createdTimeTo=2026-11-24T00:00:00Z&top=50&code=$KEY"
curl -s "$BASE/instances/<instance-id>?taskHub=$HUB&showHistory=true&code=$KEY"

List results are paged. Read the x-ms-continuation-token response header and send it back as a request header, otherwise your count is wrong.

If the API itself fails to answer, the host is down. Fix host startup before looking at the hub.

The last history event tells you where to look:

Last event in history Likely cause Next step
No history, status Pending Start message not dequeued Check 2 and 3
TaskScheduled, no completion Activity running, lost to a crash, or queued Work-item queue depth
TimerCreated, fire time in the past Control queue not draining Check 2 and 3
Waiting on an external event Event never raised, or sent to the wrong ID or name Check the caller
Moved until a deployment, then stopped Replay mismatch Check 4

Check 2: measure queue depth per partition

# pip install azure-identity azure-storage-queue
from azure.identity import DefaultAzureCredential
from azure.storage.queue import QueueServiceClient

svc = QueueServiceClient(
    "https://<storageaccount>.queue.core.windows.net",
    credential=DefaultAzureCredential(),
)
for q in svc.list_queues(name_starts_with="ordershub-"):
    c = svc.get_queue_client(q.name)
    print(q.name, c.get_queue_properties().approximate_message_count)

The identity needs a queue data role such as Storage Queue Data Reader. Run it several times, a minute apart.

  • One control queue grows: that partition has no healthy owner, or a hot instance such as a singleton or an overused entity lives there.
  • All control queues grow: host down, storage throttled, or another app is competing.
  • Only workitems grows: an activity problem. Look at dependencies and concurrency, not orchestrators.
  • All queues are empty, instances still Running: the instances are waiting for an event, or their messages were lost or consumed elsewhere.

Check 3: find who is processing, and who should not be

traces
| where timestamp > ago(1h)
| where tostring(customDimensions.Category) == "DurableTask.AzureStorage"
| extend hub = tostring(customDimensions.prop__TaskHub),
         partition = tostring(customDimensions.prop__PartitionId),
         ageMs = tolong(customDimensions.prop__Age),
         dequeues = toint(customDimensions.prop__DequeueCount)
| where partition contains "control"
| summarize messages = count(), maxAgeMs = max(ageMs), maxDequeues = max(dequeues),
            workers = dcount(cloud_RoleInstance), apps = make_set(cloud_RoleName)
    by hub, partition, bin(timestamp, 5m)
| order by timestamp desc, partition asc

This needs DurableTask.AzureStorage logged at Information. If you get nothing, check the log level and sampling before concluding that nothing is running.

A normal dequeue count is 1. High counts mean a message keeps failing. High maxAgeMs means it waited a long time.

If apps holds two names, two apps share the hub. The usual case is a staging slot: it dequeues production messages and either runs old code or fails to find the function. Give each slot its own hub and make the setting sticky:

{
  "version": "2.0",
  "extensions": {
    "durableTask": {
      "hubName": "%TaskHubName%",
      "storageProvider": { "partitionCount": 8 }
    }
  }
}
az functionapp config appsettings set -g $RG -n $APP \
  --slot-settings TaskHubName=OrdersHub
az functionapp config appsettings set -g $RG -n $APP --slot staging \
  --slot-settings TaskHubName=OrdersHubStaging

Warning

Renaming the hub on a live app strands every in-flight instance in the old hub. Pin the current production name first. Check it from the queue prefixes rather than guessing.

Check 4: prove or rule out non-determinism

An orchestrator replays its code against the saved history. If a deployment added, removed, reordered or renamed a call, replay no longer matches and the instance fails or appears stuck.

union traces, exceptions
| where timestamp > ago(24h)
| extend text = strcat(message, " ", outerMessage, " ", tostring(customDimensions.prop__reason))
| where text has_any ("non-deterministic", "nondeterministic", "Non-Deterministic")
| summarize count(), first = min(timestamp) by operation_Name, cloud_RoleInstance

Compare first with the deployment time. Then review the orchestrator for:

  • Current time, random numbers or GUIDs not taken from the orchestration context
  • Environment variables or configuration that select a branch
  • Direct I/O, or awaiting anything other than a Durable task
  • Blocking sleeps in place of durable timers

Fix

Partition not draining

Restart the app first. It forces partition ownership to be reacquired:

az functionapp restart -g $RG -n $APP

If one queue stays stuck, look for storage throttling on the account in AzureWebJobsStorage, or on the one named in connectionName. Memory pressure is the other common cause: lower maxConcurrentOrchestratorFunctions and controlQueueBufferThreshold, and use a 64-bit worker where the plan lets you choose.

Activities backing up

Raise maxConcurrentActivityFunctions for I/O-bound work and lower it for CPU-bound or memory-heavy work. The limit is per worker, so multiply by the instance count before pointing it at a database.

Broken replay after a deployment

  1. Roll back to the previous build. Instances that have not failed can continue from their history.
  2. Suspend what you need to hold: POST /instances/<id>/suspend?reason=....
  3. Redeploy with orchestration versioning, or side by side on a new hub.

For instances you cannot save, terminate and restart them:

curl -X POST "$BASE/instances/<id>/terminate?taskHub=$HUB&reason=bad-deploy&code=$KEY"
curl -X POST "$BASE/instances/<id>/restart?taskHub=$HUB&restartWithNewInstanceId=true&code=$KEY"

Caution

Restart runs the workflow again from the start with the original input. Activities that charge cards or send mail will repeat unless they are idempotent. Terminate does not stop an activity that is already executing, and does not propagate automatically to everything you may expect. Check sub-orchestrations.

Caution

Do not clear control or work-item queues in production to "unstick" a hub. It deletes messages for healthy instances, which then wait forever.

Prevent it next time

  • Version orchestrators. Where your SDK supports it, set defaultVersion under durableTask in host.json and branch on the instance version in code. Otherwise, use side-by-side hubs and drain the old one.
  • Choose partitionCount before launch. It cannot be changed on an existing hub; you need a new hub name.
  • Keep histories small. Use continue-as-new for eternal loops, split large fan-outs into sub-orchestrations, and pass blob references instead of payloads.
  • Give the hub its own storage account when volume is high, through connectionName.
  • Purge finished instances on a timer with DELETE /instances and a created-time range.
  • Alert on age, not only failures. Page on control queue message age and on Running instances older than the workflow's normal maximum.
  • Test replay. Replay saved production histories against new code, if your SDK has support for it, before deploying.