alpha

Lays down guidelines for building Azure Durable Functions in C# with the isolated worker model: replay-safe orchestrators, activities, entities, retries and testing.
description: 'Guidelines and best practices for building Azure Durable Functions in C# using the isolated worker model'
applyTo: '**/.cs, **/host.json, **/local.settings.json, **/.csproj'
Microsoft.Azure.Functions.Worker.Extensions.DurableTask NuGet package for new Durable Functions projects.Microsoft.DurableTask namespaces for orchestrator and activity context types (TaskOrchestrationContext, TaskActivityContext).context.CreateReplaySafeLogger(nameof(OrchestratorName)) inside orchestrator functions for logging; never use injected ILogger<T> directly in orchestrators as it logs on every replay.async Task or async Task<T> for all orchestrator and activity methods — never async void.DateTime.Now, Guid.NewGuid(), Random, direct HTTP calls, or non-deterministic I/O inside orchestrators.context.CurrentUtcDateTime instead of DateTime.UtcNow inside orchestrators.Program.cs via builder.Services.AddDurableTaskClient() and builder.ConfigureFunctionsWorkerDefaults(x => x.UseDurableTask())./Orchestrations/OrderProcessing/), not by function type.Orchestrator (e.g., ProcessOrderOrchestrator), activities with the suffix Activity (e.g., ChargePaymentActivity), and entities with the suffix Entity (e.g., CartEntity).CallActivityAsync, CallSubOrchestratorAsync, and GetEntityStateAsync to prevent typos.AzureWebJobsStorage connection string for local development — Durable Functions requires storage to maintain orchestration state."UseDevelopmentStorage=true" or Azurite connection string for local testing — never use a production storage account from local dev.FUNCTIONS_WORKER_RUNTIME to "dotnet-isolated" in local.settings.json.EventHubsConnection for Netherite).local.settings.json to source control — add it to .gitignore; use local.settings.json.example with placeholder values instead.@Microsoft.KeyVault(...) references if needed."extensions": { "durableTask": { ... } } — do not rely on defaults for production."hubName" to a meaningful, environment-specific value (e.g., "MyAppProd", "MyAppDev") to isolate Task Hubs across environments sharing the same storage account."maxConcurrentActivityFunctions" and "maxConcurrentOrchestratorFunctions" based on expected throughput and hosting plan — defaults are conservative."extendedSessionsEnabled": true) for long-running orchestrations on Premium/Dedicated plans to reduce replay overhead."storageProvider": { "type": "netherite" } or "mssql" for high-scale scenarios instead of default Azure Storage."maxQueuePollingInterval" appropriately — lower values increase responsiveness but increase storage transaction costs on Consumption plan."logging": { "applicationInsights": { "samplingSettings": { ... } } } to control telemetry volume.await context.CallActivityAsync<T>(nameof(ActivityName), input) calls for step-by-step workflows where each step depends on the result of the previous.Task.WhenAll(tasks) after fanning out with multiple context.CallActivityAsync calls to aggregate parallel results.List<Task<T>> over dynamic task arrays; capture all tasks before awaiting to avoid replay issues.client.ScheduleNewOrchestrationInstanceAsync from an HTTP trigger starter function; return await client.CreateCheckStatusResponseAsync(req, instanceId) to provide polling URLs to callers.context.WaitForExternalEvent<T>("EventName", timeout) combined with context.CreateTimer(deadline, CancellationToken) to implement approval/callback patterns with timeouts.Task.WhenAny(externalEventTask, timerTask) and cancel the timer if the event arrives first.while loop with context.CreateTimer(context.CurrentUtcDateTime.Add(interval), CancellationToken.None) for polling workflows instead of separate timer-triggered functions.context.ContinueAsNew(input) to restart the orchestration with fresh state and prevent unbounded history growth.context.ContinueAsNew(newInput) at the end of the orchestrator body to restart with clean state for long-lived recurring workflows.ContinueAsNew when using isKeepRunning patterns.ContinueAsNew with context.CreateTimer to implement periodic tasks (e.g., daily report generation, cache refresh).context.CallSubOrchestratorAsync<T>(nameof(SubOrchestrator), instanceId, input) to decompose complex workflows into reusable child orchestrations.instanceId for sub-orchestrations when idempotency or correlation is required.TaskEntity<TState> for typed, encapsulated state management.entity.State); never read or write entity storage directly.context.Entities.CallEntityAsync<T> from activities or context.Entities.SignalEntityAsync from orchestrators for fire-and-forget entity operations.SignalEntityAsync over CallEntityAsync from orchestrators when the return value is not needed, to avoid unnecessary blocking.IRepository, IHttpClientFactory) via constructor DI into the class containing activity functions; do not use [FromServices] inside the activity method.TaskActivityContext parameter type for activity context; log using the injected ILogger<T> (not a replay-safe logger — activities are not replayed).context.CallActivityAsync calls in try/catch blocks within the orchestrator to handle TaskFailedException for graceful error handling and compensation.RetryPolicy (via new TaskOptions(new RetryPolicy(maxRetries, firstRetryInterval))) on activity calls for automatic retries with backoff on transient failures.context.CreateTimer(fireAt, CancellationToken) for durable delays inside orchestrators — never use Task.Delay or Thread.Sleep.CancellationTokenSource.instanceId values (e.g., $"order-{orderId}") instead of GUIDs when the orchestration needs to be correlated to a business entity.client.GetInstanceMetadataAsync(instanceId) before scheduling new ones to prevent duplicate orchestrations (singleton pattern).client.TerminateInstanceAsync, client.SuspendInstanceAsync, and client.ResumeInstanceAsync for lifecycle management in management APIs or administrative functions.client.PurgeInstanceAsync or bulk purge to control Task Hub storage growth.context.CreateReplaySafeLogger(nameof(Orchestrator)) for all logging inside orchestrators to prevent duplicate log entries during replay.instanceId in every log statement from orchestrators and starters for end-to-end traceability./runtime/webhooks/durabletask/instances) or the Durable Functions Monitor VS Code extension.durableTask.maxConcurrentOrchestratorFunctions and durableTask.maxConcurrentActivityFunctions in host.json to control concurrency and prevent resource exhaustion.host.json under "extensions": { "durableTask": { "hubName": "MyTaskHub" } } to isolate environments (dev/staging/prod) sharing the same storage account.Microsoft.Azure.Functions.Worker.Extensions.DurableTask.Tests NuGet package (if available) or manually mock TaskOrchestrationContext for unit testing orchestrators.context.CallActivityAsync, context.CreateTimer, and context.WaitForExternalEvent using a test harness or manual mocks.$"test-{Guid.NewGuid()}") to enable querying and verifying orchestration state via client.GetInstanceMetadataAsync.context.CreateTimer to fire immediately and verifying the orchestrator handles the timeout branch.client.WaitForInstanceCompletionAsync in integration tests instead of polling — it blocks until the orchestration completes or times out.context.Entities.SignalEntityAsync in test orchestrators and verify entity state via client.ReadEntityStateAsync after the orchestration completes.DateTime.UtcNow or DateTime.Now is used inside an orchestrator, flag it and replace with context.CurrentUtcDateTime.Guid.NewGuid() or Random is used inside an orchestrator, flag it as non-deterministic and move it to an activity.HttpClient.GetAsync, etc.) are made inside an orchestrator, flag them immediately and move the call into an activity function.Task.Delay or Thread.Sleep is used inside an orchestrator, replace with context.CreateTimer.ContinueAsNew on long-running loops, suggest adding ContinueAsNew to reset history.© GitHub, Inc. · MIT · source · posted by @OpenSourceBuffGuy on promptparty.com


