Skip to content

Add workflow management APIs: list, history and rerun - #1217

Open
javier-aliaga wants to merge 1 commit into
dapr:mainfrom
javier-aliaga:feat/workflow-management-apis
Open

javier-aliaga wants to merge 1 commit into
dapr:mainfrom
javier-aliaga:feat/workflow-management-apis

Conversation

@javier-aliaga

@javier-aliaga javier-aliaga commented Sep 17, 2026

Copy link
Copy Markdown

Description

The vendored durabletask protos already carry ListInstanceIDs, GetInstanceHistory and RerunWorkflowFromEvent, but neither client layer exposed them. This adds all three to DaprWorkflowClient and its async counterpart:

Method Returns
list_workflow_instances(*, page_size, continuation_token) WorkflowInstanceIdPage — one page plus the next token
iter_workflow_instances(*, page_size=1024) lazy iterator, pages internally (async for on the async client)
get_workflow_history(instance_id) list[WorkflowHistoryEvent]
rerun_workflow_from_event(instance_id, event_id, ...) the new instance ID

All additive; no existing signature changes.

Two behaviours worth knowing:

  • rerun_workflow_from_event takes the replacement input as a single argument. Omit it to keep the original input, pass None to clear it.
  • WorkflowHistoryEvent carries event_id, timestamp, event_type, name, task_scheduled_id and failure_details, so a rerun point can be chosen by activity name. Unrecognised event types map to UNKNOWN rather than raising.

Issue reference

Closes #1181
Part of dapr/dapr#9729

Testing

  • 52 unit tests across tests/ext/workflow/test_workflow_management.py and tests/ext/workflow/durabletask/test_client_management_apis.py, covering both clients.
  • Full unit suite green; mypy and ruff clean.
  • examples/workflow/workflow_management.py runs list → history → rerun against a live sidecar, asserted by tests/examples/test_workflow.py::test_workflow_management.

Note for reviewers

get_workflow_history lets gRPC NOT_FOUND propagate for a missing or purged instance, matching pause/resume/terminate/purge, rather than returning None the way get_workflow_state does. Happy to invert it if you prefer.

The three advanced workflow management operations from dapr/dapr#9729 had
no Python surface: the vendored durabletask protos carried ListInstanceIDs,
GetInstanceHistory and RerunWorkflowFromEvent, but neither client layer
exposed them, so reaching them meant using the gRPC stub directly.

DaprWorkflowClient and its async counterpart now expose:

- list_workflow_instances(page_size, continuation_token) -> one page of
  instance IDs plus the token for the next, when the caller wants to hold
  the cursor themselves.
- iter_workflow_instances(page_size) -> a lazy iterator that pages
  internally; an async generator on the async client.
- get_workflow_history(instance_id) -> the instance's events as
  WorkflowHistoryEvent records.
- rerun_workflow_from_event(instance_id, event_id, ...) -> the ID of a new
  instance that replays history up to the chosen event and resumes there.

The rerun input is a single argument rather than a value plus a flag. The
wire format pairs a non-optional StringValue with an overwriteInput bool
precisely because StringValue cannot express absence, so the two are
collapsed behind a sentinel default: omitting input keeps the original,
passing None clears it. A falsy value such as 0 still overwrites.

WorkflowHistoryEvent carries event_id, timestamp, event_type, name,
task_scheduled_id and failure_details, which is enough to choose a rerun
point by activity name instead of by raw event number. is_rerunnable
reports this SDK's snapshot of which event types the runtime restarts
from; the sidecar keeps the final say. Unrecognised event types map to
UNKNOWN rather than raising, so a newer sidecar cannot break history reads.

Verified end to end against runtime 1.18.0: a failed order is listed, its
history read, and the failed charge rerun with a corrected input to
completion. examples/workflow/workflow_management.py covers that flow and
is asserted by tests/examples/test_workflow.py.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Signed-off-by: Javier Aliaga <javier@diagrid.io>
@javier-aliaga
javier-aliaga requested review from a team as code owners September 17, 2026 11:47
@codecov

codecov Bot commented Sep 17, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 99.27007% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 83.47%. Comparing base (74c3c54) to head (03a1293).

Files with missing lines Patch % Lines
dapr/ext/workflow/_durabletask/client.py 94.73% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1217      +/-   ##
==========================================
+ Coverage   83.32%   83.47%   +0.14%     
==========================================
  Files         123      124       +1     
  Lines       10250    10384     +134     
==========================================
+ Hits         8541     8668     +127     
- Misses       1709     1716       +7     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

dapr/ext/workflow/AGENTS.md now contains a misleading statement about NOT_FOUND being converted to None, which conflicts with the new get_workflow_history() behavior.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

This PR extends the Dapr Python SDK workflow extension by exposing three durabletask-backed workflow management capabilities (instance listing, history retrieval, and rerun-from-event) on both DaprWorkflowClient and dapr.ext.workflow.aio.DaprWorkflowClient. It also adds a runnable example plus unit and example tests to validate the new APIs end-to-end.

Changes:

  • Added workflow management client APIs: list_workflow_instances, iter_workflow_instances, get_workflow_history, and rerun_workflow_from_event (sync + async).
  • Introduced typed return models for instance pages and history events (WorkflowInstanceIdPage, WorkflowHistoryEvent, WorkflowHistoryEventType), including “unknown event type” resilience.
  • Added comprehensive unit tests (client layer + engine client layer) and a new example validated by the examples test suite.
File summaries
File Description
dapr/ext/workflow/dapr_workflow_client.py Adds the new management APIs to the sync workflow client.
dapr/ext/workflow/aio/dapr_workflow_client.py Adds async equivalents of the new management APIs.
dapr/ext/workflow/workflow_management.py New typed models and conversions for instance pages and history events.
dapr/ext/workflow/_durabletask/client.py Adds engine-client RPC wrappers + sentinel handling for rerun input semantics.
dapr/ext/workflow/_durabletask/aio/client.py Async engine-client wrappers for list/history/rerun using shared request builder.
dapr/ext/workflow/__init__.py Exposes the new management types (and FailureDetails) at the extension top-level.
dapr/ext/workflow/AGENTS.md Documents the new APIs (but needs a small correction to the NOT_FOUND/None note).
tests/ext/workflow/test_workflow_management.py New unit tests covering sync + async workflow management APIs.
tests/ext/workflow/durabletask/test_client_management_apis.py New engine-client tests validating request/response behavior for list/history/rerun.
examples/workflow/workflow_management.py New example demonstrating list → history → rerun flow.
examples/workflow/README.md Documents the new example and explains rerunnable event types and caveats.
tests/examples/test_workflow.py Adds output-based validation for the new workflow management example.
Review details
  • Files reviewed: 12/12 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread dapr/ext/workflow/AGENTS.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[WORKFLOW SDK FEATURE REQUEST] Expose advanced workflow management APIs

2 participants