Support `DynamicWorkflow` under Azure Durable Task
Stacked on #14523 (CodeMode under Azure Durable Task). Reuses its in_durable_task_orchestration() helper and use_portal parameter. Merge #14523 first; this PR's own diff is the last commit.
DynamicWorkflow under AzureDurableTaskDurability failed on its first run_workflow with the error CodeMode had: "Agent code awaited non-durable work inside a Durable Task orchestration". Monty completes an awaited call by waking the loop from its own I/O thread, which the orchestrator loop (_TrampolineLoop) refuses. The new test reproduces this before the fix.
Fix: DynamicWorkflow opens the Monty portal in a Durable Task orchestration as well as in a Temporal workflow, using #14523's helper (_uses_portal() wraps the two checks). No new portal code.
Test (tests/harness/azure_durable_task/test_dynamic_workflow.py, InMemoryWorker): the script gathers two sub-agents (each with a model request, a tool call and a second request), sleeps on a durable timer, then runs a third sub-agent on both results.
- Before the timer, the gathered sub-agents' activities interleave (
model.requestĆ2,call_toolĆ2,model.requestĆ2), so they run concurrently. - A new worker with new agent instances resumes after the timer. Only the third sub-agent's model requests and tool call run, and its activity names are pinned.
- No portal thread or Monty worker outlives a dispatch.
InMemoryWorker.replay(instance_id)(new fixture helper) re-executes the finished history on a fresh executor. It produces onlycompleteOrchestration, with the same output, and runs no model or tool call.
For the durable reviewer:
- Replay determinism. The SDK replays the whole history on every orchestration turn. It fails the orchestration with
NonDeterminismErrorif a replay schedules a different activity or timer at any sequence number, so every turn in the test checks the order, and the finalreplaychecks it on a cold executor. Sub-agent dispatch order follows the script, and a scriptasyncio.sleepis an asyncio timer, which the trampoline turns into a durable timer. - Portal and generator orchestration.
run_durabledrivesagent.runon the trampoline loop inside the SDK's generator. While a snippet computes, the orchestrator thread blocks on the portal (a helper thread with a normal asyncio loop). When the script awaits a sub-agent, control returns to the trampoline, whose awaits become yielded SDK tasks. The portal and the Monty worker are closed when a turn ends, including one that ends mid-script: the first thread-count assertion runs while the orchestration is parked on the timer. Nothing is held between turns, and the next turn re-runs the script from recorded results. - Runaway programs. Unlike
CodeMode,DynamicWorkflowdoesn't turnmax_duration_secondsoff in orchestrator code, matching its existing Temporal behavior: there is no default cap, and a cap the user sets still applies. With no cap, the only bounds aremax_memory(256 MB by default) and the sub-agent budgets, which a CPU-only loop never reaches. Such a loop holds the orchestrator thread. The README and docstring now say this for Azure as well as Temporal. As on Temporal, a script that runs close to a cap can stop at a different point on replay, and the docs say so.
Docs: the Dynamic Workflow README and docs page get an Azure Durable Task paragraph under "Running under other durable engines". The Azure README's orchestrator-code bullet links to it.
Checklist
- No breaking changes in accordance with the version policy.
- Any permitted compatibility impact has a label, warning, migration and release note, and an exact API-check waiver if the gate reports it.
- PR title is fit for the release changelog.
š¤ Generated with Claude Code
Summary by cubic
Makes DynamicWorkflow work under AzureDurableTaskDurability, where its first run_workflow call previously failed with "Agent code awaited non-durable work". Part of #14514.
- Calls Monty through the portal in Durable Task orchestrations, reusing the
in_durable_task_orchestration()helper;_uses_portal()now covers both Temporal workflows and Durable Task orchestrations. - Disables
max_duration_secondsin orchestrator code, where elapsed time could make a replay take a different branch than the recorded run; the sleep allowance and memory cap still apply. - Adds an
InMemoryWorker.replay()fixture helper and tests covering two concurrent gathered sub-agents, a durable timer, resuming on a new worker, replaying the finished history on a cold executor without repeating any activity, and the elapsed-time limit being off during an orchestration. - Documents Azure Durable Task support in both READMEs and the docs pages, noting that a replay divergence may fail with a
NonDeterminismErroror continue with a different tool result after the script's last sub-agent call.