Sea turtle carrying floating film studio island
Draws a giant sea turtle carrying a floating island film studio through a starry sky, where fairies polish rough film strips into golden film.
image-prompt, nano-banana, 3d-render, cartoon, fantasy-world, creatures, animals, whimsical, dreamy, cinematic, dramatic-lighting, vibrant-colors, bokeh, miniature, widescreen, night-scene, illustration, concept-art, surreal, storytelling, clay-3d

Desert buggy escapes drones past industrial outpost
Builds a 15-second desert chase video where a racer in an armored buggy escapes drones past an industrial outpost, using five reference images with set jobs.
video-prompt, hailuo, action, multi-shot, timed-beats, camera-movement, reference-image, character-consistency, negative-prompt, cinematic, sci-fi, cars, landscape, aerial-view, tracking-shot, photorealistic, sound-effects, structured-output, long-form, widescreen

Cozy Pixel Art Farm Island Village
Draws a cozy 16-bit pixel-art farming village across six small islands joined by bridges, with exact counts for buildings, animals and crops.
image-prompt, gpt-image, pixel-art, isometric, game-assets, concept-art, maps, worldbuilding, cozy, vibrant-colors, ocean, landscape, wide-shot, widescreen, game-development, video-games, structured-output, whimsical, summer, high-angle, aerial-view, animals, negative-prompt, cityscape
Loading reviews…
Loading comments…